无法使用 ExoPlayer 获取 AAC 文件的 getDuration() [英] Not able to get getDuration() for AAC file using ExoPlayer

查看:33
本文介绍了无法使用 ExoPlayer 获取 AAC 文件的 getDuration()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 ExoPlayer 流式传输 URL.网址:

I have been trying to stream a URL using ExoPlayer. The URLs:

STREAM_URL_1 = "http://storage.googleapis.com/exoplayer-test-media-0/play.mp3"

STREAM_URL_1 = "http://storage.googleapis.com/exoplayer-test-media-0/play.mp3"

STREAM_URL_2 = "https://s3-ap-southeast-1.amazonaws.com/ok.talk.channels/zakirkhan/Zakir+khan+-+when+my+father+took+my+gf%27s+call.aac"

STREAM_URL_2 = "https://s3-ap-southeast-1.amazonaws.com/ok.talk.channels/zakirkhan/Zakir+khan+-+when+my+father+took+my+gf%27s+call.aac"

两个 URL 都可以播放,但我无法获得 STREAM_URL_2 的 getDuration(),它是一个 .aac 文件..mp3 有效.

Both URLs play but I am not able to get the getDuration() for STREAM_URL_2 which is an .aac file. The .mp3 works.

以下是我的做法.如何获取第二个 URL 的 getDuration().如果 getDuration() 不起作用,即使 seekTo() 也不起作用.

The following is how I do it. How do I get the getDuration() for the 2nd URL. Even seekTo() doesn't work if getDuration() doesn't work.

我应该做出什么改变?我需要更改任何 Extractor 吗?

What change should I make? Do I need to change any Extractor?

player = ExoPlayer.Factory.newInstance(RENDERER_COUNT, MIN_BUFFER_MS, MIN_RE_BUFFER_MS);
playerControl = new PlayerControl(player);
Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);

private static final String STREAM_URL = "http://storage.googleapis.com/exoplayer-test-media-0/play.mp3";
uri = Uri.parse(STREAM_URL);

// Build the video and audio renderers.
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(player.getMainHandler(),
    null);
String userAgent = Util.getUserAgent(this, "MyMediaPlayer");
DataSource dataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent, true);
ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri, dataSource, allocator,
    BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE);

MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,
    null, true);

// Invoke the callback.
TrackRenderer[] renderers = new TrackRenderer[1];
renderers[RadioPlayer.TYPE_AUDIO] = audioRenderer;
player.prepare(renderers);
player.seekTo(0);
player.setPlayWhenReady(true);

推荐答案

您的代码没有任何问题.MP3 文件的格式可以计算文件的持续时间,并在其中查找任何位置.

There's nothing wrong in your code. MP3 files are formatted in such a way that it's possible to calculate the duration of the file, and seek into any position within it.

然而,AAC 文件没有那么奢侈.你无法计算持续时间,也无法在其中寻找.

However, AAC files do not have that luxury. You can't calulate the duration and can't seek within it.

Exoplayer Demo APK 中有一个 AAC 文件.我想如果你玩那个,它会表现出同样的行为.

There is a AAC file in Exoplayer Demo APK. I think if you play that, it will exhibit the same behavour.

这篇关于无法使用 ExoPlayer 获取 AAC 文件的 getDuration()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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