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:
- Create a media player (see How do I add a video player).
- Create a control element as a
Nodeextension.
Tip: You can either construct this element by using thejavafx.scene.shapeandjavafx.scene.controlpackages, use the prefabricated image added to theImageViewobject, or create a more complicated implementation extending theCustomNodeclass.
- 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
- Dragging an MP3 Player Applet to the Desktop
This sample shows how to create a draggable player that users can save on the desktop for later use. - Playing Video on the Sides of a Rotating Cube
This sample shows how to play video on the sides of a rotating cube. - Media Player
This application is a full-functional media player with graphical UI elements that control the media playback. - Media Player with Graphical Overlays
The full-functional player with graphical panels that display additional information overlaying the media content. - Controlling Media Playback
- Applying Graphics Assets to Media
API Documentation
Last Updated: November 2009
[Return to How-To's Home]
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 repliesyour information is not used for any other purpose. By submitting a comment, you agree to these Terms of Use.