Search code examples
javaandroidexoplayerogg

error playing stream on android 9 and 10 with exoplayer


String prp = "http://stream.dedyn.io:8000/dsbmradio.opus";

it works until android 8, but it doesn't work on 9 or 10. follow the code I'm using

BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
Uri videoURI = Uri.parse(prp);
DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory("exoplayer_video");
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
MediaSource mediaSource = new ExtractorMediaSource(videoURI, dataSourceFactory, extractorsFactory, null, null);

exoPlayerView.setPlayer(exoPlayer);
exoPlayer.prepare(mediaSource);
exoPlayer.setPlayWhenReady(true);

this is the error generated

E/ExoPlayerImplInternal: Source error.
com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to http://rfmbrasil.servemp3.com:8000/uespi.ogg

Solution

  • Since you are using "http" url you are not able to play video in android 9 and above.

    Starting with Android 9 (API level 28), cleartext support is disabled by default.

    Have a look at below answer for more info

    https://stackoverflow.com/a/50834600/7398620