Playing multiple videos at a time

586 Views Asked by At

I am using following code to run multiple videos at a time. UPDATED CODE

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    video1=(VideoView)findViewById(R.id.myvideoview);
    video1.setVideoURI(Uri.parse("android.resource://" +getPackageName()+ "/"+R.raw.sample));
    video1.setMediaController(new MediaController(this));
    video1.requestFocus();

    video2=(VideoView)findViewById(R.id.myvideview);
    video2.setVideoURI(Uri.parse("android.resource://" +getPackageName()+ "/"+R.raw.sample1));
    video2.setMediaController(new MediaController(this));
    video2.requestFocus();

    Thread view1=new Thread(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_DISPLAY);
            video1.start();
        }
    });

    Thread view2=new Thread(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_DISPLAY);
            video2.start();
        }
    });

    view1.start();
    view2.start();
}

And it is giving me error and

mediaPlayer error (1, -110) 

And suddenly dialog box appears and shows that can not play this video

Any suggesion??

2

There are 2 best solutions below

5
Shashika On

You can't do UI related operations on background threads. Android does all UI operations on the main thread. That's why the error message says "Only the original thread that created a view hierarchy can touch its views."

0
Rohit On

I got the solutions....

Above code posted by me works but it is depend upon h/w accelerator. If it supports multi-video view at a time then it will work fine else it will give you error This media can not be played