Android Question How to add referer in ExoPlayer

david7374

Member
I tried, It gives this error:

Error:
java.lang.NoSuchFieldException: No field baseDataSourceFactory in class Landroidx/media3/exoplayer/hls/DefaultHlsDataSourceFactory; (declaration of 'androidx.media3.exoplayer.hls.DefaultHlsDataSourceFactory' appears in /data/app/b44664.exadsdsdfdfple-dJX1ozhzon9IWr9_W0QEBA==/base.apk)
    at java.lang.Class.getDeclaredField(Native Method)
    at anywheresoftware.b4a.agraham.reflection.Reflection.GetField(Reflection.java:316)
    at b44664.exadsdsdfdfple.b4xmainpage._b4xpage_created(b4xmainpage.java:60)
    at b44664.exadsdsdfdfple.b4xmainpage.callSub(b4xmainpage.java:134)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1098)
    at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:1069)
    at b44664.exadsdsdfdfple.b4xpagesmanager._vvvvvvvvvvvvv1(b4xpagesmanager.java:529)
    at b44664.exadsdsdfdfple.b4xpagesmanager._vvv3(b4xpagesmanager.java:866)
    at b44664.exadsdsdfdfple.b4xpagesmanager._v0(b4xpagesmanager.java:200)
    at b44664.exadsdsdfdfple.b4xpagesmanager._vv1(b4xpagesmanager.java:207)
    at b44664.exadsdsdfdfple.b4xpagesmanager._initialize(b4xpagesmanager.java:717)
    at b44664.exadsdsdfdfple.main._activity_create(main.java:366)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
    at b44664.exadsdsdfdfple.main.afterFirstLayout(main.java:105)
    at b44664.exadsdsdfdfple.main.access$000(main.java:17)
    at b44664.exadsdsdfdfple.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:900)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:219)
    at android.app.ActivityThread.main(ActivityThread.java:8668)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)

Error in this line:

Error:
Dim http As JavaObject = r.GetField("baseDataSourceFactory")
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code allows you to add headers to the request:
B4X:
Private Sub CreateUriSource(Uri As String) As Object
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim HttpDataSourceFactory As JavaObject
    HttpDataSourceFactory.InitializeNewInstance("androidx.media3.datasource.DefaultHttpDataSource$Factory", Null)
    'HttpDataSourceFactory.RunMethod("setAllowCrossProtocolRedirects", Array(True))
    Dim DataSource As JavaObject = HttpDataSourceFactory.RunMethod("createDataSource", Null)
    DataSource.RunMethod("setRequestProperty", Array("header", "value")) '<------  
    Dim DataSourceFactory As JavaObject = ctxt.CreateEvent("androidx.media3.datasource.DataSource.Factory", "", DataSource)
    Dim ProgressiveMediaSourceFactory As JavaObject
    ProgressiveMediaSourceFactory.InitializeNewInstance("androidx.media3.exoplayer.source.ProgressiveMediaSource.Factory", Array(DataSourceFactory))
    Dim MediaItem As JavaObject
    MediaItem.InitializeStatic("androidx.media3.common.MediaItem")
    Return ProgressiveMediaSourceFactory.RunMethod("createMediaSource", Array(MediaItem.RunMethod("fromUri", Array(Uri))))
End Sub
 
Upvote 0
Top