1

I want to reproduce the URL in my application, but when using the exoplayer library, it gives an error, while if I use the standard mediaplayer, everything will be fine and the mp3 will play. Please help me find my mistake and give useful information. Thank.

Here is an example URL address, it is redirected but it is necessary that exoplayer works with it: https://m.z1.fm/xxx-load/22346945?play=on

This is my code

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);

1 Answers1

2

Modify your code and add 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);
Asuk Nath
  • 570
  • 4
  • 10
  • Thank you, but why does it swear at this code snippet: (TransferListener super DataSource>) Writes: does not have type parameters – Dima Chibuk Dec 09 '18 at 17:48
  • Passed DefaultBandwidthMeter. Did you try this code? I'm using this code for playing Video and Audio with 301 Cross Domain Redirected streaming URLs. https://stackoverflow.com/questions/41517440/exoplayer2-how-can-i-make-a-http-301-redirect-work FYI, your URL is now returning 404. – Asuk Nath Dec 10 '18 at 04:20
  • I have tried many methods, but for some reason everything is unsuccessful, although mediaPlayer has no problems with this .. strange ... But I decided this way in another way: Connection.Response response = Jsoup.connect(urlTrack).followRedirects(false).execute(); String finalUrl= response.header("location"); – Dima Chibuk Dec 10 '18 at 13:12