Java Reference
In-Depth Information
Listing 9-14 shows the new Application class that creates the views and initializes the drag-and-drop handling.
The SongModel instance is created in the constructor of the AudioPlayer3 class and gets passed to the application's
views later in the start method. The code that creates and initializes the Scene , loads the style sheets, and initializes
the Stage is mostly unchanged from AudioPlayer2, with the minor addition of calling the initSceneDragAndDrop
method that was shown in Listing 9-13. Another difference is that we are now using a BorderPane layout node to keep
our metadata view on top of the controls view.
Listing 9-14. The AudioPlayer3 Application Class
public class AudioPlayer3 extends Application {
private final SongModel songModel;
private MetadataView metaDataView;
private PlayerControlsView playerControlsView;
public static void main(String[] args) {
launch(args);
}
public AudioPlayer3() {
songModel = new SongModel();
}
@Override
public void start(Stage primaryStage) {
songModel.setURL(" http://traffic.libsyn.com/dickwall/JavaPosse373.mp3 " );
metaDataView = new MetadataView(songModel);
playerControlsView = new PlayerControlsView(songModel);
final BorderPane root = new BorderPane();
root.setCenter(metaDataView.getViewNode());
root.setBottom(playerControlsView.getViewNode());
final Scene scene = new Scene(root, 800, 400);
initSceneDragAndDrop(scene);
final URL stylesheet = getClass().getResource("media.css");
scene.getStylesheets().add(stylesheet.toString());
primaryStage.setScene(scene);
primaryStage.setTitle("Audio Player 3");
primaryStage.show();
songModel.getPlayer().play();
}
private void initSceneDragAndDrop(Scene scene) {
// Shown in Listing 9-13.
}
}
We now have a good beginning to an audio player application, but it's pretty annoying when you can't control the
playback of the songs. It's time to remedy that.
 
Search WWH ::




Custom Search