Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java Swing应用程序中播放MP4视频_Java_Video_Jframe_Jpanel_Mp4 - Fatal编程技术网

如何在Java Swing应用程序中播放MP4视频

如何在Java Swing应用程序中播放MP4视频,java,video,jframe,jpanel,mp4,Java,Video,Jframe,Jpanel,Mp4,有人知道我可以在JPanel中播放.mp4视频文件的方法吗? 我曾尝试使用.avi文件使用JMF,但没有成功,现在我对播放视频文件这样简单的任务变得如此乏味感到困惑和沮丧 请外面的任何人告诉我我可以走哪条路,我将非常感激 我听说过VLCJ,但问题是我不能保证运行此应用程序的每台机器都会安装VLC播放器。有没有办法将VLC播放器捆绑到分发文件夹中 最初,我们使用的视频是在Vimeo上的,但事实证明,由于缺乏API支持,几乎不可能嵌入它,我想我可以在本地播放它,现在甚至变得非常困难。感谢@VGR让我

有人知道我可以在JPanel中播放.mp4视频文件的方法吗? 我曾尝试使用.avi文件使用JMF,但没有成功,现在我对播放视频文件这样简单的任务变得如此乏味感到困惑和沮丧

请外面的任何人告诉我我可以走哪条路,我将非常感激

我听说过VLCJ,但问题是我不能保证运行此应用程序的每台机器都会安装VLC播放器。有没有办法将VLC播放器捆绑到分发文件夹中


最初,我们使用的视频是在Vimeo上的,但事实证明,由于缺乏API支持,几乎不可能嵌入它,我想我可以在本地播放它,现在甚至变得非常困难。

感谢@VGR让我注意到JavaFX,我刚刚将一个JFXPanel集成到一个JPanel中,它显示了我想要的视频位置。在我的例子中,它工作得非常好,因为它是一个简单的屏幕,只有一个视频可以播放

下面是完整的代码片段:

private void getVideo(){
    final JFXPanel VFXPanel = new JFXPanel();

    File video_source = new File("tutorial.mp4");
    Media m = new Media(video_source.toURI().toString());
    MediaPlayer player = new MediaPlayer(m);
    MediaView viewer = new MediaView(player);

    StackPane root = new StackPane();
    Scene scene = new Scene(root);

    // center video position
    javafx.geometry.Rectangle2D screen = Screen.getPrimary().getVisualBounds();
    viewer.setX((screen.getWidth() - videoPanel.getWidth()) / 2);
    viewer.setY((screen.getHeight() - videoPanel.getHeight()) / 2);

    // resize video based on screen size
    DoubleProperty width = viewer.fitWidthProperty();
    DoubleProperty height = viewer.fitHeightProperty();
    width.bind(Bindings.selectDouble(viewer.sceneProperty(), "width"));
    height.bind(Bindings.selectDouble(viewer.sceneProperty(), "height"));
    viewer.setPreserveRatio(true);

    // add video to stackpane
    root.getChildren().add(viewer);

    VFXPanel.setScene(scene);
    //player.play();
    videoPanel.setLayout(new BorderLayout());
    videoPanel.add(VFXPanel, BorderLayout.CENTER);
}

一旦创建了getVideo()函数,我就在JFrame的构造函数中调用它,以便在应用程序启动时触发它。带MediaControl的播放器

public class MainFrame {

private JFrame frmPlayerJava;
private JFXPanel videoPanel;

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                MainFrame window = new MainFrame();
                window.frmPlayerJava.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        
    });
}

public MainFrame() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frmPlayerJava = new JFrame();
    frmPlayerJava.setTitle("Player Java");
    frmPlayerJava.setBounds(100, 100, 1260, 782);
    frmPlayerJava.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frmPlayerJava.getContentPane().setLayout(null);
    videoPanel = new JFXPanel();
    videoPanel.setBorder(new LineBorder(new Color(0, 0, 0), 2));
    videoPanel.setBounds(714, 309, 509, 317);
    frmPlayerJava.getContentPane().add(videoPanel);
    
    JLabel Title = new JLabel("Metus Player Java");
    Title.setHorizontalAlignment(SwingConstants.CENTER);
    Title.setFont(new Font("Tahoma", Font.PLAIN, 24));
    Title.setBounds(502, 11, 289, 42);
    frmPlayerJava.getContentPane().add(Title);
    
    
    JButton btnNewButton = new JButton("Play");
    btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 23));
    btnNewButton.setBounds(870, 637, 228, 79);
    frmPlayerJava.getContentPane().add(btnNewButton);

    
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
                getVideo();
        }
    });
}

private void getVideo(){
    File video_source = new File("video.mp4");
    Media m = new Media(video_source.toURI().toString());
    //Media m = new Media("https://www.youtube.com/embed/qzW6mgfY5X4");
    MediaPlayer player = new MediaPlayer(m);
    player.play();
    MediaControl mediaControl = new MediaControl(player);
    
    StackPane root = new StackPane();
    Scene scene = new Scene(root);
    scene.setRoot(mediaControl);
    
    // add video to stackpane
    videoPanel.setScene(scene);
    
}
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaPlayer.Status;
import javafx.scene.media.MediaView;
import javafx.util.Duration;

public class MediaControl extends BorderPane {
    this.mp = mp;
    setStyle("-fx-background-color: #bfc2c7;");
    mediaView = new MediaView(mp);
    StackPane mvPane = new StackPane() {
    };
    
    mvPane.getChildren().add(mediaView);
    mvPane.setStyle("-fx-background-color: black;");
    mediaView.fitWidthProperty().bind(mvPane.widthProperty());
    mediaView.fitHeightProperty().bind(mvPane.heightProperty());
    mediaView.setPreserveRatio(true);
    setCenter(mvPane);

    mediaBar = new HBox();
    mediaBar.setAlignment(Pos.CENTER);
    mediaBar.setPadding(new Insets(5, 10, 5, 10));
    BorderPane.setAlignment(mediaBar, Pos.CENTER);

    final Button playButton = new Button(">");

    playButton.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent e) {
            Status status = mp.getStatus();

            if (status == Status.UNKNOWN || status == Status.HALTED) {
                // don't do anything in these states
                return;
            }

            if (status == Status.PAUSED
                    || status == Status.READY
                    || status == Status.STOPPED) {
                // rewind the movie if we're sitting at the end
                if (atEndOfMedia) {
                    mp.seek(mp.getStartTime());
                    atEndOfMedia = false;
                }
                mp.play();
            } else {
                mp.pause();
            }
        }
    });
    mp.currentTimeProperty().addListener(new InvalidationListener() {
        public void invalidated(Observable ov) {
            updateValues();
        }
    });

    mp.setOnPlaying(new Runnable() {
        public void run() {
            if (stopRequested) {
                mp.pause();
                stopRequested = false;
            } else {
                playButton.setText("||");
            }
        }
    });

    mp.setOnPaused(new Runnable() {
        public void run() {
            System.out.println("onPaused");
            playButton.setText(">");
        }
    });

    mp.setOnReady(new Runnable() {
        public void run() {
            duration = mp.getMedia().getDuration();
            System.out.println("Duration: "+duration);
            updateValues();
        }
    });

    mp.setCycleCount(repeat ? MediaPlayer.INDEFINITE : 1);
    mp.setOnEndOfMedia(new Runnable() {
        public void run() {
            System.out.println("Entre");
            if (!repeat) {
                playButton.setText(">");
                stopRequested = true;
                atEndOfMedia = true;
            }
        }
    });

    mediaBar.getChildren().add(playButton);
    // Add spacer
    Label spacer = new Label("   ");
    mediaBar.getChildren().add(spacer);

    // Add Time label
    Label timeLabel = new Label("Tiempo: ");
    mediaBar.getChildren().add(timeLabel);

    // Add time slider
    timeSlider = new Slider();
    HBox.setHgrow(timeSlider, Priority.ALWAYS);
    timeSlider.setMinWidth(50);
    timeSlider.setMaxWidth(Double.MAX_VALUE);
    timeSlider.valueProperty().addListener(new InvalidationListener() {
        public void invalidated(Observable ov) {
            if (timeSlider.isValueChanging()) {
                // multiply duration by percentage calculated by slider position
                mp.seek(duration.multiply(timeSlider.getValue() / 100.0));
            }
        }
    });
    mediaBar.getChildren().add(timeSlider);
    
    Label spacer1 = new Label("   ");
    mediaBar.getChildren().add(spacer1);
    
    // Add Play label
    playTime = new Label();
    playTime.setPrefWidth(130);
    playTime.setMinWidth(50);
    mediaBar.getChildren().add(playTime);

    // Add the volume label
    Label volumeLabel = new Label("Vol: ");
    mediaBar.getChildren().add(volumeLabel);

    // Add Volume slider
    volumeSlider = new Slider(0,100,100);
    volumeSlider.setPrefWidth(70);
    volumeSlider.setMaxWidth(Region.USE_PREF_SIZE);
    volumeSlider.setMinWidth(30);
    volumeSlider.valueProperty().addListener(new InvalidationListener() {
        public void invalidated(Observable ov) {
            if (volumeSlider.isValueChanging()) {
                mp.setVolume(volumeSlider.getValue() / 100.0);
            }
        }
    });
    mediaBar.getChildren().add(volumeSlider);

    setBottom(mediaBar);
}

protected void updateValues() {
    if (playTime != null && timeSlider != null && volumeSlider != null) {
        Platform.runLater(new Runnable() {
            public void run() {
                duration = mp.getMedia().getDuration();
                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));
                }
            }
        });
    }
}

private static String formatTime(Duration elapsed, Duration duration) {
    int intElapsed = (int) Math.floor(elapsed.toSeconds());
    int elapsedHours = intElapsed / (60 * 60);
    if (elapsedHours > 0) {
        intElapsed -= elapsedHours * 60 * 60;
    }
    int elapsedMinutes = intElapsed / 60;
    int elapsedSeconds = intElapsed - elapsedHours * 60 * 60
            - elapsedMinutes * 60;

    if (duration.greaterThan(Duration.ZERO)) {
        int intDuration = (int) Math.floor(duration.toSeconds());
        int durationHours = intDuration / (60 * 60);
        if (durationHours > 0) {
            intDuration -= durationHours * 60 * 60;
        }
        int durationMinutes = intDuration / 60;
        int durationSeconds = intDuration - durationHours * 60 * 60
                - durationMinutes * 60;
        if (durationHours > 0) {
            return String.format("%d:%02d:%02d/%d:%02d:%02d",
                    elapsedHours, elapsedMinutes, elapsedSeconds,
                    durationHours, durationMinutes, durationSeconds);
        } else {
            return String.format("%02d:%02d/%02d:%02d",
                    elapsedMinutes, elapsedSeconds, durationMinutes,
                    durationSeconds);
        }
    } else {
        if (elapsedHours > 0) {
            return String.format("%d:%02d:%02d", elapsedHours,
                    elapsedMinutes, elapsedSeconds);
        } else {
            return String.format("%02d:%02d", elapsedMinutes,
                    elapsedSeconds);
        }
    }
}
类媒体控件

public class MainFrame {

private JFrame frmPlayerJava;
private JFXPanel videoPanel;

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                MainFrame window = new MainFrame();
                window.frmPlayerJava.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        
    });
}

public MainFrame() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frmPlayerJava = new JFrame();
    frmPlayerJava.setTitle("Player Java");
    frmPlayerJava.setBounds(100, 100, 1260, 782);
    frmPlayerJava.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frmPlayerJava.getContentPane().setLayout(null);
    videoPanel = new JFXPanel();
    videoPanel.setBorder(new LineBorder(new Color(0, 0, 0), 2));
    videoPanel.setBounds(714, 309, 509, 317);
    frmPlayerJava.getContentPane().add(videoPanel);
    
    JLabel Title = new JLabel("Metus Player Java");
    Title.setHorizontalAlignment(SwingConstants.CENTER);
    Title.setFont(new Font("Tahoma", Font.PLAIN, 24));
    Title.setBounds(502, 11, 289, 42);
    frmPlayerJava.getContentPane().add(Title);
    
    
    JButton btnNewButton = new JButton("Play");
    btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 23));
    btnNewButton.setBounds(870, 637, 228, 79);
    frmPlayerJava.getContentPane().add(btnNewButton);

    
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
                getVideo();
        }
    });
}

private void getVideo(){
    File video_source = new File("video.mp4");
    Media m = new Media(video_source.toURI().toString());
    //Media m = new Media("https://www.youtube.com/embed/qzW6mgfY5X4");
    MediaPlayer player = new MediaPlayer(m);
    player.play();
    MediaControl mediaControl = new MediaControl(player);
    
    StackPane root = new StackPane();
    Scene scene = new Scene(root);
    scene.setRoot(mediaControl);
    
    // add video to stackpane
    videoPanel.setScene(scene);
    
}
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaPlayer.Status;
import javafx.scene.media.MediaView;
import javafx.util.Duration;

public class MediaControl extends BorderPane {
    this.mp = mp;
    setStyle("-fx-background-color: #bfc2c7;");
    mediaView = new MediaView(mp);
    StackPane mvPane = new StackPane() {
    };
    
    mvPane.getChildren().add(mediaView);
    mvPane.setStyle("-fx-background-color: black;");
    mediaView.fitWidthProperty().bind(mvPane.widthProperty());
    mediaView.fitHeightProperty().bind(mvPane.heightProperty());
    mediaView.setPreserveRatio(true);
    setCenter(mvPane);

    mediaBar = new HBox();
    mediaBar.setAlignment(Pos.CENTER);
    mediaBar.setPadding(new Insets(5, 10, 5, 10));
    BorderPane.setAlignment(mediaBar, Pos.CENTER);

    final Button playButton = new Button(">");

    playButton.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent e) {
            Status status = mp.getStatus();

            if (status == Status.UNKNOWN || status == Status.HALTED) {
                // don't do anything in these states
                return;
            }

            if (status == Status.PAUSED
                    || status == Status.READY
                    || status == Status.STOPPED) {
                // rewind the movie if we're sitting at the end
                if (atEndOfMedia) {
                    mp.seek(mp.getStartTime());
                    atEndOfMedia = false;
                }
                mp.play();
            } else {
                mp.pause();
            }
        }
    });
    mp.currentTimeProperty().addListener(new InvalidationListener() {
        public void invalidated(Observable ov) {
            updateValues();
        }
    });

    mp.setOnPlaying(new Runnable() {
        public void run() {
            if (stopRequested) {
                mp.pause();
                stopRequested = false;
            } else {
                playButton.setText("||");
            }
        }
    });

    mp.setOnPaused(new Runnable() {
        public void run() {
            System.out.println("onPaused");
            playButton.setText(">");
        }
    });

    mp.setOnReady(new Runnable() {
        public void run() {
            duration = mp.getMedia().getDuration();
            System.out.println("Duration: "+duration);
            updateValues();
        }
    });

    mp.setCycleCount(repeat ? MediaPlayer.INDEFINITE : 1);
    mp.setOnEndOfMedia(new Runnable() {
        public void run() {
            System.out.println("Entre");
            if (!repeat) {
                playButton.setText(">");
                stopRequested = true;
                atEndOfMedia = true;
            }
        }
    });

    mediaBar.getChildren().add(playButton);
    // Add spacer
    Label spacer = new Label("   ");
    mediaBar.getChildren().add(spacer);

    // Add Time label
    Label timeLabel = new Label("Tiempo: ");
    mediaBar.getChildren().add(timeLabel);

    // Add time slider
    timeSlider = new Slider();
    HBox.setHgrow(timeSlider, Priority.ALWAYS);
    timeSlider.setMinWidth(50);
    timeSlider.setMaxWidth(Double.MAX_VALUE);
    timeSlider.valueProperty().addListener(new InvalidationListener() {
        public void invalidated(Observable ov) {
            if (timeSlider.isValueChanging()) {
                // multiply duration by percentage calculated by slider position
                mp.seek(duration.multiply(timeSlider.getValue() / 100.0));
            }
        }
    });
    mediaBar.getChildren().add(timeSlider);
    
    Label spacer1 = new Label("   ");
    mediaBar.getChildren().add(spacer1);
    
    // Add Play label
    playTime = new Label();
    playTime.setPrefWidth(130);
    playTime.setMinWidth(50);
    mediaBar.getChildren().add(playTime);

    // Add the volume label
    Label volumeLabel = new Label("Vol: ");
    mediaBar.getChildren().add(volumeLabel);

    // Add Volume slider
    volumeSlider = new Slider(0,100,100);
    volumeSlider.setPrefWidth(70);
    volumeSlider.setMaxWidth(Region.USE_PREF_SIZE);
    volumeSlider.setMinWidth(30);
    volumeSlider.valueProperty().addListener(new InvalidationListener() {
        public void invalidated(Observable ov) {
            if (volumeSlider.isValueChanging()) {
                mp.setVolume(volumeSlider.getValue() / 100.0);
            }
        }
    });
    mediaBar.getChildren().add(volumeSlider);

    setBottom(mediaBar);
}

protected void updateValues() {
    if (playTime != null && timeSlider != null && volumeSlider != null) {
        Platform.runLater(new Runnable() {
            public void run() {
                duration = mp.getMedia().getDuration();
                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));
                }
            }
        });
    }
}

private static String formatTime(Duration elapsed, Duration duration) {
    int intElapsed = (int) Math.floor(elapsed.toSeconds());
    int elapsedHours = intElapsed / (60 * 60);
    if (elapsedHours > 0) {
        intElapsed -= elapsedHours * 60 * 60;
    }
    int elapsedMinutes = intElapsed / 60;
    int elapsedSeconds = intElapsed - elapsedHours * 60 * 60
            - elapsedMinutes * 60;

    if (duration.greaterThan(Duration.ZERO)) {
        int intDuration = (int) Math.floor(duration.toSeconds());
        int durationHours = intDuration / (60 * 60);
        if (durationHours > 0) {
            intDuration -= durationHours * 60 * 60;
        }
        int durationMinutes = intDuration / 60;
        int durationSeconds = intDuration - durationHours * 60 * 60
                - durationMinutes * 60;
        if (durationHours > 0) {
            return String.format("%d:%02d:%02d/%d:%02d:%02d",
                    elapsedHours, elapsedMinutes, elapsedSeconds,
                    durationHours, durationMinutes, durationSeconds);
        } else {
            return String.format("%02d:%02d/%02d:%02d",
                    elapsedMinutes, elapsedSeconds, durationMinutes,
                    durationSeconds);
        }
    } else {
        if (elapsedHours > 0) {
            return String.format("%d:%02d:%02d", elapsedHours,
                    elapsedMinutes, elapsedSeconds);
        } else {
            return String.format("%02d:%02d", elapsedMinutes,
                    elapsedSeconds);
        }
    }
}
导入javafx.application.Platform;
导入javafx.beans.InvalizationListener;
导入javafx.beans.Observable;
导入javafx.event.ActionEvent;
导入javafx.event.EventHandler;
导入javafx.scene.layout.Priority;
导入javafx.scene.layout.Region;
导入javafx.scene.layout.StackPane;
导入javafx.geometry.Insets;
导入javafx.geometry.Pos;
导入javafx.scene.control.Button;
导入javafx.scene.control.Label;
导入javafx.scene.control.Slider;
导入javafx.scene.layout.BorderPane;
导入javafx.scene.layout.HBox;
导入javafx.scene.media.MediaPlayer;
导入javafx.scene.media.MediaPlayer.Status;
导入javafx.scene.media.MediaView;
导入javafx.util.Duration;
公共类MediaControl扩展了BorderPane{
this.mp=mp;
设置样式(“-fx背景色:#bfc2c7;”);
mediaView=新mediaView(mp);
StackPane mvPane=新建StackPane(){
};
mvPane.getChildren().add(mediaView);
mvPane.setStyle(“-fx背景色:黑色;”);
mediaView.fitWidthProperty().bind(mvPane.widthProperty());
mediaView.fitHeightProperty().bind(mvPane.heightProperty());
mediaView.setPreserveRatio(true);
设置中心(mvPane);
mediaBar=新的HBox();
mediaBar.setAlignment(位置中心);
mediaBar.setPadding(新插图(5,10,5,10));
边框窗格。设置对齐(mediaBar,位置中心);
最终按钮playButton=新按钮(“>”);

playButton.setOnAction(新的EventHandler

您必须使用Swing吗?JavaFX有一个可能可以播放它的软件包。@VGR不幸的是,是的,因为我已经完成了70%的开发,并且我没有预见到这个特殊的问题。我花了一段时间才注意到
//player.play();
被注释掉了。否则,效果很好。