Android Question Exoplayer play/pause state

Shivito1

Active Member
Licensed User
how do I get the status of the player?

I have tried
log(player1.pause)
log(player1)
and a few other futile attempts with no success.

Is this possible?
 

Shivito1

Active Member
Licensed User
My mistake. The correct code is:
B4X:
jo.CreateEventFromUI("com.google.android.exoplayer2.ExoPlayer$EventListener", "statechanged", False)

I actually later played with it to understand why it fails with other values and mistakenly posted the wrong version.
Oh my... It worked! Big Thanks to all who took the time to assist I really appreciate it :)
 
Upvote 0

cxdzbl

Active Member
Licensed User
You can see the events here: https://www.b4x.com/android/help/exoplayer.html#simpleexoplayer
Or in the IDE.

Adding an event listener to monitor the playback state:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     player1.Initialize("player")
     Dim sources As List
     sources.Initialize
     sources.Add(player1.CreateDashSource("http://www.youtube.com/api/manifest/dash/id/bf5bb2419360daf1/source/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=51AF5F39AB0CEC3E5497CD9C900EBFEAECCCB5C7.8506521BFC350652163895D4C26DEE124209AA9E&key=ik0"))
     sources.Add(player1.CreateHLSSource("https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8"))
     sources.Add(player1.CreateUriSource("http://html5demos.com/assets/dizzy.mp4"))
     player1.Prepare(player1.CreateListSource(sources))
     Dim jo As JavaObject = player1 
     Dim event As Object = jo.CreateEventFromUI("com.google.android.exoplayer2.ExoPlayer$EventListener", "statechanged", False)
     jo.GetFieldJO("player").RunMethod("addListener", Array(event))
   End If
   Activity.LoadLayout("1")
   SimpleExoPlayerView1.Player = player1
   player1.Play
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
Thank you
 
Upvote 0
Top