Failed to get getDuration () for AAC file using ExoPlayer

I am trying to convey URLusing ExoPlayer. Urls:

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 "

Both urls are reproducing, but I cannot get getDuration()for STREAM_URL_2, which is a .aac file. Works .mp3.

The next is how I do it. How to get getDuration()for the second URL. It seekTo()doesn’t even work if it getDuration()doesn’t work.

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);
0
source share
1 answer

There is nothing wrong with the code. MP3 files are formatted so that you can calculate the duration of the file and look for any position in it.

However, AAC files do not have that luxury. You cannot calculate the duration and cannot search in it.

There is an AAC file in the Exocayer Demo APK. I think that if you play this, he will have the same behavior.

+2
source

Source: https://habr.com/ru/post/1613323/


All Articles