How-To's > How do I access volume controls?


Use the volume and the mute instance variables of the MediaPlayer class to alter the volume level and to mute/unmute the audio stream. In general you should implement the following steps:

  1. Create a media player (see How do I add a video player).
  2. Create a control element as a Node extension.
    Tip: You can either construct this element by using the javafx.scene.shape and javafx.scene.control packages, use the prefabricated image added to the ImageView object, or create a more complicated implementation extending the CustomNode class.
    volume control
  3. Bind the volume level and the mute status retrieved from the control element to the corresponding variables of the media player object.

The following code scheme illustrates this approach.

public class VolumeControl extends CustomNode {
    public var volume: Number;
    public var mute: Boolean = false;


//Create your volume control here

}

public class MyPlayer extends MediaPlayer {
    public override var volume on replace {...}
    public override var mute on replace {...}


//Create your media player here 

}

public class CutePlayer{
// This is the main class of your application
...

Stage {
    scene: Scene{
            content:[
            //All the graphical components go here
            ...
            //Bidirectional binding is applied
            var volumeControl = VolumeControl {
                     volume: bind myPlayer.volume with inverse
                     mute: bind myPlayer.mute with inverse
            ...
            ]
   }

}
... 
}

Examples

API Documentation

Last Updated: November 2009
[Return to How-To's Home]



Rate This Article
Leave a Comment or Suggest a Topic

Do you have comments about this article? We welcome your participation in our community. Please keep your comments civil and on point. You may optionally provide your email address to be notified of replies—your information is not used for any other purpose. By submitting a comment, you agree to these Terms of Use.

 

English
日本語
한국어
简体中文
русский
Português do Brasil