ExoPlayer 流 mp3

ExoPlayer stream mp3

我想在我的应用程序中重现 URL,但是当使用 exoplayer 库时,它给出了一个错误,而如果我使用标准媒体播放器,一切都会很好,mp3 可以播放。请帮助我找到我的错误并提供有用的信息。谢谢

这里是一个示例 URL 地址,它被重定向但是 exoplayer 必须使用它:https://m.z1.fm/xxx-load/22346945?play=on

这是我的代码

DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(context, null,
            DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF);
exoPlayer = ExoPlayerFactory.newSimpleInstance(context, renderersFactory, new DefaultTrackSelector());
DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(
                URLs.getUserAgentMobile(), new DefaultBandwidthMeter(),
                DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
                DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true);
ExtractorMediaSource mediaSource mediaSource = 
                new ExtractorMediaSource.Factory(httpDataSourceFactory).createMediaSource(Uri.parse(urlTrack));
exoPlayer.prepare(mediaSource);
exoPlayer.setPlayWhenReady(true);

修改您的代码并添加 DefaultDataSourceFactory

DefaultExtractorsFactory extractorFactory = new DefaultExtractorsFactory();

DefaultBandwidthMeter BANDWIDTH_METER = new DefaultBandwidthMeter();

DataSource.Factory mediaDataSourceFactory =  new DefaultDataSourceFactory(this, (TransferListener<? super DataSource>) BANDWIDTH_METER, httpDataSourceFactory);

ExtractorMediaSource mediaSource mediaSource =  new ExtractorMediaSource.Factory(mediaDataSourceFactory).
setExtractorsFactory(extractorFactory).
createMediaSource(uri);