gpt4 book ai didi

android - VideoView 抛出 IllegalStateException

转载 作者:行者123 更新时间:2023-11-29 01:40:15 27 4
gpt4 key购买 nike

我的应用程序中有一个视频 View ,可以播放我的扩展文件中的视频。这是代码:

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)
...

我不知道为什么会这样。谁能帮忙?

我的布局只是一个视频 View 。

最佳答案

试试这个

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) {
}

关于android - VideoView 抛出 IllegalStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25162740/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com