The MediaPlayer class is the class which can play media, either audio or video. It doesn't have any UI controls and for the video playback you need to use the corresponding MediaView class (see the next section).
As you don't need any UI for an audio, let's look at it first. Playing an MP3 song looks as follows:
Media media = new Media("http://www.sample-videos.com/audio/mp3/wave.mp3");MediaPlayer mp = new MediaPlayer(media);mp.play();
You can control playback in various ways using Media class properties, APIs, and event handlers; some of them are very similar to Timeline ones (see Chapter 5, Animation). I'll list the most interesting ones:
- seek (Duration seekTime): Sets the playback to the ...