blank video after path change on some devices

I'm quite new to android development and I am currently developing a very simple application that includes also some videos. To demonstrate my problem I have 2 videos (eg video1.mp4 and video2.mp4) in my res/raw/ directory. I want to start playing the second video as soon as the first ends. This is how I call videos:

public void showVideo1() {
    VideoView vd = (VideoView)findViewById(R.id.videoview);
    vd.setVideoPath("android.resource://com.myapp.hello/" + R.raw.video1);
    vd.setOnCompletionListener(new MediaPlayer.OnCompletionListener() 
    {           
        public void onCompletion(MediaPlayer mp) 
        {
            Log.d("VideoComplete", "Video 1 is complete");
            showVideo2(); // start playing the second video...
        }           
    }); 
    vd.start();
}


public void showVideo2() {
    VideoView vd = (VideoView)findViewById(R.id.videoview);
    vd.setVideoPath("android.resource://com.myapp.hello/" + R.raw.video2);
    vd.setOnCompletionListener(new MediaPlayer.OnCompletionListener() 
    {           
        public void onCompletion(MediaPlayer mp) 
        {
            Log.d("VideoComplete", "Video 2 is complete");
        }           
    }); 
    vd.start();
}

This example works on most devices - I call showVideo1() that calls showVideo2, both videos are played and that's it. But I found out that some devices won't play the second video (???). For example my old Samsung Galaxy 5 i5500 just displays a blank screen after it finishes the first video - I can see in debug that second video was loaded and started but it does not display - the first video plays without a problem. This phone uses Android v2.2 and I also tried on another device using the same OS version (Galaxy Tab GT-P1000) and both videos are played there.

I tried recoding videos (thought it was a codec error) but still no luck. I also played around with setZOrderOnTop(true), seekTo(0), ... and it's driving me crazy.

Any suggestion? My future app depends on this functionality (being able to playback one video after another) on all devices so I'm really desperate about this.


You can create a Handler in your onCompleteListener of Video1 and check after some time whether your video is being played or not. You can further try stopping the Video2 and playing it again in the runnable and try different things just to know if it is absolutely impossible for other devices to support your logic. Keep track of events happening from LogCat. Good Luck

链接地址: http://www.djcxy.com/p/46496.html

上一篇: 在Android中,Activity没有看到方向改变?

下一篇: 在某些设备上更改路径后出现空白视频