如何在一个屏幕上播放两个视频? [英] how can i play two video on one screen?

查看:121
本文介绍了如何在一个屏幕上播放两个视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须创建一个需要在屏幕上同时播放两个视频的应用程序.这是我的代码.但是视频无法播放.我在任何地方做错了吗?:(

i have to make an application where i need to play two video simultaniously,on screen. here is my code.but the video dose not play.am i doing wrong anywhere? :(

    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();
    }

推荐答案

我认为您需要两个单独的线程才能播放两个视频.由于IO操作受阻...视频播放器之一可能会饿死CPU ...在两个单独的线程中调用start()....希望能帮到您!

I think you require two separate threads for playing two videos. since IO operations are blocking... One of the video Player may starve for CPU... Call start() in two separate threads.... Hope that helps!!!

编辑首先从onCreate()中删除start()调用.创建两个单独的线程

EDIT first remove the start() calls from onCreate().. Create two separate threads

    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();
        });

现在一个一个地启动这些线程...

now start these threads one by one...

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

希望有帮助!!!

这篇关于如何在一个屏幕上播放两个视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆