Android开发:如何播放assets下的mp4文件

1.

public class CustomVideoView extends VideoView {
    public CustomVideoView(Context context){
        super(context);
    }
    public CustomVideoView(Context context, AttributeSet attributeSet){
        super(context,attributeSet);
    }
    public CustomVideoView(Context context,AttributeSet attributeSet,int defStyle){
        super(context,attributeSet,defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int width=getDefaultSize(0,widthMeasureSpec);
        int height=getDefaultSize(0,heightMeasureSpec);
        setMeasuredDimension(width,height);
    }

2.

3.

Android开发:如何播放assets下的mp4文件_第1张图片

 4.

String file_path=mActivity.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).toString()+"/video";
//使用VideoView播放视频
VideoView videoView = mBind.videoView;
String path=file_path+"/dota_montage_02.mp4";
Log.d("播放地址",path);
videoView.setVideoPath(path);
//创建MediaController对象
MediaController mediaController = new MediaController(mActivity);
//绑定mediaController
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.start();
mBind.videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
    @Override
    public void onCompletion(MediaPlayer mp) {
        mBind.videoView.start();
    }
});

ending~

你可能感兴趣的:(android,java)