Android VideoView prevent on video change

I am using a VideoView to play Mp4 video. There are buttons in the screen and on the click event I need to change the video of the VideoView and play. I want this transition to be as smooth as possible. This is the code I was using in the button onclick handler.

Uri uri = Uri.parse("android.resource://"+getPackageName() + "/"+R.raw.myvideo);
mainVideoView.setVideoURI(uri);
mainVideoView.requestFocus();
mainVideoView.start();

I was testing this on my phone with Andorid 4, everything worked fine. But when I tested it in a phone with Android 2.2, I was shocked to see on click of the button the videoview part of the screen becomes black for a second and the new video starts. I cant afford that delay in my application.


Try this code

This is a java code

package com.android.video;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class VideoActivity extends Activity {
/** Called when the activity is first created. */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.main);
        VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
        MediaController mc = new MediaController(this);
        videoView.setMediaController(mc);
   //videoView.setVideoURI(Uri.parse("http://www.mediafire.com/?trc33d4yma3rkv3.mp4"));
     videoView.setVideoPath("/sdcard/movie.mp4");
        videoView.requestFocus();
        videoView.start();
    }
}

This is main.xml

 <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
 <VideoView android:id="@+id/videoView" android:layout_width="300dp" android:layout_height="300dp" /> 
 </LinearLayout>

This is manifest file

 <uses-permission android:name="android.permission.INTERNET" />
链接地址: http://www.djcxy.com/p/46494.html

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

下一篇: Android VideoView可防止视频更改