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

查看:460
本文介绍了无法使用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 ="

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天全站免登陆