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
B4X:
Sub ExoPlayer_Complete

End Sub
Well spoke to soon again I tried the following

B4X:
Sub ExoPlayer_Complete
    log("test")
End Sub
In my program I set player1 = to SimpleExoPlayer so I also tried
B4X:
Sub player1_Complete
    log("test")
End Sub

on both I never received the "test" log message
 
Upvote 0

Shivito1

Active Member
Licensed User
Okay lol it only triggers at the end of the video
that does not help really.

I need to know when ever play or pause is pressed.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I did not find that documented any where.
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.Player$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
 
Last edited:
Upvote 0

Shivito1

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", 10)
     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

Starting to wonder if I should let this one go. I really hate to keep taking up your time. however I have tried this and got the following error.
B4X:
** Activity (main) Create, isFirst = true **
0
Panel size is unknown. Layout may not be loaded correctly.
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
java.lang.IndexOutOfBoundsException: Index: 1807, Size: 1807
End of SRT File
(ArrayList) [1, 00:00:03,844 --> 00:00:05,945, Oh, for gloyvin' out loud., , 2, 00:00:32,019 --> 00:00:36,019, <font color="#00FF00">♪ The Simpsons 26x19 ♪</font>, <font color="#00FFFF">The Kids Are All Fight</font>, Original Air Date on April 26, 2015, , 3, 00:00:46,678 --> 00:00:48,111, D'oh!, , 4, 00:00:50,815 --> 00:00:54,815, == sync, corrected by <font color=#00FF00>elderman</font> ==, <font color=#00FFFF>@elder_man</font>, , 5, 00:00:54,953 --> 00:00:57,654, Well, this is, a no-brainer., , 6, 00:01:02,427 --> 00:01:03,961, D'oh!, , 7, 00:01:05,430 --> 00:01:07,030, D'oh!, , 8, 00:01:08,299 --> 00:01:09,666, D'oh!, , 9, 00:01:10,802 --> 00:01:12,436, D'oh!, , 10, 00:01:14,472 --> 00:01:15,839, D'oh!, , 11, 00:01:15,874 --> 00:01:17,274, D'oh!, , 12, 00:01:17,308 --> 00:01:18,742, D'oh!, , 13, 00:01:18,776 --> 00:01:20,844, D'oh!, , 14, 00:01:20,879 --> 00:01:21,879, D'oh!, , 15, 00:01:21,880 --> 00:01:23,313, D'oh!, , 16, 00:01:28,553 --> 00:01:29,620, Now what?, , 17, 00:01:42,000 --> 00:01:43,834, Well, I better get going., , 18, 00:01:43,868 --> 00:01:45,636, Should I just put that, on your tab?, , 19, 00:01:45,670 --> 00:01:47,204, No, I'll pay off my bill., , 20, 00:01:47,238 --> 00:01:48,639, Hmm?, , 21, 00:01:48,673 --> 00:01:49,940, Oh, my God! Oh, my God!, , 22, 00:01:49,974 --> 00:01:51,341, Someone's actually paying?, , 23, 00:01:51,376 --> 00:01:54,811, Now let me see if I remember, how to open this thing., , 24, 00:01:54,846 --> 00:01:56,446, Some kind of button or knob., , 25, 00:01:57,582 --> 00:01:59,883, So that's what that noise means., , 26, 00:01:59,918 --> 00:02:01,051, Just take your stupid money., , 27, 00:02:01,085 --> 00:02:02,519, Huh?, , 28, 00:02:02,553 --> 00:02:05,822, Hey, this jacket's, full of old stuff., , 29, 00:02:05,857 --> 00:02:07,925, I knew I wasn't getting, my money., , 30, 00:02:08,893 --> 00:02:10,494, Hey., , 31, 00:02:11,496 --> 00:02:13,096, D'oh!, , 32, 00:02:14,165 --> 00:02:15,465, Losers., , 33, 00:02:15,500 --> 00:02:17,200, What the...?, , 34, 00:02:17,235 --> 00:02:19,603, Oh., , 35, 00:02:21,039 --> 00:02:22,506, Ooh!, , 36, 00:02:22,540 --> 00:02:24,508, Here's a roll of film, I never developed., , 37, 00:02:24,542 --> 00:02:25,709, Well, too late for that., , 38, 00:02:25,743 --> 00:02:27,477, All those, photo developing joints, , 39, 00:02:27,512 --> 00:02:30,547, are either knocked down or have, been turned into deer blinds., , 40, 00:02:42,260 --> 00:02:43,493, Eh, listen, Homer., , 41, 00:02:43,528 --> 00:02:45,162, Uh, I can develop this for you., , 42, 00:02:45,196 --> 00:02:47,197, Yeah, this bar is so poorly lit,, , 43, 00:02:47,231 --> 00:02:49,333, it's legally a darkroom., , 44, 00:02:49,367 --> 00:02:51,802, Mmm... mmm., , 45, 00:02:51,836 --> 00:02:53,003, And the best part is,, , 46, 00:02:53,037 --> 00:02:55,038, Duff is, chemically indistinguishable, , 47, 00:02:55,073 --> 00:02:56,673, from developing fluid., , 48, 00:02:56,708 --> 00:02:58,442, Way to go, Duff!, , 49, 00:02:58,476 --> 00:03:00,377, I'm developing quite a thirst., , 50, 00:03:00,411 --> 00:03:02,746, Now, there's an, eight-by-ten I can enjoy., , 51, 00:03:13,558 --> 00:03:14,958, Here you go, Midge., , 52, 00:03:14,993 --> 00:03:17,194, I played with the colors, and changed the lighting,, , 53, 00:03:17,228 --> 00:03:19,796, but I could only make your kids, so cute and no cuter., , 54, 00:03:19,831 --> 00:03:21,098, This is so exciting., , 55, 00:03:21,132 --> 00:03:22,699, It's like a sneak peek, , 56, 00:03:22,734 --> 00:03:25,802, into the long-forgotten, world of six years ago., , 57, 00:03:25,837 --> 00:03:27,437, Yeah, well, beware., , 58, 00:03:27,472 --> 00:03:29,473, These pictures show, that six years ago,, , 59, 00:03:29,507 --> 00:03:30,774, Bart and Lisa were fighting, , 60, 00:03:30,808 --> 00:03:32,809, like creationists, and common sense., , 61, 00:03:34,145 --> 00:03:35,779, Hey, photos don't lie,, my friend., , 62, 00:03:37,515 --> 00:03:38,915, Would you like, a matte finish?, , 63, 00:03:38,950 --> 00:03:40,183, Sur
Message longer than Log limit (4000). Message was truncated.
Panel size is unknown. Layout may not be loaded correctly.
Error occurred on line: 1404 (Main)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:755)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:345)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
    at android.view.View.performClick(View.java:6257)
    at android.widget.TextView.performClick(TextView.java:11149)
    at android.view.View$PerformClick.run(View.java:23705)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6780)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: java.lang.ClassCastException: Couldn't convert result of type int to boolean
    at $Proxy0.equals(Unknown Source)
    at java.util.concurrent.CopyOnWriteArrayList.indexOf(CopyOnWriteArrayList.java:497)
    at java.util.concurrent.CopyOnWriteArrayList.indexOf(CopyOnWriteArrayList.java:155)
    at java.util.concurrent.CopyOnWriteArrayList.contains(CopyOnWriteArrayList.java:125)
    at java.util.concurrent.CopyOnWriteArrayList.addIfAbsent(CopyOnWriteArrayList.java:335)
    at java.util.concurrent.CopyOnWriteArraySet.add(CopyOnWriteArraySet.java:233)
    at com.google.android.exoplayer2.ExoPlayerImpl.addListener(ExoPlayerImpl.java:89)
    at com.google.android.exoplayer2.SimpleExoPlayer.addListener(SimpleExoPlayer.java:405)
    ... 21 more
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
ion: Index: 1807, Size: 1807
you are accessing an item from a list which is out of bounds.
A list with 10 items have the indexes 0 to 9. If you want you access index 10 then it crshes.
This is what happens here... Check your routine and make sure to use for i= 0 to list.size -1
 
Upvote 0

Shivito1

Active Member
Licensed User
you are accessing an item from a list which is out of bounds.
A list with 10 items have the indexes 0 to 9. If you want you access index 10 then it crshes.
This is what happens here... Check your routine and make sure to use for i= 0 to list.size -1
thanks however after fixing that I still have the java error.
B4X:
Error occurred on line: 1404 (Main)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:755)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:345)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
    at android.view.View.performClick(View.java:6257)
    at android.widget.TextView.performClick(TextView.java:11149)
    at android.view.View$PerformClick.run(View.java:23705)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6780)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: java.lang.ClassCastException: Couldn't convert result of type int to boolean
    at $Proxy0.equals(Unknown Source)
    at java.util.concurrent.CopyOnWriteArrayList.indexOf(CopyOnWriteArrayList.java:497)
    at java.util.concurrent.CopyOnWriteArrayList.indexOf(CopyOnWriteArrayList.java:155)
    at java.util.concurrent.CopyOnWriteArrayList.contains(CopyOnWriteArrayList.java:125)
    at java.util.concurrent.CopyOnWriteArrayList.addIfAbsent(CopyOnWriteArrayList.java:335)
    at java.util.concurrent.CopyOnWriteArraySet.add(CopyOnWriteArraySet.java:233)
    at com.google.android.exoplayer2.ExoPlayerImpl.addListener(ExoPlayerImpl.java:89)
    at com.google.android.exoplayer2.SimpleExoPlayer.addListener(SimpleExoPlayer.java:405)
    ... 21 more
 
Upvote 0

Shivito1

Active Member
Licensed User
you are accessing an item from a list which is out of bounds.
A list with 10 items have the indexes 0 to 9. If you want you access index 10 then it crshes.
This is what happens here... Check your routine and make sure to use for i= 0 to list.size -1
B4X:
    If vidfile.Length > 0 Then
        player1.Initialize("player")
        sources.Initialize
        sources.Add(player1.CreateFileSource(vidpath,vidfile))
        player1.Prepare(player1.CreateListSource(sources))
        '        SimpleExoPlayerView1.
        Dim jo As JavaObject = player1
        Dim event As Object = jo.CreateEventFromUI("com.google.android.exoplayer2.ExoPlayer$EventListener", "statechanged", 10)
        jo.GetFieldJO("player").RunMethod("addListener", Array(event))
        subspinnerint = 130
        SimpleExoPlayerView1.Player = player1
        whileplaying.Enabled = True
        StartService(Videosub_service)
   
        p.SetScreenOrientation(-1)
    Else
        Msgbox("No Videos in Downloads folder","Error No Video Selected")
        player1.Initialize("player")
        sources.Initialize
        player1.Prepare(player1.CreateListSource(sources))
        B5_Click
    End If

   
End Sub

'player1 state changed
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

okay, the blue underlined section is where the issue is taking place. I tried making that last parameter Boolean(returns no errors but does not trigger the StateChanged Sub)
 
Upvote 0

Shivito1

Active Member
Licensed User
I put a Boolean in and still same error. Man this is frustrating. If it wasn't such an important part I might just toss the idea altogether lol. I've been at this piece for days :(

thanks for your continued help though.
 
Upvote 0

fixit30

Active Member
Licensed User
Longtime User
Based on the error you should replace
B4X:
Dim Playing As Boolean = Args(0)
With
B4X:
Dim Playing As Int = Args(0)
 
Upvote 0

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.
I see. well I'm going to give it a try. Thanks :)
 
Upvote 0
Top