Codenameone MediaPlayer在Android上生成“无法播放此视频"错误,我该如何截取对话框,使其静默失败 [英] Codenameone MediaPlayer generates 'can't play this video' error on Android how do i intercept the dialog so it fails silently

查看:48
本文介绍了Codenameone MediaPlayer在Android上生成“无法播放此视频"错误,我该如何截取对话框,使其静默失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的codenameone项目有一个mediaPlayer,可在下载视频后播放视频,在某些情况下,即使网络损坏,即使网络中断,该视频仍会保存在设备上,而当播放器尝试播放此视频时,我会收到无法播放此视频"对话框.我该如何拦截它,使其不显示对话框,并且我可以在后台处理错误,因此媒体播放器的代码如下

My codenameone project has a mediaPlayer which plays videos once they are downloaded, in some instances when the network breaks the video is still saved on the device even though it is corrupt and when the player tries to play this video i get the 'can't play this video' dialog. How can i intercept this so it doesnt show the dialog and i can handle the error in the background, my code for the media player is below

video = MediaManager.createMedia(videostream, "video/mp4", new Runnable() {
                                                @Override
                                                public void run() {

                                                    videoIsPlaying = false;
                                                    videoCounter++;

                                                }
                                            });



                                            video.setNativePlayerMode(true);

                                            newmp = new MediaPlayer(video);

                                            newmp.setAutoplay(true);
                                            newmp.hideControls();

                                            newmp.setHideNativeVideoControls(true);

推荐答案

我将其分为两个过程:

  • 下载
  • 播放

您可以将视频本地下载到文件系统,然后播放该文件.通过分离,您还可以在下载过程中创建令人愉悦的进度动画,甚至提供下载进度的指示.

You can download the video locally to file system, the play that file. By separating you can also create a pleasing progress animation during the download process and even provide indication of the download pace.

简单的下载/播放过程如下所示:

A simplistic download/play process would look something like this:

import static com.codename1.ui.CN.*;

然后播放/下载:

String f = getAppHomePath() + "videoName.mp4";
if(Util.downloadUrlToFile(url, f, true)) {
    video = MediaManager.createMedia(f, () -> {
          videoIsPlaying = false;
          videoCounter++;
      });

}

这篇关于Codenameone MediaPlayer在Android上生成“无法播放此视频"错误,我该如何截取对话框,使其静默失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆