Android Question Exoplayer "getPlackbackState Not found" error when checking for buffering state

mcqueccu

Well-Known Member
Licensed User
Longtime User
I want to be able to know when my radio streaming app is buffering or idle but i kept getting this error.

B4X:
Sub Process_Globals
    Dim exoplay As SimpleExoPlayer
    Dim connect As String = "http://streaming.shoutcast.com/LeafeCodesOnline?lang=en-US%2cen%3bq%3d0.9"
    Dim tm As Timer
End Sub

Sub Globals
    Private playView As SimpleExoPlayerView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("ui")
    
    playView.Player = exoplay
    
    exoplay.Initialize("exoplay")
    exoplay.Prepare(exoplay.CreateUriSource(connect))
    exoplay.Play
    
    tm.Initialize ("tm",1000)
    tm.Enabled = True   
End Sub

Sub exoplay_Ready
    Log("Player is ready")
End Sub

Sub exoplay_Error (Message As String)
    Log("Error: " & Message)
End Sub
    
Sub exoplay_complete
    Log("complete")
End Sub

Sub exoplay_TrackChanged
    Log("Track Changed")
End Sub
    
Sub tm_Tick
    Dim jo As JavaObject = exoplay
    Dim state As Int = jo.RunMethod("getPlaybackState", Null)

'    1 = IDLE
'    2 = BUFFERING
'    3 = READY
'    4 = ENDED

    Select state
        Case 1
            Log("IDLE")
        Case 2
            Log("BUFFERING")
        Case 3
            Log("READY")
        Case 4
            Log("ENDED")
    End Select
End Sub

ERROR

B4X:
Logger connected to:  motorola Moto C Plus
--------- beginning of main
Track Changed
main_tm_tick (java line: 438)
--------- beginning of system
java.lang.RuntimeException: Method: getPlaybackState not found in: anywheresoftware.b4a.objects.SimpleExoPlayerWrapper
    at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:366)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:119)
    at com.leafecodes.onlineradio.main._tm_tick(main.java:438)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
    at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6251)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1075)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
--------- beginning of crash
 

Attachments

  • player.zip
    48.9 KB · Views: 373

Serge Bertet

Active Member
Licensed User
Hi,

did you reach your goal monitiring state of player?
I followed your 2 threads about that, tried all Erel's advice but i'm still not able to do that.
B4X:
    Dim jo As JavaObject = player
    jo = jo.GetField("player")
    Dim state As Int = jo.RunMethod("getPlaybackState", Null)
    If state = 2 Then ProgressDialogShow("Buffering ...")    ' BUFFERING
    If state = 3 Then ProgressDialogHide                    ' READY

with : Private player As SimpleExoPlayer in Process_Globals
and : Private ExoPlayerView As SimpleExoPlayerView in Globals

I get this message "Cannot get methods of class: com.google.android.exoplayer2.SimpleExoPlayer, disabling cache."
followed by "java.lang.NullPointerException at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:343)"

I tried also with your create_event function and all callback, but no chance.

Serge
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
Yes, its working fine..If you can upload a small project for me to run...

I hope you are running that code in a timer tick subroutine?

B4X:
Sub tmDetectState_Tick
    Dim jo As JavaObject = exoplay   'i declared my player as exoplay
    jo = jo.GetField("player")
    Dim state As Int = jo.RunMethod("getPlaybackState", Null)

'    1 = IDLE
'    2 = BUFFERING
'    3 = READY
'    4 = ENDED

    Select state
        Case 1
            Log("IDLE")           
        Case 2
            Log("BUFFERING")
            pb.Visible = True      'Show loading progressbar
        Case 3
            Log("READY")
            pb.Visible = False     'hide loading progressbar
        Case 4
            Log("ENDED")
    End Select
End Sub
 
Upvote 0

Serge Bertet

Active Member
Licensed User
Thank you for your answer,
I do not see any difference with my code.
Yes, I run this code in a 100ms timer.
Actually I do not play videos as streaming but from local storage, maybe that makes a difference.
When i seek video from beginning to the middle the user needs to wait so I want to inform him.
Serge
 
Upvote 0
Top