Android的MediaPlayer的:getDuration()后的prepare返回0() [英] Android MediaPlayer: getDuration() returns 0 after prepare()

查看:3944
本文介绍了Android的MediaPlayer的:getDuration()后的prepare返回0()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用蜂窝MediaPlayer的,不能得到任何HLS在prepared的持续时间(HTTP实时流媒体),视频()的函数。

I'm using MediaPlayer on Honeycomb and cannot get the duration of any HLS (http live streaming) video in the function onPrepared().

如果 getDuration() prepare被称为(),则返回0:

public void onPrepared(MediaPlayer mp) {
    // getduration returns 0
    mediaPlayer.start();
    Log.d(TAG, "duration: " + mediaPlayer.getDuration());
}

不过,视频开始播放。

However, the videos starts playing.

如果 getDuration()被称为 onVideoSizeChanged()返回正确的值,

If getDuration() is called in onVideoSizeChanged() it returns the correct value,

public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    // returns the correct value
    Log.d(TAG, "duration: " + mediaPlayer.getDuration());
}

为什么 getDuration() onVideoSizeChanged(),但不是在工作于prepared()

修改:起初我以为getDuration()不会在所有的工作,却发现它在onVideoSizeChanged返回正确的值()。修改问题,以反映这一点。

Edit: At first I thought getDuration() doesn't work at all, but found it to return the correct value in onVideoSizeChanged(). Modified question to reflect this.

推荐答案

有没有什么可以做这件事。流的细节将不知道直到该流被读取。根据不同的格式,有可能是流,暗示或没有前部附近正确的信息。

There isn't anything you can do about this. The stream details won't be known until the stream is being read. Depending on the format there may be correct information near the front of the stream, a hint or nothing.

由于视频尺寸变化监听器总是被调用,你必须调整你的code,以获得时间,然后(如果可用)。

Since the video size change listener is always called you'll have to restructure your code to get the duration then (if it is available).

(即使这是一个bug,即使它是固定的,这样的修正将不会被部署到数以百万计的现有设备,使你被卡住当前的行为的。)

(Even if this is a bug and even if it is fixed, such a fix would not be deployed to millions of existing devices so you are stuck with current behaviour.)

这篇关于Android的MediaPlayer的:getDuration()后的prepare返回0()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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