gpt4 book ai didi

android - MediaPlayer 在 Android 上生成 'can' t 播放此视频错误

转载 作者:行者123 更新时间:2023-11-29 02:31:07 25 4
gpt4 key购买 nike

我有一个表单,除了播放从服务器下载的视频外什么都不做。它工作正常,除了在视频播放完毕后按下后退按钮(从工具栏或设备后退按钮)时,在上一个表单已经弹出后弹出带有消息“无法播放此视频”的原生 Android 对话框显示。如果我在播放视频时退出表单,我不会收到任何错误。我真的很想摆脱这条消息。
这是我的代码:

以前的形式

final Button playVideo = new Button(res.getImage("play-video2.png"));
playVideo.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent evt) {
try {
new VideoPlayerForm(getComponentForm(), (String) fileInfo.get("path")).show();
} catch (IOException ex) {
ex.printStackTrace();
}
}
});

VideoPlayerForm

public VideoPlayerForm(Form instance, String videoUrl) throws IOException {
super(instance);
setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_SCALE));
setTitle(MyApplication.getInstance().getString("video"));
String filepath = FileSystemStorage.getInstance().getAppHomePath() + MyApplication.DIRECTORY_APP_DOWNLOADS + "/" + videoUrl;
try{
if(!FileSystemStorage.getInstance().exists(filepath)){
Log.p("Downloading " + videoUrl + " to local storage");
success = Cn1FileUtils.downloadRemoteFile("https://medonline.co.il/uploads/" + videoUrl, videoUrl, true);
if(!success){
UniversalToast.show(MyApplication.getInstance().getString("error_video_download_failed"), UniversalToast.LENGTH_SHORT);
return;
}
}
final InputStream is = FileSystemStorage.getInstance().openInputStream(filepath);
video = MediaManager.createMedia(is, "video/mp4");
}catch(Exception e){
new DownloadedFileBrowserForm(this).show();
return;
}

add(BorderLayout.CENTER, new MediaPlayer(video));
}

@Override
protected void onShowCompleted() {
super.onShowCompleted();
if(!success){
previousInstance.showBack();
}
else{
video.setFullScreen(true);
video.play();
}
}
}

Android 堆栈跟踪

03-29 14:03:25.563 11427 11427 W VideoView: Unable to open content: file:///data/user/0/il.co.medonline.doctorapp/cache/mtmp-257887399
03-29 14:03:25.563 11427 11427 W VideoView: java.io.IOException: setDataSource failed.
03-29 14:03:25.563 11427 11427 W VideoView: at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1095)
03-29 14:03:25.563 11427 11427 W VideoView: at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1041)
03-29 14:03:25.563 11427 11427 W VideoView: at android.media.MediaPlayer.setDataSource(MediaPlayer.java:987)
03-29 14:03:25.563 11427 11427 W VideoView: at android.widget.VideoView.openVideo(VideoView.java:346)
03-29 14:03:25.563 11427 11427 W VideoView: at android.widget.VideoView.access$2100(VideoView.java:70)
03-29 14:03:25.563 11427 11427 W VideoView: at android.widget.VideoView$7.surfaceCreated(VideoView.java:622)
03-29 14:03:25.563 11427 11427 W VideoView: at android.view.SurfaceView.updateWindow(SurfaceView.java:597)
03-29 14:03:25.563 11427 11427 W VideoView: at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:179)
03-29 14:03:25.563 11427 11427 W VideoView: at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
03-29 14:03:25.563 11427 11427 W VideoView: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2055)
03-29 14:03:25.563 11427 11427 W VideoView: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
03-29 14:03:25.563 11427 11427 W VideoView: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)

最佳答案

我认为全屏查看器错误地返回到您的父表单而不是实际返回表单(因为全屏模式)并且由于 onShowComplete 方法运行两次而再次触发启动代码.

当视频结束时,您可以使用以下语法获取事件:

video = MediaManager.createMedia(is, "video/mp4", () -> {
video = null;
parentForm.show();
});

关于android - MediaPlayer 在 Android 上生成 'can' t 播放此视频错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49554807/

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