exoplayer流mp3

6yoyoihd  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(442)

我想在我的应用程序中复制url,但是当使用exoplayer库时,它会给出一个错误,而如果我使用标准的mediaplayer,一切都会很好,mp3也会播放。请帮我找出错误并提供有用的信息。谢谢。
下面是一个示例url地址,它被重定向,但exoplayer必须使用它:https://m.z1.fm/-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);
ggazkfy8

ggazkfy81#

修改代码并添加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);

相关问题