android – 无法使用ExoPlayer获取AAC文件的getDuration()
作者:互联网
我一直在尝试使用ExoPlayer流式传输URL.网址:
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”
两个URL都播放但我无法获取STREAM_URL_2的getDuration(),这是一个.aac文件. .mp3有效.
以下是我的工作方式.如何获取第二个URL的getDuration().如果getDuration()不起作用,即使seekTo()也不起作用.
我应该做些什么改变?我需要更换任何提取器吗?
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文件的格式化方式使得可以计算文件的持续时间,并搜索其中的任何位置.
但是,AAC文件没有那么奢侈.你不能计算持续时间,也不能在其中寻求.
Exoplayer Demo APK中有一个AAC文件.我想如果你玩它,它会表现出同样的行为.
标签:audio-player,android,exoplayer,android-mediaplayer,android-music-player 来源: https://codeday.me/bug/20190926/1820684.html