我的应用中有一个视频视图,可以播放我的扩展文件中的视频。这是代码:
private VideoView _vv;
private static final Uri CONTENT_URI = Uri.parse("content://--PACKAGENAMEHIDDENFORSECURITY--.EHZipUriProvider");
private static final String VIDEO_NAME = "b1.mp4";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
_vv = (VideoView) findViewById(R.id.vv);
startVideoPlayback();
}
private void startVideoPlayback()
{
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(_vv);
_vv.setMediaController(mediaController);
_vv.setVideoURI(Uri.parse(CONTENT_URI + "/" + VIDEO_NAME));
_vv.start();
}
堆栈跟踪:
java.lang.IllegalStateException
at android.media.MediaPlayer.prepareAsync(Native Method)
at android.widget.VideoView.openVideo(VideoView.java:335)
at android.widget.VideoView.access$2100(VideoView.java:71)
at android.widget.VideoView$7.surfaceCreated(VideoView.java:607)
at android.view.SurfaceView.updateWindow(SurfaceView.java:572)
at android.view.SurfaceView.access$000(SurfaceView.java:86)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:175)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1897)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1019)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5725)
...
我不知道为什么会这样做。有人可以帮忙吗?
我的布局只是一个视频观看。
答案 0 :(得分:1)
试试这个
try {
mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse(url);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
return false;
}
});
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
videoView.start();
}
});
videoView.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
}
});
} catch (Exception e) {
}