Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExoPlayer not working for some streams

I have this type of stream: http://radiohoryzont.jgora.pl:8050. The problem is, that when I try to play it using ExoPlayer, following exception is thrown.

E/ExoPlayerImplInternal: Internal track renderer error. com.google.android.exoplayer.ExoPlaybackException: com.google.android.exoplayer.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to http://radiohoryzont.jgora.pl:8050

Strange thing is, that on another mobile phone it seems to be working (it is working on Android 6, but not on Android 4). Could somebody help me with this?

I am using EMAudioPlayer.

 mediaPlayer = new EMAudioPlayer(getApplicationContext());
 mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
 mediaPlayer.setDataSource(getApplicationContext(), myURI);

Thanks in advance for your help.

like image 854
Tom11 Avatar asked Nov 06 '16 19:11

Tom11


1 Answers

I've been solving the very same issue recently and found the solution.

The URL which fails for you is a ShoutCast and these are not working well with HttpDataSource on Android 4. However if you manage to replace this with OkHttpDataSource, data will be retrieved correctly.

You are using EMAudioPlayer, which uses ExoPlayer to stream music (for API level 16+). You can easily replace HttpDataSource with OkHttpDataSource:


    TrackSelector trackSelector = new DefaultTrackSelector(
        new Handler(),
        new AdaptiveVideoTrackSelection.Factory(
            new DefaultBandwidthMeter()
        )
    );
    mediaPlayer = ExoPlayerFactory.newSimpleInstance(
        getApplicationContext(),
        trackSelector,
        new DefaultLoadControl()
    );
    MediaSource source = new ExtractorMediaSource(
        myURI,
        new OkHttpDataSourceFactory(
            new OkHttpClient(),
            userAgent,
            null
        ),
        new DefaultExtractorsFactory(),
        null,
        null
    );
    mediaPlayer.prepare(source);
    mediaPlayer.setPlayWhenReady(true);

like image 94
Marek Potkan Avatar answered Nov 09 '22 17:11

Marek Potkan