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??
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."