本文整理匯總了Java中javafx.scene.media.MediaPlayer.setOnError方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaPlayer.setOnError方法的具體用法?Java MediaPlayer.setOnError怎麽用?Java MediaPlayer.setOnError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.scene.media.MediaPlayer
的用法示例。
在下文中一共展示了MediaPlayer.setOnError方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void execute() {
if (elementInfo.canWork()) {
elementInfo.setAsWorking();
MediaPlayer currentSoundToPlay = soundToPlay;
currentSoundToPlay.setOnEndOfMedia(() -> {
// Using local reference, because soundToPlay field is substituted later.
removeFromManagerAndDisposeSound(currentSoundToPlay);
});
currentSoundToPlay.setOnStopped(() -> { // Stopped from SuperSoundManager.
removeFromManagerAndDisposeSound(currentSoundToPlay);
});
currentSoundToPlay.setOnError(() -> {
removeFromManagerAndDisposeSound(currentSoundToPlay);
});
boolean wasAbleToPlay = play();
filePicker.computeNextFileIndex();
File nextFileToPlay = filePicker.getTemporarySourceFileList()
.get(filePicker.getCurrentFileIndex());
String nextSoundToPlay = nextFileToPlay.getPath();
soundToPlay = initializeSoundAndAddToManager(nextSoundToPlay);
elementInfo.setBooleanResult(wasAbleToPlay);
}
}
示例2: initialize
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
public void initialize()
{
// get URL of the video file
URL url = VideoPlayerController.class.getResource("sts117.mp4");
// create a Media object for the specified URL
Media media = new Media(url.toExternalForm());
// create a MediaPlayer to control Media playback
mediaPlayer = new MediaPlayer(media);
// specify which MediaPlayer to display in the MediaView
mediaView.setMediaPlayer(mediaPlayer);
// set handler to be called when the video completes playing
mediaPlayer.setOnEndOfMedia(() -> {
playing = false;
playPauseButton.setText("Play");
});
// set handler that displays an ExceptionDialog if an error occurs
mediaPlayer.setOnError(() -> {
ExceptionDialog dialog =
new ExceptionDialog(mediaPlayer.getError());
dialog.showAndWait();
});
// bind the MediaView's width/height to the scene's width/height
DoubleProperty width = mediaView.fitWidthProperty();
DoubleProperty height = mediaView.fitHeightProperty();
width.bind(Bindings.selectDouble(
mediaView.sceneProperty(), "width"));
height.bind(Bindings.selectDouble(
mediaView.sceneProperty(), "height"));
}
示例3: getMediaPlayerFor
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer getMediaPlayerFor(Media media) {
try {
playerReady = false;
final MediaPlayer mediaPlayer = new MediaPlayer(media);
if(mediaPlayer.getError() == null) {
mediaPlayer.setAutoPlay(false);
mediaPlayer.currentTimeProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
Duration newDuration = (Duration) newValue;
progressBar.setValue((int) Math.round(newDuration.toSeconds()));
updateTimeLabel();
}
});
mediaPlayer.setOnReady(new Runnable() {
public void run() {
playerReady = true;
progressBar.setMinimum(0.0);
progressBar.setValue(0.0);
progressBar.setMaximum(mediaPlayer.getTotalDuration().toSeconds());
refreshLayout();
}
});
mediaPlayer.setOnError(new Runnable() {
public void run() {
processError(mediaPlayer.getError());
}
});
return mediaPlayer;
}
else {
processError(mediaPlayer.getError());
}
}
catch(Exception e) {
processError(e);
}
return null;
}
示例4: start
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void start(Stage primaryStage)
{
File fileForMusic = new File("C:\\Users\\Eric\\Music\\New stuff\\Prism.mp3");
if (!fileForMusic.exists())
{
System.out.println("File does not exist");
return;
}
System.out.println(fileForMusic.toURI().toString());
// Create the m
Media song = new Media(fileForMusic.toURI().toString());
final MediaPlayer player = new MediaPlayer(song);
player.setAutoPlay(true);
player.setOnError(new Runnable() {
@Override
public void run() {
System.out.println("ERROR");
MediaException e = player.getError();
e.printStackTrace();
}
});
System.out.println(player.getStatus());
System.out.println(player);
System.out.println(player.getMedia());
player.setOnReady(new Runnable() {
@Override
public void run() {
System.out.println("Player running?");
player.play();
}
});
// Add a mediaView, to display the media. Its necessary !
// This mediaView is added to a Pane
MediaView mediaView = new MediaView(player);
mediaView.setMediaPlayer(player);
// Setup the Java FX Scene
primaryStage.setTitle("Hello World!");
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
root.getChildren().add(mediaView);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}