Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffering radio stream #3164

Closed
psedoykin opened this issue Aug 11, 2017 · 12 comments
Closed

Buffering radio stream #3164

psedoykin opened this issue Aug 11, 2017 · 12 comments

Comments

@psedoykin
Copy link

Issue description

I use exoplayer for playing radio stream. And I have question related to buffering:
How to increase it?

I found the following issue (#2438) but increase DEFAULT_MIN_BUFFER_MS and DEFAULT_MAX_BUFFER_MS doesn't help me.

Now I have about 20-30 sec buffering when Internet off. I want to increase it to 3 min.
It is not server issue because Ios client support buffering about 3 min for the same server.

Could you help me ? may be need change another settings ?

Please see my code:

LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE), 2DEFAULT_MIN_BUFFER_MS,
2
DEFAULT_MAX_BUFFER_MS, DEFAULT_BUFFER_FOR_PLAYBACK_MS, DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS);

        DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(mContext);

        TrackSelection.Factory videoTrackSelectionFactory =
                new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
        TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

        mPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory,
                trackSelector,
                loadControl);

        mPlayer.setAudioStreamType(C.STREAM_TYPE_MUSIC);
        mPlayer.addListener(this);

        setWakeMode(mContext, PowerManager.PARTIAL_WAKE_LOCK);

Version of ExoPlayer being used

r2.5.1

Device(s) and version(s) of Android being used

Galaxy note 5 - Android 6.0.1

@ojw28
Copy link
Contributor

ojw28 commented Aug 14, 2017

We need more complete information to help with issues like this. For example information about the type of stream you're trying to play (and preferable a link to an example).

@psedoykin
Copy link
Author

Mp3 stream from Internet (for example http://79.174.68.63:7999/luxury).
I have added file with code related to exoplayer from my project.
LocalPlayback.java.zip

Please look at function createMediaPlayerIfNeeded. (But it default init for exoplayer)

@ojw28
Copy link
Contributor

ojw28 commented Aug 16, 2017

If you have a three minute buffer, does that imply three minutes of latency (e.g. the audio the user hears is three minutes behind "live")?

@djerom
Copy link

djerom commented Aug 16, 2017

I don't see the point to increase so much your buffer size.
Anyway you can customize buffer settings as below:

private static final int DEFAULT_MIN_BUFFER_MS = 5000;
private static final int DEFAULT_MAX_BUFFER_MS = 10000;
private static final int DEFAULT_BUFFER_FOR_PLAYBACK_MS = 3500;

private void createMediaPlayerIfNeeded() {
    if (mExoPlayer == null) {
        mExoPlayer = ExoPlayerFactory.newSimpleInstance(
                new DefaultRenderersFactory(mContext),
                new DefaultTrackSelector(),
                new DefaultLoadControl(new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE),
                            DEFAULT_MIN_BUFFER_MS, DEFAULT_MAX_BUFFER_MS, DEFAULT_BUFFER_FOR_PLAYBACK_MS,                      DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS));
        AudioAttributes.Builder builder = new AudioAttributes.Builder()
                .setContentType(C.CONTENT_TYPE_MUSIC);
        mExoPlayer.setAudioAttributes(builder.build());
        mExoPlayer.setPlayWhenReady(true);
        mExoPlayer.addListener(this);
    }
}

@psedoykin
Copy link
Author

@ojw28 I want to implement the following behavior:
If the Internet should turn off on the phone, then the app should play 3 more minutes.

@psedoykin
Copy link
Author

@djerom I have customized the settings but it didn't help me.

@ojw28
Copy link
Contributor

ojw28 commented Aug 17, 2017

As already asked above, does that imply three minutes of latency (e.g. the audio the user hears is three minutes behind "live")?

@psedoykin
Copy link
Author

No, I want to play "live" and buffering some next time of stream. Is it possible ?

@ojw28
Copy link
Contributor

ojw28 commented Aug 20, 2017

It's fundamentally impossible to be both "live" and have three minutes of media buffered, since that would require you to have buffered three minutes of content from the future. Please clarify the question. Thanks.

@psedoykin
Copy link
Author

So for what DEFAULT_MIN_BUFFER_MS, DEFAULT_MAX_BUFFER_MS used in DefaultLoadControl ? I think that for buffering media.

@ojw28
Copy link
Contributor

ojw28 commented Aug 22, 2017

They're used as documented. Note that the "will attempt" part of the documentation is important. If the serving side doesn't allow the client to buffer that much media, then the client wont be able to do so.

I took a look at the stream mentioned earlier in this thread (http://79.174.68.63:7999/luxury). The server allows the client to buffer ~145 seconds of media. Increasing DEFAULT_MIN_BUFFER_MS and DEFAULT_MAX_BUFFER_MS to this duration or more will cause ~145 seconds of media to be buffered, and this is working correctly. You can verify this by periodically querying the difference between player.getBufferedPosition and player.getCurrentPosition during playback.

I think the problem you're seeing isn't that the duration of media you want isn't being buffered. It's that the player attempts to reconnect too quickly in the case of a network error, rather than first playing out all of the media that's in the buffer. This issue is tracked by #1606, so you should follow that for updates.

@psedoykin
Copy link
Author

Ok, Thanks for your help.

@google google locked and limited conversation to collaborators Dec 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants