Android Question [Solved] Questions about ExoPlayer (Media3) event listeners

park jae hyun

Member
Licensed User
Longtime User
ExoPlayer (Media3)
I would like to know how to add an event listener to monitor the playing status.

Previous work was

ExoPlayer (Media3)
B4X:
Dim jo As JavaObject = player1
    Dim event As Object = jo.CreateEventFromUI("androidx.media3.exoplayer.Player$EventListener", "statechanged", False)
    jo.GetFieldJO("player").RunMethod("addListener", Array(event))

It doesn't work.
What should I do?
 

park jae hyun

Member
Licensed User
Longtime User
I need to know when the player is paused or playing

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1   
    Root.LoadLayout("MainPage")
    
    Player.Initialize("Player")
    Player.Prepare(Player.CreateUriSource("https://bestvpn.org/html5demos/assets/dizzy.mp4"))
        
    Dim jo As JavaObject = Player
    Dim event As Object = jo.CreateEventFromUI("androidx.media3.exoplayer.Player$EventListener", "statechanged", False)  'Error
    jo.GetFieldJO("player").RunMethod("addListener", Array(event))
        
    SimpleExoPlayerView1.Player = Player
    Player.Play
    lblEnterFullScreen.Visible = False
End Sub

Sub StateChanged_Event (MethodName As String, Args() As Object) As Object
    If MethodName = "onPlayerStateChanged" Then
        Dim Playing As Boolean = Args(0)
        Log("IsPlaying: " & Playing)
    End If
    Return Null
End Sub

B4X:
** Service (starter) Start **
** Activity (main) Create (first time) **
Error occurred on line: 30 (B4XMainPage)
java.lang.ClassNotFoundException: androidx$media3$exoplayer$Player$EventListener
    at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:289)
    at anywheresoftware.b4j.object.JavaObject.createEvent(JavaObject.java:253)
    at anywheresoftware.b4j.object.JavaObject.CreateEventFromUI(JavaObject.java:223)
    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.debug.Debug.delegate(Debug.java:262)
    at b4a.ExoPlayerFullScreen.b4xmainpage._b4xpage_created(b4xmainpage.java:50)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
    at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1087)
    at b4a.ExoPlayerFullScreen.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:1069)
    at b4a.ExoPlayerFullScreen.b4xpagesmanager._showpage(b4xpagesmanager.java:426)
    at b4a.ExoPlayerFullScreen.b4xpagesmanager._addpage(b4xpagesmanager.java:246)
    at b4a.ExoPlayerFullScreen.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:260)
    at b4a.ExoPlayerFullScreen.b4xpagesmanager._initialize(b4xpagesmanager.java:166)
    at b4a.ExoPlayerFullScreen.main._activity_create(main.java:429)
    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 b4a.ExoPlayerFullScreen.main.afterFirstLayout(main.java:105)
    at b4a.ExoPlayerFullScreen.main.access$000(main.java:17)
    at b4a.ExoPlayerFullScreen.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
 
Upvote 0
Top