我如何在一个屏幕上播放两个视频?

时间:2012-04-05 06:24:00

标签: android video android-video-player

我必须制作一个应用程序,我需要在屏幕上同时播放两个视频。 这是我的代码。但视频没有播放。我在哪里做错了? :(

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
    myVideoView.setVideoURI(Uri.parse(SrcPath));
    myVideoView.setMediaController(new MediaController(this));
    myVideoView.requestFocus();
    myVideoView.start();
    VideoView myVideoView2 = (VideoView)findViewById(R.id.myvideoview2);
    myVideoView2.setVideoURI(Uri.parse(SrcPath2));

    myVideoView2.setMediaController(new MediaController(this));
    myVideoView2.requestFocus();
    myVideoView2.start();
    }

1 个答案:

答案 0 :(得分:3)

我认为你需要两个独立的线程来播放两个视频。因为IO操作正在阻塞......其中一个视频播放器可能会饿死CPU ......在两个独立的线程中调用start()......希望有所帮助!

修改 首先从onCreate()中删除start()调用。创建两个单独的线程

    Thread view1Thrad = new Thread(new Runnable(){
    @Override
    public void run(){
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
    myVideoView.start();
    });
    Thread view2Thrad = new Thread(new Runnable(){
        @Override
        public void run(){
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
        myVideoView2.start();
        });

现在逐个启动这些线程......

view1Thread.start(); //starts first video
view2Thread.start(); //starts second video

希望有所帮助!!!