Android getDuration for video gets different value on different versions

别说谁变了你拦得住时间么 提交于 2019-12-11 14:49:45

问题


I'm trying to play the following video on all devices. The problem is that with Android 4.1.2 the getDuration is 1476000 AKA 24:36 minutes. With Android 5.0.2 the getDuration returns 1546347 AKA 25:46 minutes.

So on Android 4.1.2 the real problem is that the video continues to play after "being finished". But the reality is that the video should have a getDuration like on Android 5.0.2. Does anyone here have any clue?

To see the UI problem: http://i.stack.imgur.com/tRAg5.jpg

Code below:

private void crearVideoPlayer(String videoURL) {
    // Find your VideoView in your video_main.xml layout
    videoview = (VideoView) findViewById(R.id.VideoView);

    videoControls = new MediaController(this);
    videoview.setMediaController(videoControls);
    // Start the MediaController
    videoControls.setAnchorView(videoview);

    // Get the URL from String VideoURL
    Uri video = Uri.parse(videoURL);

    videoview.setOnCompletionListener(this);
    videoview.setOnTouchListener(this);

    videoview.setVideoURI(video);

    videoview.requestFocus();
    videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        // Close the progress bar and play the video
        public void onPrepared(MediaPlayer mp) {
            pDialog.dismiss();
            videoview.start();
        }
    });

}

来源:https://stackoverflow.com/questions/32660964/android-getduration-for-video-gets-different-value-on-different-versions

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