Android Question video track for Exoplayer

zedapp

Member
Hello friends, i am using exoplayer i my app, and i wanna get for each video played (for expl .m3u8) his video track displayed in config of exoplayer, how can i do that and thanx
 

zedapp

Member
this is the error log:


** Activity (main) Pause event (activity is not paused). **
** Activity (fullscreen) Create (first time) **
** Activity (fullscreen) Resume **
Error occurred on line: 114 (FullScreen)
java.lang.ClassNotFoundException: com.google.android$exoplayer2$trackselection$DefaultTrackSelector
at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:289)
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:84)
at com.Aymentv.b4o.fullscreen$ResumableSub_Activity_Create.resume(fullscreen.java:771)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
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:351)
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.raiseEvent(BA.java:201)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1748)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:8919)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
 
Upvote 0

zedapp

Member
code used to get avilables video qualities played in exoplayer:
'-------------------------------------------------------------------------

Dim trackSelector As JavaObject
trackSelector.InitializeNewInstance("com.google.android.exoplayer2.trackselection.DefaultTrackSelector", Null)

Dim player As JavaObject
player = SimpleExoPlayer1
player.RunMethod("setTrackSelector", Array(trackSelector))

Dim mappedTrackInfo As JavaObject
mappedTrackInfo = trackSelector.RunMethod("getCurrentMappedTrackInfo", Null)

If mappedTrackInfo <> Null Then
Dim qualities As List
qualities.Initialize

For rendererIndex = 0 To mappedTrackInfo.RunMethod("getRendererCount", Null) - 1
Dim trackGroups As JavaObject
trackGroups = mappedTrackInfo.RunMethod("getTrackGroups", Array(rendererIndex))

For groupIndex = 0 To trackGroups.RunMethod("length", Null) - 1
Dim trackGroup As JavaObject
trackGroup = trackGroups.RunMethod("get", Array(groupIndex))

For trackIndex = 0 To trackGroup.RunMethod("length", Null) - 1
Dim format As JavaObject
format = trackGroup.RunMethod("getFormat", Array(trackIndex))
Dim quality As String
quality = $"Resolution: ${format.GetField("width")}x${format.GetField("height")}, Bitrate: ${format.GetField("bitrate")}"$
qualities.Add(quality)
Next
Next
Next

' Display the qualities in a ListView or any other UI component
For Each quality As String In qualities
Log(quality) ' You can also add this to a ListView or other UI component
Next
End If
 
Upvote 0

zedapp

Member
Hellow, finally after searching i have find the sollution, and the code is:
'*****************************************************************************
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
PopulateVideoQualities
End Sub

Sub PopulateVideoQualities
Dim mp As B4XMainPage = B4XPages.MainPage
Dim jo As JavaObject = mp.Player
TrackGroups = jo.GetFieldJO("player").RunMethod("getCurrentTrackGroups", Null)

Dim videoQualities As List
videoQualities.Initialize

For i = 0 To TrackGroups.GetField("length") - 1
Dim TrackGroup As JavaObject = TrackGroups.RunMethod("get", Array(i))
For j = 0 To TrackGroup.GetField("length") - 1
Dim Format As JavaObject = TrackGroup.RunMethodJO("getFormat", Array(j))
Dim mime As String = Format.GetField("sampleMimeType")
If mime.StartsWith("video") Then
Dim width As Int = Format.GetField("width")
Dim height As Int = Format.GetField("height")
If width > 0 And height > 0 Then
Dim quality As String = width & ", " & height
videoQualities.Add(quality)
End If
End If
Next
Next

' Populate ListView with video qualities
For Each quality As String In videoQualities
lvQualities.AddSingleLine(quality)
Next
End Sub

Sub lvQualities_ItemClick (Position As Int, Value As Object)
Dim quality As String = Value
Dim parts() As String = Regex.Split(", ", quality)
Dim width As Int = parts(0)
Dim height As Int = parts(1)
SetVideoResolution(width, height)
End Sub

Private Sub SetVideoResolution(x As Int, y As Int)
Dim mp As B4XMainPage = B4XPages.MainPage
Dim jo As JavaObject = mp.Player
Dim trackSelector As JavaObject = jo.GetField("trackSelector")
trackSelector.RunMethod("setParameters", Array(trackSelector.RunMethodJO("buildUponParameters", Null).RunMethod("setMaxVideoSize", Array(x, y))))
End Sub
 

Attachments

  • video_qualities.jpg
    37.9 KB · Views: 67
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…