Java 类javafx.scene.media.MediaPlayer 实例源码

项目:boomer-tuner    文件:Player.java   
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();
}
项目:ExtremeGuiMakeover    文件:MovieViewSkin.java   
private void addBackgroundMediaView() {
    Media media = new Media(MovieView.class.getResource("/backdrop-video.mp4").toExternalForm());
    MediaPlayer player = new MediaPlayer(media);
    player.setMute(true);
    MediaView mediaView = new MediaView(player);
    mediaView.setOpacity(.3);
    getChildren().add(mediaView);
    mediaView.visibleProperty().bind(getSkinnable().showMediaViewBackgroundProperty());
    getSkinnable().showMediaViewBackgroundProperty().addListener(it -> {
        if (getSkinnable().isShowMediaViewBackground()) {

            /*
             * Implementing our own infinite loop support.
             * The built-in cycle count support seems to be buggy.
             */
            player.setOnEndOfMedia(() -> {
                player.seek(Duration.ZERO);
                player.play();
            });
            player.play();
        } else {
            player.stop();
        }
    });
}
项目:SupPlayer    文件:Music.java   
public Music(File f)
{
    file = f;

    String path = StringUtil.convertToFileURL(file.toURI().getRawPath());
    String url = StringUtil.convertToFileURL(file.getAbsolutePath());
    String[] split = url.split("/");
    String uri = url.split("/")[split.length - 1];
    String[] sp = uri.split("\\.");
    format = new SimpleStringProperty(sp[sp.length - 1]);
    sp[sp.length - 1] = "";
    name = new SimpleStringProperty(String.join(".", sp));
    media = new MediaPlayer(new Media(path));
    duration = new SimpleStringProperty("");


}
项目:osumer    文件:BeforeSoundAction.java   
@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();
}
项目:osumer    文件:AfterSoundAction.java   
@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();
}
项目:GazePlay    文件:Utils.java   
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);
        }
    }
项目:boomer-tuner    文件:Player.java   
private void setCurrentPlayer(final MediaPlayer player) {
    currentPlayer = player;
    Category newItem = playQueue.get(currentIndex);
    switch (CategoryType.of(newItem)) {
        case Songs: newSongBeingPlayed(); break;
        case Videos: newVideoBeingPlayed(); break;
    }

    currentPlayer.setOnEndOfMedia(() -> {
        if (lastPlayed.size() > maxDeckSize) {
            lastPlayed.pollLast();
            lastPlayed.addFirst(playQueue.get(currentIndex));
        }

        currentIndex = nextIndex();
        Media media = new Media(playQueue.get(currentIndex).getUri().toString());
        setCurrentPlayer(new MediaPlayer(media));
        currentPlayer.play();
    });
    currentPlayer.statusProperty()
            .addListener((observable, oldValue, newValue) -> playingStatusChanged(newValue));
    currentPlayer.currentTimeProperty().addListener(ov -> timeUpdated());
    currentPlayer.currentTimeProperty().addListener(crossfadeTimeListener());
    currentPlayer.setOnReady(this::timeUpdated);
    currentPlayer.volumeProperty().bind(volume);
}
项目:ExtremeGuiMakeover    文件:MasterDetailViewController.java   
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();
}
项目:ExtremeGuiMakeover    文件:MediaControl.java   
protected void updateValues() {
    if (playTime != null && timeSlider != null && volumeSlider != null) {
        Platform.runLater(() -> {
            MediaPlayer mp = getMediaPlayer();

            Duration currentTime = mp.getCurrentTime();
            playTime.setText(formatTime(currentTime, duration));
            timeSlider.setDisable(duration.isUnknown());
            if (!timeSlider.isDisabled()
                    && duration.greaterThan(Duration.ZERO)
                    && !timeSlider.isValueChanging()) {
                timeSlider.setValue(currentTime.divide(duration).toMillis()
                        * 100.0);
            }
            if (!volumeSlider.isValueChanging()) {
                volumeSlider.setValue((int) Math.round(mp.getVolume()
                        * 100));
            }
        });
    }
}
项目:Himalaya-JavaFX    文件:Main.java   
@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();
}
项目:szoftlab    文件:Game.java   
/**
 * Instantiates a new model.Game.
 * <p>
 * Init szekvencia.
 * </p>
 */
public Game() {
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("game.fxml"));
    Parent root = null;
    try {
        root = fxmlLoader.load();
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
    Controller ctrl = fxmlLoader.getController();
    ctrl.setModel(this);
    timer = new SimulationTimer();
    mapManager = new MapManager(timer, this);
    view = new View(mapManager, ctrl);
    view.setScene(new Scene(root));
    timer.setView(view);
    winMedia = new MediaPlayer(new Media(new File(winSound).toURI().toString()));
    loseMedia = new MediaPlayer(new Media(new File(loseSound).toURI().toString()));
}
项目:Music_Player_material_design_javaFX    文件:Main.java   
private void loadingParam() {
    File paramFile = new File("res/Parameters");
    Scanner sc;
    try {
        sc = new Scanner(paramFile);
        if (sc.hasNextLine()) {
            isRandom = Boolean.valueOf(sc.nextLine());
            musicIndex = Integer.valueOf(sc.nextLine());
        }
        hit = new Media(musicList.get(musicIndex).toURI().toString());
        mediaPlayer = new MediaPlayer(hit);
        mediaPlayer.setOnReady(this::playMusic);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:CloneHero    文件:EditorController.java   
/**
 * 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();
}
项目:fx-video-viewer    文件:FxVideoViewer.java   
public void closeMedia() {
    final MediaView mediaView = getMediaView();
    if (null == mediaView) return;
    //
    mediaView.fitHeightProperty().unbind();
    mediaView.fitWidthProperty().unbind();
    //
    final MediaPlayer mediaPlayer = mediaView.getMediaPlayer();
    if (null != mediaPlayer) {
        mediaPlayer.stop();
        mediaPlayer.volumeProperty().unbind();
        mediaPlayer.onReadyProperty().unbind();
        mediaPlayer.dispose();
        //
        mediaView.setOnScroll(null);
        mediaView.setOnMouseClicked(null);
        mediaView.setMediaPlayer(null);
    }
    //
    getChildren().remove(mediaView);
    MEDIA_VIEW.set(null);
}
项目:SudoTimer    文件:MainViewController.java   
public void startAction() {

        timer1 = null;
        task = null;

        if (currentMinutes <= 0 && currentSeconds <= 0) {
            currentMinutes = 10;
            currentSeconds = 0;

        }
        setTimer(currentMinutes, currentSeconds);

        media = new Media(path);
        mp = new MediaPlayer(media);

        reset.setDisable(false);
        stop.setDisable(false);
        pomodoro.setDisable(false);
        shortBreak.setDisable(false);
        longBreak.setDisable(false);
        volume.setDisable(false);
    }
项目:Hacking-Demo    文件:VideoPlayer.java   
public VideoPlayer(String p) 
{
    super();

    this.file = new Media(p);
    this.player = new MediaPlayer(this.file);
    this.view = new MediaView(this.player);

    this.pane = new BorderPane();
    this.fxScene = new Scene(this.pane);

    this.pane.setCenter(this.view);

    this.fxScene.setFill(Paint.valueOf("black"));

    this.addComponentListener(this);
    this.addKeyListener(this);
    this.componentResized(null);

    this.setScene(this.fxScene);
}
项目:Game-Engine-Vooga    文件:GameboyDisplay.java   
/**
     * Method that contains a series of initialize statements
     * 
     */
    private void initialize() {
        myPromptFactory = new PromptFactory();
//      myControl = new StandardControl(getGameRunner());
        //myHUD = new StandardHUD(getGameRunner());
        myStage = new Stage();
        myPane = new AnchorPane();
        myPane.setId("bp");
        myGameScreen = new Pane();
        myPrompt = new PromptFactory();
        myKeyEvents = new ArrayList<>();
        myBGM = new Media(new File(BGM_PATH).toURI().toString());
        myMediaPlayer = new MediaPlayer(myBGM);
        myScreensHolder = new StackPane();
        myUIScreen = new Pane();

    }
项目:SokubanFX    文件:VideoLoader.java   
public MediaPlayer loadVideo(int videoIndex) {
    LoggerFacade.INSTANCE.debug(this.getClass(), "Load video"); // NOI18N

    final StringBuilder sb = new StringBuilder();
    sb.append(PREFIX__VIDEO);
    sb.append(videoIndex);
    sb.append(SUFFIX__FILE);

    final String video = PropertiesFacade.INSTANCE.getProperty(KEY__RESOURCE_BUNDLE__VIDEO, sb.toString());
    try {
        final Media media = new Media(this.getClass().getResource(video).toURI().toString());
        final MediaPlayer mediaPlayer = new MediaPlayer(media);
        mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE);
        mediaPlayer.setOnReady(() -> {
            mediaPlayer.play();
        });

        return mediaPlayer;
    } catch (URISyntaxException ex) {
        LoggerFacade.INSTANCE.error(this.getClass(), "Can't load video: " + video, ex); // NOI18N
    }

    return null;
}
项目:osumer    文件:BeforeSoundAction.java   
@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();
}
项目:osumer    文件:AfterSoundAction.java   
@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();
}
项目:MusicHub    文件:MainPlayerController.java   
@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();
        }
    }
}
项目:livro-javafx-pratico    文件:TocandoVideo.java   
@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
}
项目:code-similarity    文件:JfxVideo.java   
@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();
}
项目:Maus    文件:NotificationView.java   
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;
}
项目:Verse    文件:MainMenu.java   
/**
 * Level initialisieren
 *
 * @param collector - Objektsammler
 */
@Override
protected void init(ObjectCollector collector) {

    rdm = new Random();

    // Init Hintergrundmusik
    menuTheme = new Media(getClass().getResource("/de/janroslan/verse/resources/sounds/menu.aiff").toExternalForm());
    mplayer = new MediaPlayer(menuTheme);
    mplayer.setVolume(0.7);
    mplayer.setAutoPlay(true);

    // Init Maus Hover Sound
    buttonHoverSound = new AudioClip(getClass().getResource("/de/janroslan/verse/resources/sounds/click.wav").toString());

    initPictures(collector);
    initObjs(collector);
    initTexts(collector);
    initButtons(collector);


}
项目:Java-MP3-player    文件:EqualizerPresets.java   
void previous_Mode(int index,JSlider bands[],MediaPlayer mediaPlayer ,JLabel name)
{
    index=(index<0?17:index);
    name.setText(this.name[index]);   

    double previous_val,next_val;
    for(int i=0;i<10;i++)
    {
        previous_val=mediaPlayer.getAudioEqualizer().getBands().get(i).MAX_GAIN*2;
        mediaPlayer.getAudioEqualizer().getBands().get(i).setGain(Presets[index][i]);
        next_val=mediaPlayer.getAudioEqualizer().getBands().get(i).getGain();


        bands[i].setValue((int)(Math.abs(next_val/previous_val)*100));
    }

}
项目:minesim    文件:Music.java   
/**
 * The constructor method for music, takes an ArrayList and creates the instance of the class
 * using the default play list
 * @param playlistStrings is a list of strings that music initializes with, accessing those sound files
 * and turning them into a play list to be played.
 */
public Music(List<String> playlistStrings) {
    persistentSettings();
    playlist = new ArrayList<MediaPlayer>();
    for (int i = 0; i < playlistStrings.size(); i++) {
        try {
            URL url = Music.class.getResource("../Music/" + playlistStrings.get(i));
            Media media = new Media(url.toString());
            MediaPlayer listPlayer = new MediaPlayer(media);
            playlist.add(listPlayer);
        } catch (RuntimeException re) {
            LOG.error("There was an error creating the mediaplayer, perhaps incorrect filename or it is not" +
                    " stored in the music folder under resources", re);
        }
    }
}
项目:JavaFX-Chat    文件:ChatController.java   
public void newUserNotification(Message msg) {
    Platform.runLater(() -> {
        Image profileImg = new Image(getClass().getClassLoader().getResource("images/" + msg.getPicture().toLowerCase() +".png").toString(),50,50,false,false);
        TrayNotification tray = new TrayNotification();
        tray.setTitle("A new user has joined!");
        tray.setMessage(msg.getName() + " has joined the JavaFX Chatroom!");
        tray.setRectangleFill(Paint.valueOf("#2C3E50"));
        tray.setAnimationType(AnimationType.POPUP);
        tray.setImage(profileImg);
        tray.showAndDismiss(Duration.seconds(5));
        try {
            Media hit = new Media(getClass().getClassLoader().getResource("sounds/notification.wav").toString());
            MediaPlayer mediaPlayer = new MediaPlayer(hit);
            mediaPlayer.play();
        } catch (Exception e) {
            e.printStackTrace();
        }

    });
}
项目:NoMoreDropboxMSN    文件:AudioPanel.java   
MusicPlayer(File f){
    this.song = new Media(Paths.get(f.getAbsolutePath()).toUri().toString());
    this.player = new MediaPlayer(song);
    while(player.getStatus() != MediaPlayer.Status.READY){
        try {
            sleep(10);
        } catch (InterruptedException ex) {}
    }
    this.length = player.getTotalDuration().toSeconds();
    this.state = MusicPlayerState.STOPPED;
    this.songName = f.getName();
    this.player.setOnEndOfMedia(new Runnable() {
        @Override
        public void run() {
            player.stop();
            state = MusicPlayerState.STOPPED;
        }
    });
}
项目:fr.xs.jtk    文件:PlayerFX.java   
private void setCurrentlyPlaying(final MediaPlayer newPlayer) {
    progress.setProgress(0);
    progressChangeListener = new ChangeListener<Duration>() {
        @Override
        public void changed(
                ObservableValue<? extends Duration> observableValue,
                Duration oldValue, Duration newValue) {
            progress.setProgress(1.0
                    * newPlayer.getCurrentTime().toMillis()
                    / newPlayer.getTotalDuration().toMillis());
        }
    };
    newPlayer.currentTimeProperty().addListener(progressChangeListener);

    String source = newPlayer.getMedia().getSource();
    source = source.substring(0, source.length() - ".mp4".length());
    source = source.substring(source.lastIndexOf("/") + 1).replaceAll("%20", " ");
    currentlyPlaying.setText("Now Playing: " + source + "(" + mediaView.getMediaPlayer().getTotalDuration() + ")");

    slider.setMax(mediaView.getMediaPlayer().getTotalDuration().toMillis());
    slider.setMajorTickUnit(mediaView.getMediaPlayer().getTotalDuration().toMillis());
    slider.setValue(0);

}
项目:org.csstudio.display.builder    文件:AudioDemo.java   
@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();
    });
}
项目:contentment    文件:MediaRhythm.java   
public MediaRhythm(String mediaString)
{
    Media m = new Media(mediaString);
    mediaPlayer = new MediaPlayer(m);
    mediaPlayer.pause();
    beatProperty = new SimpleLongProperty(0L);
    isPlaying = false;
    startedPauseAt = 0L;
    timer = new AnimationTimer()
    {

        @Override
        public void handle(long now)
        {
            update();
        }
    };

}
项目:StreamSis    文件:MultiSoundAction.java   
@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);
    }
}
项目:yummy-xml-UI    文件:VideoPlayer.java   
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);
    }
项目:Cherno    文件:Sound.java   
private void create(final String file) {
    final File soundFile = new File(file);
    if (!soundFile.exists()) {
        System.err.println("Sound File \"" + file + "\" not found!");
        return;
    }
    String[] strings = file.split("/");
    this.soundFile = strings[strings.length - 1];
    new Thread() {
        public void run() {
            try {
                sound = new MediaPlayer(new Media(soundFile.toURI().toString()));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
}
项目:ShopCarFX-2.0    文件:TutorialPlayer.java   
@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();
}
项目:cn1    文件:JavaSEPort.java   
public VideoComponent(JFrame frm, final javafx.embed.swing.JFXPanel vid, javafx.scene.media.MediaPlayer player) {
    super(null);
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            cnt.setLayout(new BorderLayout());
            cnt.add(BorderLayout.CENTER, vid);
            cnt.setVisible(false);
        }
    });

    Group root = new Group();
    v = new MediaView(player);
    root.getChildren().add(v);
    vid.setScene(new Scene(root));

    this.vid = vid;
    this.frm = frm;
}
项目:Multiplication_Dungeon    文件:UsefulSnippets.java   
public static void playMusic(String fileLoc) {
    if (SettingsProperties.programSound == true) {
        try {
            Thread sound;
            sound = new Thread() {
                public void run() {
                    try {
                        Media mu = new Media(fileLoc);
                        MediaPlayer mediaPlayer = new MediaPlayer(mu);
                        mediaPlayer.play();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            sound.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
项目:javafx-demos    文件:JavaFX_VideoPlayer.java   
@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("java-buddy.blogspot.com/");

    Group root = new Group();
    Scene scene = new Scene(root, 540, 210);

    // create media player
    Media media = new Media((arg1 != null) ? arg1 : MEDIA_URL);
    MediaPlayer mediaPlayer = new MediaPlayer(media);
    mediaPlayer.setAutoPlay(true);

    // create mediaView and add media player to the viewer
    MediaView mediaView = new MediaView(mediaPlayer);
    ((Group)scene.getRoot()).getChildren().add(mediaView);

    primaryStage.setScene(scene);
    primaryStage.show();
}
项目:javafx-demos    文件:MediaPlayerDemo.java   
public void start(Stage primaryStage) {
    primaryStage.setTitle("Embedded Media Player");
    Group root = new Group();
    Scene scene = new Scene(root, 540, 241);

    // create media player
    Media media = new Media("D:\\Pradeep\\Funny Mails\\Magic Sand.wmv");
    MediaPlayer mediaPlayer = new MediaPlayer(media);
    mediaPlayer.setAutoPlay(true);
    StackPane stack = new StackPane();

    Text t = new Text("Subtitle..");
 // t.textProperty().addChangeListener(..);
//    MediaControl mediaControl = new MediaControl(mediaPlayer);
    MediaView m =new MediaView(mediaPlayer);

    stack.getChildren().addAll(m, t);
    scene.setRoot(stack);

    primaryStage.setScene(scene);
    primaryStage.show();
}