本文整理匯總了Java中javafx.scene.media.MediaPlayer.play方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaPlayer.play方法的具體用法?Java MediaPlayer.play怎麽用?Java MediaPlayer.play使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.scene.media.MediaPlayer
的用法示例。
在下文中一共展示了MediaPlayer.play方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: playCrossfade
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
private void playCrossfade(final List<? extends Playable> items, final int index) {
MediaPlayer oldPlayer = currentPlayer;
final double currentVolume = oldPlayer.getVolume();
oldPlayer.volumeProperty().unbind();
playQueue = new ArrayList<>(items);
currentIndex = index;
MediaPlayer newPlayer = new MediaPlayer(new Media(playQueue.get(currentIndex).getUri().toString()));
newPlayer.setVolume(0);
newPlayer.play();
Timeline crossfade = new Timeline(new KeyFrame(Duration.seconds(CROSSFADE_DURATION),
new KeyValue(oldPlayer.volumeProperty(), 0),
new KeyValue(newPlayer.volumeProperty(), currentVolume)));
crossfade.setOnFinished(event -> {
oldPlayer.stop();
setCurrentPlayer(newPlayer);
});
crossfade.play();
}
示例2: start
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("JavaFX Video");
final List<String> args = getParameters().getRaw();
String url = args.size() > 0 ?
args.get(args.size() - 1) :
"http://www.mediacollege.com/" +
"video-gallery/testclips/20051210-w50s.flv";
Media media = new Media(url);
MediaPlayer player = new MediaPlayer(media);
player.play();
MediaView view = new MediaView(player);
Group root = new Group();
root.getChildren().add(view);
Scene scene = SceneBuilder.create().
width(360).height(288).
root(root).
fill(Color.WHITE).
build();
primaryStage.setScene(scene);
primaryStage.show();
}
示例3: run
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void run(Queue queue) {
Thread thread = new Thread(new Runnable() {
public void run() {
try {
Media m = new Media(new File(config.getToneBeforeDownloadPath()).toURI().toString());
MediaPlayer mp = new MediaPlayer(m);
mp.play();
} catch (Exception e) {
e.printStackTrace();
DumpManager.getInstance().addDump(new DebugDump(null, "---", "Play before download sound", "---", "Error occurred when trying to play sound", false, e));
}
}
});
thread.setDaemon(true);
thread.start();
}
示例4: playSound
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
public static void playSound(String ressource) {
log.info("Try to play " + ressource);
URL url = ClassLoader.getSystemResource(ressource);
String path = null;
if (url == null) {
path = new File(ressource).toURI().toString();
} else
path = url.toString();
log.info("path " + path);
try {
Media media = new Media(path);
MediaPlayer mp = new MediaPlayer(media);
mp.play();
} catch (Exception e) {
log.error("Exception", e);
}
}
示例5: 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();
}
示例6: start
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void start(Stage stage) {
ScreensController mainContainer = new ScreensController();
mainContainer.loadScreen(screenMenuID, screenMenuFile);
mainContainer.loadScreen(screenMainID, screenMainFile);
mainContainer.setScreen(screenMenuID);
Group root = new Group();
root.getChildren().addAll(mainContainer);
Scene scene = new Scene(root, Color.TRANSPARENT);
stage.setScene(scene);
stage.show();
//Music Theme Himalya
File filestring = new File("src/resources/music/music_menu.mp3");
Media file = new Media(filestring.toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(file);
mediaPlayer.autoPlayProperty();
mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE);
mediaPlayer.play();
}
示例7: startBtnAction
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
/**
* FE start/stop button
*
* @param event
*/
public void startBtnAction(ActionEvent event) {
if (!isRecording) {
countLabel.setText("Recording");
startBtn.setText("Stop");
isRecording = true;
saveBtn.setVisible(false);
saver = new Saver();
Media sound = new Media(this.songPath);
mediaPlayer = new MediaPlayer(sound);
mediaPlayer.play();
textPresses.setText("");
} else {
countLabel.setText("Editor");
startBtn.setText("Start");
isRecording = false;
saveBtn.setVisible(true);
mediaPlayer.stop();
mediaPlayer = null;
}
startListenButtons();
}
示例8: run
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void run(Queue queue) {
Thread thread = new Thread(new Runnable() {
public void run() {
try {
Media m = new Media(new File(config.getToneAfterDownloadPath()).toURI().toString());
MediaPlayer mp = new MediaPlayer(m);
mp.play();
} catch (Exception e) {
e.printStackTrace();
DumpManager.getInstance().addDump(new DebugDump(null, "---", "Play after download sound", "---", "Error occurred when trying to play sound", false, e));
}
}
});
thread.setDaemon(true);
thread.start();
}
示例9: 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();
}
}
}
示例10: start
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void start(Stage palco) throws Exception {
Media media = new Media(VIDEO_URL); // 1
MediaPlayer mediaPlayer = new MediaPlayer(media); // 2
MediaView mediaView = new MediaView(mediaPlayer); // 3
StackPane raiz = new StackPane();
raiz.getChildren().add(mediaView); // 4
Scene cena = new Scene(raiz, 600, 400);
palco.setTitle("Tocando Video em JavaFX");
palco.setScene(cena);
palco.show();
mediaPlayer.play(); // 4
}
示例11: getNotificationView
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
private VBox getNotificationView() {
VBox vBox = new VBox(5);
vBox.setId("notification");
vBox.setAlignment(Pos.CENTER);
VBox.setVgrow(vBox, Priority.ALWAYS);
Image alert = new Image(getClass().getResourceAsStream("/Images/Icons/alert.png"));
ImageView imageView = new ImageView(alert);
notificationText = new Label("");
notificationText = (Label) Styler.styleAdd(notificationText, "label-light");
vBox.getChildren().addAll(imageView, notificationText);
vBox.getStylesheets().add(getClass().getResource("/css/global.css").toExternalForm());
if (MausSettings.SOUND) {
Media notify = new Media(getClass().getResource("/audio/notify.mp3").toExternalForm());
MediaPlayer mediaPlayer = new MediaPlayer(notify);
mediaPlayer.play();
}
Styler.styleAdd(vBox, "notification");
return vBox;
}
示例12: 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();
});
}
示例13: initComponents
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
@Override
public void initComponents()
{
media = new Media(getClass().getResource(RESOURCES + "videos/" + mediaName).toString());
mediaPlayer = new MediaPlayer(media);
mediaView = new MediaView(mediaPlayer);
slideIn = new Timeline();
slideOut = new Timeline();
rightTimer = new Label();
rightTimer.setId("lbl-timer");
leftTimer = new Label();
leftTimer.setId("lbl-timer");
vbox = new VBox(5);
vbox.setId("fundo-padrao");
test = new StackPane();
timeSlider = new Slider();
btnPlay = new Button();
btnPlay.setGraphic(new ImageView(imgPause));
btnPlay.setId("btn-play");
final HBox hbox = new HBox();
hbox.setAlignment(Pos.CENTER);
hbox.getChildren().addAll(leftTimer, btnPlay, rightTimer);
vbox.getChildren().addAll(timeSlider, hbox);
getChildren().addAll(mediaView, vbox);
mediaPlayer.play();
}
示例14: playSoundEffect
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
private void playSoundEffect(String soundFileName) {
Media sound = new Media(new File(soundFileName).toURI().toString());
try {
MediaPlayer soundEffect = new MediaPlayer(sound);
soundEffect.setVolume(soundEffectVolumn);
soundEffect.play();
soundPlayers.add(soundEffect);
}catch (MediaException e) {
new CustomAlert(AlertType.ERROR, "Sound Manager Error").show();
}
}
示例15: playSound
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
public void playSound(String folder, String filename) {
MediaPlayer mPlayer = findSound(folder, filename);
if(mPlayer == null) {
mPlayer = createMediaPlayer(folder, filename);
}
if(mPlayer.getCycleDuration().lessThanOrEqualTo(mPlayer.getCurrentTime())) {
mPlayer.seek(Duration.ZERO);
}
mPlayer.play();
}