Android Question Is there a way to adjust certain ExoPlayer buffer values

JohnC

Expert
Licensed User
Longtime User
On this page:


There are various default buffer values for ExoPlayer:

B4X:
bufferForPlaybackMs    2500
minBufferMs    15000
maxBufferMs    50000
bufferForPlaybackAfterRebufferMs    5000

Is there a way using JavaObject/Reflection to change these values?

Basically, when I start Exoplayer, the stream doesn't start playing until it reaches that 2500ms default value (bufferForPlaybackMs), but I would like to set this to 1000ms so the stream will start quicker.
 
Last edited:
Solution
B4X:
Sub CreateNativePlayer As Object
    Dim np As JavaObject
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim renderer, trackSelecter As JavaObject
    renderer.InitializeNewInstance("com.google.android.exoplayer2.DefaultRenderersFactory", Array(ctxt))
    trackSelecter.InitializeNewInstance("com.google.android.exoplayer2.trackselection.DefaultTrackSelector", Array(ctxt))
    Dim LoadControlBuilder As JavaObject
    LoadControlBuilder.InitializeNewInstance("com.google.android.exoplayer2.DefaultLoadControl.Builder", Null)
    Dim bufferForPlaybackMs = 2500, minBufferMs = 15000, maxBufferMs = 50000, bufferForPlaybackAfterRebufferMs = 5000 As Int
    
    LoadControlBuilder.RunMethod("setBufferDurationsMs", Array(minBufferMs...

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub CreateNativePlayer As Object
    Dim np As JavaObject
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim renderer, trackSelecter As JavaObject
    renderer.InitializeNewInstance("com.google.android.exoplayer2.DefaultRenderersFactory", Array(ctxt))
    trackSelecter.InitializeNewInstance("com.google.android.exoplayer2.trackselection.DefaultTrackSelector", Array(ctxt))
    Dim LoadControlBuilder As JavaObject
    LoadControlBuilder.InitializeNewInstance("com.google.android.exoplayer2.DefaultLoadControl.Builder", Null)
    Dim bufferForPlaybackMs = 2500, minBufferMs = 15000, maxBufferMs = 50000, bufferForPlaybackAfterRebufferMs = 5000 As Int
    
    LoadControlBuilder.RunMethod("setBufferDurationsMs", Array(minBufferMs, maxBufferMs, bufferForPlaybackMs, bufferForPlaybackAfterRebufferMs))
    np = np.InitializeStatic("com.google.android.exoplayer2.ExoPlayerFactory").RunMethod("newSimpleInstance", _
        Array(ctxt, renderer,trackSelecter, LoadControlBuilder.RunMethod("createDefaultLoadControl", Null)))
    Return np
End Sub

B4X:
player1.InitializeCustom("player", CreateNativePlayer)
 
Upvote 0
Solution

JohnC

Expert
Licensed User
Longtime User
Works great!

Thank you.
 
Upvote 0
Top