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


Java MediaPlayer.play方法代碼示例

本文整理匯總了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();
}
 
開發者ID:jakemanning,項目名稱:boomer-tuner,代碼行數:20,代碼來源:Player.java

示例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();
}
 
開發者ID:shashanksingh28,項目名稱:code-similarity,代碼行數:26,代碼來源:JfxVideo.java

示例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();
}
 
開發者ID:mob41,項目名稱:osumer,代碼行數:18,代碼來源:BeforeSoundAction.java

示例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);
        }
    }
 
開發者ID:schwabdidier,項目名稱:GazePlay,代碼行數:24,代碼來源:Utils.java

示例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();
}
 
開發者ID:hendrikebbers,項目名稱:ExtremeGuiMakeover,代碼行數:22,代碼來源:MasterDetailViewController.java

示例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();
}
 
開發者ID:sebastienscout,項目名稱:Himalaya-JavaFX,代碼行數:23,代碼來源:Main.java

示例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();
}
 
開發者ID:JavaMugs,項目名稱:CloneHero,代碼行數:30,代碼來源:EditorController.java

示例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();
}
 
開發者ID:mob41,項目名稱:osumer,代碼行數:18,代碼來源:AfterSoundAction.java

示例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();
        }
    }
}
 
開發者ID:daothanhduy305,項目名稱:MusicHub,代碼行數:20,代碼來源:MainPlayerController.java

示例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
}
 
開發者ID:jesuino,項目名稱:livro-javafx-pratico,代碼行數:17,代碼來源:TocandoVideo.java

示例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;
}
 
開發者ID:Ghosts,項目名稱:Maus,代碼行數:20,代碼來源:NotificationView.java

示例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();
    });
}
 
開發者ID:kasemir,項目名稱:org.csstudio.display.builder,代碼行數:23,代碼來源:AudioDemo.java

示例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();
}
 
開發者ID:vfreitas-,項目名稱:ShopCarFX-2.0,代碼行數:34,代碼來源:TutorialPlayer.java

示例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();
	}		
}
 
開發者ID:LtubSalad,項目名稱:voogasalad-ltub,代碼行數:12,代碼來源:SoundManager.java

示例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();
}
 
開發者ID:cookerlyk,項目名稱:missile-defense,代碼行數:11,代碼來源:AudioPlayer.java


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