3
votes

I am trying to implement a basic radio player that can pause the live stream, rewind it and then fast forward it again.

I think that this functionality should be natively supported from version 2.1 of the ExoPlayer.

However, the rewind and fast-forward controls are grayed out when streaming even though they work when playing local content.

Here is how I am creating the player:

private void initExoPlayer(){

    Handler mHandler = new Handler();

    String userAgent = "userAgent";

    Uri uri = Uri.parse(urlSourceOfStream);

    dataSourceFactory = new DefaultHttpDataSourceFactory(
            userAgent, null,
            DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
            1800000,
            true);

    mediaSource = new ExtractorMediaSource(uri,dataSourceFactory, Mp3Extractor.FACTORY,
            mHandler, null);

     bandwidthMeter = new DefaultBandwidthMeter();

    trackSelectionFactory =
            new AdaptiveTrackSelection.Factory(bandwidthMeter); 

    trackSelector = new DefaultTrackSelector(trackSelectionFactory);

    loadControl = new DefaultLoadControl();
    exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);

    exoPlayer.prepare(mediaSource);

    ((SimpleExoPlayerView) findViewById(R.id.exoPlayer)).setPlayer(exoPlayer);

}

The player can pause successfully, and it seems to be caching the content as I can resume the player after it has been paused for minutes. This also indicates that there should be some cache that can allow me to rewind the content.

I've also tried using the OkHttpDataSourceFactory :

OkHttpClient client = new OkHttpClient.Builder().cache(new Cache(getFilesDir() , 1000)).build();
OkHttpDataSourceFactory okHttpDataSourceFactory = new OkHttpDataSourceFactory(client, userAgent, null);

Trying to rewind the player like this makes the player play from the live stream position and does not rewind the content:

exoPlayer.seekTo(Math.max(exoPlayer.getCurrentPosition() - 1000, 0));

My question in a nutshell: How can I rewind and fast-forward an HLS with the ExoPlayer?

Thanks in advance.

1

1 Answers

0
votes

It looks like there is a bug, https://github.com/google/ExoPlayer/issues/87 discussing this, and it's been closed. But I'm not sure if its reached the v2 release, and rather it might be in the dev release, here