The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.sound.sampled  [9 examples] > Properties  [5 examples]

e730. Setting the Volume of a Sampled Audio Player

    // To create a Clip object, see e723 Loading and Playing Sampled Audio
    
    // Set Volume
    FloatControl gainControl = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
    double gain = .5D;    // number between 0 and 1 (loudest)
    float dB = (float)(Math.log(gain)/Math.log(10.0)*20.0);
    gainControl.setValue(dB);
    
    // Mute On
    BooleanControl muteControl = (BooleanControl)clip.getControl(BooleanControl.Type.MUTE);
    muteControl.setValue(true);
    
    // Mute Off
    muteControl.setValue(false);

 Related Examples
e726. Determining the File Format of a Sampled Audio File
e727. Determining the Encoding of a Sampled Audio File
e728. Determining the Duration of a Sampled Audio File
e729. Determining the Position of a Sampled Audio Player

See also: Events    Playing   


© 2002 Addison-Wesley.