當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaPlayer.setOnEndOfMedia方法代碼示例

本文整理匯總了Java中javafx.scene.media.MediaPlayer.setOnEndOfMedia方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaPlayer.setOnEndOfMedia方法的具體用法?Java MediaPlayer.setOnEndOfMedia怎麽用?Java MediaPlayer.setOnEndOfMedia使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javafx.scene.media.MediaPlayer的用法示例。


在下文中一共展示了MediaPlayer.setOnEndOfMedia方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: playTrailer

import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
private void playTrailer() {
    final Media media = model.getSelectedMovie().loadTrailer();
    final MediaPlayer mediaPlayer = new MediaPlayer(media);
    mediaPlayer.setOnEndOfMedia(() -> {
        mediaPane.setVisible(false);
        mediaPlayer.stop();
        mediaPlayer.dispose();
    });
    mediaView.setOnMouseClicked(e -> {
        if(MediaPlayer.Status.PLAYING.equals(mediaPlayer.getStatus())) {
            mediaPlayer.pause();
            mediaStateIcon.toPlay();
        } else {
            mediaPlayer.play();
            mediaStateIcon.toPause();
        }
    });
    mediaView.setMediaPlayer(mediaPlayer);
    mediaPane.setVisible(true);
    mediaPlayer.play();
}
 
開發者ID:hendrikebbers,項目名稱:ExtremeGuiMakeover,代碼行數:22,代碼來源:MasterDetailViewController.java

示例2: playSong

import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void playSong(SongData songData) {
    if (songData != null && !songData.getTitle().equals(" ")) {
        settingsFactory.setPlayingSong(songData);
        this.currentPlayingSong = songData;
        this.stopPlaying();
        try {
            File songFile = new File(songData.getPath());
            AudioFile audioFile = AudioFileIO.read(songFile);
            isPlaying = true;
            player = new MediaPlayer(new Media(songFile.toURI().toURL().toExternalForm()));
            songPlayerBarController.setupForPlayingMusic(audioFile);
            player.play();
            player.setOnEndOfMedia(this::playNextSong);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
開發者ID:daothanhduy305,項目名稱:MusicHub,代碼行數:20,代碼來源:MainPlayerController.java

示例3: start

import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void start(final Stage stage)
{
    stage.setTitle("Audio Demo");
    stage.show();

    // Windows and Mac OS X support WAV and MP3
    // Linux: WAV hangs, MP3 results in MediaException for unsupported format
    final File file =
    //                new File("../org.csstudio.display.builder.model/examples/audio/timer.wav");
                      new File("../org.csstudio.display.builder.model/examples/timer/timer.mp3");
    final Media audio = new Media(file.toURI().toString());
    final MediaPlayer player = new MediaPlayer(audio);
    player.setOnEndOfMedia( () -> player.stop());
    player.play();

    player.setOnStopped(() ->
    {
        player.dispose();
        stage.close();
    });
}
 
開發者ID:kasemir,項目名稱:org.csstudio.display.builder,代碼行數:23,代碼來源:AudioDemo.java

示例4: 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);
	}
}
 
開發者ID:ubershy,項目名稱:StreamSis,代碼行數:25,代碼來源:MultiSoundAction.java

示例5: createScene

import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
private void createScene(final String mediaUrl) {
        StackPane root = new StackPane();
        final Scene scene = new Scene(root);
        final File f = new File(mediaUrl);
        final Media m = new Media(f.toURI().toString());
        mediaPlayer = new MediaPlayer(m);
        final MediaView mv = new MediaView(mediaPlayer);

        final DoubleProperty width = mv.fitWidthProperty();
        final DoubleProperty height = mv.fitHeightProperty();

        width.bind(Bindings.selectDouble(mv.sceneProperty(), "width"));
        height.bind(Bindings.selectDouble(mv.sceneProperty(), "height"));
        mv.setPreserveRatio(true);
//        mediaPlayer.setAutoPlay(true);
//        mediaPlayer.setCycleCount(Integer.MAX_VALUE);
        mediaPlayer.setOnEndOfMedia(new Runnable() {

            @Override
            public void run() {
                replay();
            }
        });
        root.getChildren().add(mv);
        fxContainer.setScene(scene);
    }
 
開發者ID:toyboxman,項目名稱:yummy-xml-UI,代碼行數:27,代碼來源:VideoPlayer.java

示例6: 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")); 
}
 
開發者ID:cleitonferreira,項目名稱:LivroJavaComoProgramar10Edicao,代碼行數:36,代碼來源:VideoPlayerController.java

示例7: start

import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void start(final Stage primaryStage) throws Exception {
    MediaView mediaView = new MediaView();
    Media media = new Media(new File("credits/end_scene.mp4").toURI().toString());
    MediaPlayer mediaPlayer = new MediaPlayer(media);
    mediaView.setMediaPlayer(mediaPlayer);
    mediaPlayer.setAutoPlay(true);
    mediaView.setPreserveRatio(false);

    List<String> params = getParameters().getRaw();
    if(params.size() == 2) {
        mediaView.setFitWidth(Integer.parseInt(params.get(0)));
        mediaView.setFitHeight(Integer.parseInt(params.get(1)));
    } else {
        mediaView.setFitWidth(1280);
        mediaView.setFitHeight(720);
    }

    mediaPlayer.setOnEndOfMedia(new Runnable() {
        @Override
        public void run() {
            primaryStage.close();
        }
    });

    primaryStage.setScene(new Scene(new FlowPane(mediaView)));
    primaryStage.show();
}
 
開發者ID:camilne,項目名稱:bad-wolf,代碼行數:29,代碼來源:Credits.java

示例8: loop

import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
public static MediaPlayer loop(String fileName) {
    final MediaPlayer m = new MediaPlayer(getSound(fileName));
    m.setOnEndOfMedia(new Runnable() {
        public void run() {
            m.seek(Duration.ZERO);
        }
    });
    m.play();
    return m;
}
 
開發者ID:ritcat14,項目名稱:The-Mysterious-Mind-Of-Jack,代碼行數:11,代碼來源:SoundHandler.java

示例9: PlayMovie

import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
private void PlayMovie(Media movie){
    MediaPlayer player = new MediaPlayer(movie);
    playstop = player;
    player.setOnEndOfMedia(onMovieEnd);
    player.setAutoPlay(true);
    player.setCycleCount(1);
    player.setMute(true);
    StackedMediaView.setMediaPlayer(player);
    StackedMediaView.setFitWidth(ViewStackPane.getWidth());

    SwapDisplayMovie();
}
 
開發者ID:chrootRISCassembler,項目名稱:CapsLock,代碼行數:13,代碼來源:MainFormController.java

示例10: initMediaPlayer

import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
private void initMediaPlayer(final MediaView mediaView) {
    counter++;
    if (!manager.isEmpty()) {

        //Print the queue for test
        System.out.println(manager.getQueue());
        //Get the next item from the manager and move the current item to the end
        String filename = manager.getNext();
        final File f = new File("videos/" + filename + ".mp4");
        //Setting up the media to autoplay
        MediaPlayer mediaPlayer = new MediaPlayer(new Media(f.toURI().toString()));
        mediaPlayer.setAutoPlay(true);
        //When the media ends, make a recursive call with the updated queue
        mediaPlayer.setOnEndOfMedia(()->{
            mediaPlayer.dispose();
            initMediaPlayer(mediaView);
        });
        System.out.println("Reproduction #"+counter);
        mediaView.setMediaPlayer(mediaPlayer);
    }else{
        System.out.println("Empty queue");
        //There is no videos in the manager, try again in 10 seconds.
        try {
            Thread.sleep(15000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        initMediaPlayer(mediaView);
    }
}
 
開發者ID:kevuno,項目名稱:Offline-Streamer,代碼行數:31,代碼來源:player.java

示例11: assureMediaPlayer

import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
private boolean assureMediaPlayer(FileItem item, Runnable action) {
	try {
		int index = musicListView.getItems().indexOf(item);
		if (index > -1 && !item.isPhantomProperty().get()) {
			if (!players.containsKey(item)) {
				final MediaPlayer player = new MediaPlayer(new Media(toFileURI(item.getFile())));
				System.out.println(player + " initialized");
				player.setOnReady(action);
				player.setOnEndOfMedia(()->{
					playNext();
				});
				player.totalDurationProperty()
						.addListener((obs, oldDuration, newDuration) -> playSlider.setMax(newDuration.toSeconds()));

				player.currentTimeProperty().addListener((obs, oldTime, newTime) -> {
					if (!playSlider.isValueChanging()) {
						playSlider.setValue(player.currentTimeProperty().get().toSeconds());
					}
				});
				
				players.put(item, player);
			} else {
				action.run();
			}
			
			return true;
		}
	} catch (Exception e) {
		Logger.error(e);
	}

	return false;
}
 
開發者ID:bdh92123,項目名稱:share_all,代碼行數:34,代碼來源:RoomController.java

示例12: AudioFuture

import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
AudioFuture(final MediaPlayer player)
{
    this.player = player;
    // Player by default just stays in "PLAYING" state
    player.setOnEndOfMedia(() -> player.stop());
    player.play();
    logger.log(Level.INFO, "Playing " + this);
}
 
開發者ID:kasemir,項目名稱:org.csstudio.display.builder,代碼行數:9,代碼來源:JFXRepresentation.java

示例13: CodenameOneMediaPlayer

import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
public CodenameOneMediaPlayer(String uri, boolean isVideo, JFrame f, javafx.embed.swing.JFXPanel fx, final Runnable onCompletion) throws IOException {
    if (onCompletion != null) {
        this.onCompletion = new Runnable() {

            @Override
            public void run() {
                Display.getInstance().callSerially(onCompletion);
            }
        };
    }
    this.isVideo = isVideo;
    this.frm = f;
    try {
        File fff = new File(uri);
        if(fff.exists()) {
            uri = fff.toURI().toURL().toExternalForm();
        }
        player = new MediaPlayer(new javafx.scene.media.Media(uri));
        player.setOnEndOfMedia(this.onCompletion);
        if (isVideo) {
            videoPanel = fx;
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex);
    }
}
 
開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:29,代碼來源:JavaSEPort.java

示例14: start

import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void start(Stage stage) throws Exception
{
	Media media = new Media(new File("../core/src/main/resources/blackHandbraked.mp4").toURI().toString());
	MediaPlayer player = new MediaPlayer(media);
	player.pause();
	player.setCycleCount(Integer.MAX_VALUE);
	MediaView mediaView = new MediaView(player);
	mediaView.setFitWidth(1280d);
	BorderPane pane = new BorderPane();
	pane.setCenter(mediaView);
	ToolBar tools = new ToolBar();
	
	Text total = new Text("TOTAL");
	total.setStroke(Color.WHITE);
	total.setFill(Color.BLUE);
	total.setFont(new Font("Buxton Sketch",60d));
	tools.getItems().add(total);
	
	Text time = new Text("HI MOM!");
	time.setStroke(Color.WHITE);
	time.setFill(Color.BLUE);
	time.setFont(new Font("Buxton Sketch",60d));
	tools.getItems().add(time);

	
	pane.setTop(tools);
	player.currentTimeProperty().addListener(new ChangeListener<Duration>() {

		@Override
		public void changed(ObservableValue<? extends Duration> observable, Duration oldValue, Duration newValue)
		{
			double elapsed = ((double)player.getCurrentCount())*player.getCycleDuration().toMillis()+newValue.toMillis();
			time.setText(""+elapsed);
			total.setText(player.getCycleDuration().toString());
		}
	});
	
	player.setOnEndOfMedia(() -> System.out.println("End"));
	
	stage.setScene(new Scene(pane));
	stage.show();
	player.play();
	
}
 
開發者ID:GeePawHill,項目名稱:contentment,代碼行數:46,代碼來源:VideoPlayerExperiment.java

示例15: setMediaLocation

import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
public void setMediaLocation(String mediaLocation, Consumer<JFXMovieJFrameController> onReadyRunnable) {

        Preconditions.checkNotNull(mediaLocation, "The medialocation can not be null");
        this.mediaLocation = mediaLocation;

        Media media = new Media(mediaLocation);
        final ObservableMap<String,Object> metadata = media.getMetadata();
        //timecode.setFrameRate((Double) metadata.getOrDefault("framerate", DEFAULT_FRAME_RATE));
        frameRate = DEFAULT_FRAME_RATE;
        mediaPlayer = new MediaPlayer(media);
        mediaView.setMediaPlayer(mediaPlayer);


        // --- Configure MediaPlayer
        mediaPlayer.currentTimeProperty().addListener(observable -> updateValues());

        mediaPlayer.setOnPlaying(() -> { playButton.setText("||"); });

        mediaPlayer.setOnPaused(() -> { playButton.setText(">"); });

        mediaPlayer.setOnReady(() -> {
            Media m = mediaPlayer.getMedia();
            duration = m.getDuration();
            Timecode tc = new Timecode(duration.toSeconds() * frameRate, frameRate);
            SwingUtilities.invokeLater(() -> maxTimecodeTextField.setText(tc.toString()));
            updateValues();
            onReadyRunnable.accept(this);
            readyProperty.setValue(true);
        });


        mediaPlayer.setOnEndOfMedia(() -> { playButton.setText(">"); });

        // ---  Configure play button
        playButton.setOnAction((e) -> {
            MediaPlayer.Status status = mediaPlayer.getStatus();
            System.out.println(status);
            if (status == MediaPlayer.Status.UNKNOWN ||  status == MediaPlayer.Status.HALTED) {
                // Do nothing
                return;
            }

            if (status == MediaPlayer.Status.PLAYING) {
                mediaPlayer.pause();
            }
            else if (status == MediaPlayer.Status.PAUSED
                    || status == MediaPlayer.Status.READY
                    || status == MediaPlayer.Status.STOPPED) {
                mediaPlayer.play();
            }

        });

        // --- Configure Scrubber
        scrubber.valueProperty().addListener(observable -> {
            if (scrubber.isValueChanging()) {
                // multiply duration by percentage calculated by slider position
                mediaPlayer.seek(duration.multiply(scrubber.getValue() / 100D));
            }
        });

    }
 
開發者ID:hohonuuli,項目名稱:vars,代碼行數:63,代碼來源:JFXMovieJFrameController.java


注:本文中的javafx.scene.media.MediaPlayer.setOnEndOfMedia方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。