Android Question ExoPlayer User-agent

Pendrush

Well-Known Member
Licensed User
Longtime User
Is there any chance to change ExoPlayer user-agent?
Default user agent is: AppName/AppVerison (Linux;Android 7.0) ExoPlayerLib/2.5.3

As app get Cyrillic name, User-Agent become Cyrillic also and that create a lot of problems on ShoutCast servers.
 

Pendrush

Well-Known Member
Licensed User
Longtime User
I'm using: Plejer.Prepare(Plejer.CreateHLSSource(streamUrl) and Plejer.Prepare(Plejer.CreateUriSource(streamUrl)).
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Different approach here.

1. Add this code:
B4X:
#if Java
import anywheresoftware.b4a.keywords.B4AApplication;
import android.content.pm.PackageManager.NameNotFoundException;
import anywheresoftware.b4a.objects.SimpleExoPlayerWrapper;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
public static class MySimpleExoPlayerWrapper extends SimpleExoPlayerWrapper {
@Override
public DefaultDataSourceFactory createDefaultDataFactory() {
     return new DefaultDataSourceFactory(BA.applicationContext, "custom user agent here");
   }
}

#End If

2. Use the new class:
B4X:
Sub Globals
   Private SimpleExoPlayerView1 As SimpleExoPlayerView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Dim jo As JavaObject
   jo.InitializeNewInstance(Application.PackageName & ".main$MySimpleExoPlayerWrapper", Null)
   SimpleExoPlayerView1 = jo
   '...
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
ExoPlayer is in service "srvPlayer" I have changed intialize line, but after try to playstream i get this error
Line 184: Plejer.Prepare(Plejer.CreateUriSource(StreamUrlStanice))

Initialize line on service_create
B4X:
Dim jo As JavaObject
jo.InitializeNewInstance(Application.PackageName & ".srvplayer$MySimpleExoPlayerWrapper", Null)
Plejer = jo
 
Upvote 0

MAGAREY

Member
Licensed User
Longtime User
the global variable is simpleexoplayer
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…