Android Question how to modify the ExoPlayer "referer"?

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this:
B4X:
Dim jo As JavaObject = player1.CreateUriSource("...")
Dim r As Reflector
r.Target = jo
r.Target = r.GetField("dataSourceFactory")
Dim http As JavaObject = r.GetField("baseDataSourceFactory")
Log(GetType(http))
http.RunMethod("setDefaultRequestProperties", Array(CreateMap("referer": "test")))

It runs properly. I haven't checked whether the header is actually sent.
 
Upvote 0

mywmshow

Member
@Erel
When my URL is .m3u8, report the following error!
Please help me take a look at how to deal with, thank you very much!

B4X:
java.lang.NoSuchFieldException: baseDataSourceFactory
    at java.lang.Class.getDeclaredField(Class.java:890)
    at anywheresoftware.b4a.agraham.reflection.Reflection.GetField(Reflection.java:316)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
What do you want to change in the "Referer" of exoplayer?


the video is seen in exoplayer

1655185014329.png


B4X:
    player1.Initialize("player")
    Dim sources As List
    sources.Initialize
    sources.Add(player1.CreateHLSSource("https://r1-ndr.ykt.cbern.com.cn/edu_product/65/video/17b2ed7f547a11eb96b8fa20200c3759/fc490e8bb61d62ff98f81160030c1d43.1280.720.false/fc490e8bb61d62ff98f81160030c1d43.1280.720.m3u8"))
    player1.Prepare(player1.CreateListSource(sources))
    SimpleExoPlayerView1.Player = player1
    player1.Play
 
Upvote 0

rithrosh

New Member
Apologies to reply in this old thread, but am facing the same issue while trying to modify the 'referer' for and HLS Stream using exoplayer.

The same error comes as listed below, while trying to access "http As JavaObject = r.GetField("baseDataSourceFactory")".

B4X:
java.lang.NoSuchFieldException: No field baseDataSourceFactory in class Lcom/google/android/exoplayer2/source/hls/DefaultHlsDataSourceFactory; (declaration of 'com.google.android.exoplayer2.source.hls.DefaultHlsDataSourceFactory' appears in base.apk!classes2.dex)
    at java.lang.Class.getDeclaredField(Native Method)
    at anywheresoftware.b4a.agraham.reflection.Reflection.GetField(Reflection.java:316)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:6597)
    at android.view.View.performClickInternal(View.java:6574)
    at android.view.View.access$3100(View.java:778)
    at android.view.View$PerformClick.run(View.java:25885)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**



Code used is listed below, in the Log it has the value of Log(GetType(r.Target)) as "com.google.android.exoplayer2.source.hls.DefaultHlsDataSourceFactory"

B4X:
    Dim jo As JavaObject = player1.CreateHlsSource(uri)

    Dim r As Reflector

    r.Target = jo

    r.Target = r.GetField("dataSourceFactory")

    Log(GetType(r.Target))

    Dim http As JavaObject = r.GetField("baseDataSourceFactory")


How to deal with this, is there any way to sort this.
 
Upvote 0
Top