1

I have to play three videos on 3 different Buttons in same Activity.

My first video gets played and if I play another video the last screenshot like image comes in foreground and the current video is playing behind the screenshot like image of previous video.

Please help me I have asked this question before and given this http://blog.lemberg.co.uk/surface-view-playing-video solution but this not helpful for me..

I have tried of playing this video on different Activity and after the completion of the video it comes to the previous activity. But it is not suitable for me according to my current code structure..

Sufian
  • 6,405
  • 16
  • 66
  • 120
Abhi
  • 433
  • 2
  • 7
  • 17

2 Answers2

0

You can use one video view in the activity and switch content to play while buttons are clicking. Before starting video playback,just check whether video is playing or not For videoview you can check those by

videoView.isPlaying()

If it is playing then stop and start with new video content which is loaded from raw. So the idea is while clicking a button, check videoview is playing then stop and start, else just start.

Create a function like this

playVideo(String path)
{
    Uri uri = Uri.parse(uriPath);
    mVideoView.setVideoURI(uri);
    mVideoView.requestFocus();
    if(mVideoView.isPlaying())
     {
       mVideoView.stopPlayback();
     }
    mVideoView.start();
}

call this function in three button clicks with the three different paths.

Jiju Induchoodan
  • 4,236
  • 1
  • 22
  • 24
  • Dear Jiju Induchoodan can you please elaborate or give me a snippet. Actually I am playing another video after the completion of first video. – Abhi Jun 23 '14 at 08:31
  • Please provide the existing code base so that i can check and fix – Jiju Induchoodan Jun 23 '14 at 09:05
  • http://androidexample.com/Play_Video_File_-_Android_Example/index.php?view=article_discription&aid=124&aaid=144 I have gone through this tutorial here is only one button and one video I have 3 buttons ans three videos that's the difference – Abhi Jun 23 '14 at 09:11
  • giving null pointer exception in mVideoView.setVideoURI(uri); and in PlayVideo(uriPathfood); My uriPathfood is final String uriPathfood = "android.resource://" + getPackageName() + "/" + R.raw.food_animation; – Abhi Jun 23 '14 at 09:38
  • make sure the path is correct and the uri is not null – Jiju Induchoodan Jun 23 '14 at 09:39
0
vidRiver = (VideoView) findViewById(R.id.videoView1);


vidRiver.setMediaController(new MediaController(this));


vidRiver.setVideoPath("/mnt/sdcard/APK/river.mp4");

or

vidRiver.setVideoURI(Uri.parse("android.resource://" + getPackageName()
            + "/" + R.raw.river));
    vidRiver.requestFocus();
    vidRiver.start();
    setContentView(vidRiver);

    vidRiver.setOnCompletionListener(new OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
            // TODO Auto-generated method stub
       }
}
Roadies
  • 3,309
  • 2
  • 30
  • 46