Codenameone MediaPlayer generates 'can't play this video' error on Android how do i intercept the dialog so it fails silently

做~自己de王妃 提交于 2021-02-07 10:44:10

问题


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

回答1:


I would separate this into two processes:

  • Download
  • Play

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.*;

Then for playback/download:

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

}


来源:https://stackoverflow.com/questions/51592056/codenameone-mediaplayer-generates-cant-play-this-video-error-on-android-how-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!