Example usage for javafx.scene.media MediaPlayer setOnError

List of usage examples for javafx.scene.media MediaPlayer setOnError

Introduction

In this page you can find the example usage for javafx.scene.media MediaPlayer setOnError.

Prototype

public final void setOnError(Runnable value) 

Source Link

Document

Sets the event handler to be called when an error occurs.

Usage

From source file:filesmodel.SoundModel.java

/** @return a MediaPlayer for the given source which will report any errors it encounters */
public MediaPlayer createPlayer(String mediaSource) {
    final Media media = new Media(mediaSource);
    final MediaPlayer player = new MediaPlayer(media);
    player.setOnError(new Runnable() {
        @Override/*from w ww.j  a  v  a 2 s.c o  m*/
        public void run() {
            System.out.println("Media error occurred: " + player.getError());
        }
    });

    return player;

}