【发布时间】:2023-09-11 22:43:01
【问题描述】:
我一直在尝试使用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 都可以播放,但我无法为 .aac 文件的 STREAM_URL_2 获取 getDuration()。 .mp3 有效。
以下是我的做法。如何获取第二个 URL 的 getDuration()。如果getDuration() 不起作用,即使seekTo() 也不起作用。
我应该做出什么改变?我需要更改任何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);
【问题讨论】:
标签: android android-mediaplayer audio-player exoplayer android-music-player