how can i play two video on one screen?

我们两清 提交于 2019-12-09 07:58:49

问题


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

回答1:


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!!!

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

Hope that helps!!!



来源:https://stackoverflow.com/questions/10023605/how-can-i-play-two-video-on-one-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!