AudioExoPlayer a simple player with great potential

I have located the problem, it will be fixed in the next update

1 Like

Thanks!

Also I have a feature request for your consideration: add an OtherPlayerStarted event.

The project in which that I first encountered the above missing Playback error is one which has two players that respond to OtherPlayerStarted :slight_smile:

Kind regards,
Randal

I don't know if this will be possible. I see that Player has such an event, but it's inactive from what I can see. I'll see what can be done. What do you plan to use this event for?

Here is a test app that has two Player components set to play the same mp3 file (looped) at different volume levels.

When you start one player while the other is running, it will stop itself and update the status using the OtherPlayerStarted event... seems to work for me.

OtherPlayer_Test.aia (4.1 MB)

My app has a Player running in an Itoo service (background) that is sourced to a live audio stream of an event (eg., a sports event). By manually (using UI buttons) pausing and restarting the Player it can be adjusted to be synchronized with a live video stream (on a different device) of the same event.

But if another app starts (or a phone call comes in) it could pause/stop the Player - thus making it out of sync with the video. :frowning:

I am hoping to be able to detect this and and possibly just restart and mute my player to retain the sync... but this may not work... I have yet to demonstrate it with the standard Player component...but that is the idea.

I have an alternative in mind if this is not possible ...

Thanks for checking into it.

Kind regards,
Randal

So I think you need focus management, not necessarily an event when another player starts. I think you can set the focus so it doesn't react to other players.

Hmmm... Maybe I don't understand what you are suggesting ...

The user interface (Screen1) of my app does not remain active. Once the player is launched (by a service/process created by Itoo Open Source β€’ Background Tasks: Itoo πŸš€ ) the user interface can be exited and the app plays from the background while other apps are active... so I am not sure what focus should be maintained... What am I missing?

-Randal

The OtherPlayerStarted notification works based on the player's focus. When the player loses focus for various reasons, such as a call, changes its behavior, mutes, pauses, etc., the player built into the app inventor implements focus support. It also has a listener that detects the loss of focus and triggers the OtherPlayerStarted event. My extension is based on the exo player library, which manages focus itself. To trigger the OtherPlayerStarted event, I would have to disable the built-in focus support and implement it myself. However, I think this is better implemented in the library than I could do myself. But it is possible... OK, explain to me: when your player loses focus because someone is calling, for example, what do you do in the OtherPlayerStarted event?

I have not successfully implemented this yet...Looks like you understand this MUCH better than I do. I was trying to use the phone call component to detect the beginning of a call but I encountered a problem that I reported in post number 1113 in this thread:

The idea is to mute the player (Vol=0) and immediately re/start it when a phone call was started...and then unmute it when the call ended... But the phone call notification is not now working in Itoo

So how do you recommend that I detect the loss of focus since the Phone Call component does not presently work from within Itoo? Is there another way to detect the beginning of a call? Or should simply wait until this is made available in Itoo?

Thank you for your help.

-Randal

I can make the player mute the sound on incoming calls.

Well, if that will be a set-able/read-able boolean property, it would be quite nice!! :slight_smile:

If set=true,
On incomming calls: AudioExoPlayer does not pause but sound is muted (or Vol=0)

On call end (no answer or hangup or refuse, etc.) : AudioExoPlayer is unmuted (or Vol is set to previous vol)

Is that what you propose? That would be just what I need!!

-Randal

I tested this on my POCO phone with Android 15, and it doesn't work for me. Starting the second player doesn't trigger the OtherPlayerStarted event.

Hmmm... I assume you ran the OtherPlayer_Test.aia app that I posted above...

Let me try on other API/OS versions...

But as far as I am converned if you can implement the OnPhoneCallStart and OnPhoneCallEnd events/actions as discussed above, I would preferr that to the OtherPlayerStarted ... since the Phone call interruption on my phone did NOT fire the IA2 Comp[onent Player.OtherPlayerStarted event anyway. So your suggestion is better for me ... maybe not for other users??

Let me test a bit and get back.

-Randal

Tested on API 26 (OS ver 8) and 35 (OS ver 15) and seems to work for me.

Start Player 1 (Note that Player1 volume is set VERY low...), then start Player 2 which stops player 1 and starts player 2 playing the same audio clip but louder...I also get the momentary display/Alert notification stating one player detects the start of the other.

You can check which player is playing (or not) with the Display Player Status button...

Can you tell me what happens? Do both players play after starting the second one? If you start player2 first (louder one) does player1 start (use button to see which are playing) and player2 keeps playing...

You might remove/delete Notifier1 just to see of that's possibly making the difference. When I deleted it, it took no other code changes and it worked as expected. Again, you can use button to verify which is or is not playing...

-Randal

Yes, both players are playing simultaneously for me. I swapped Player for my AudioExoPlayer and got the same result. I think it might be some internal implementation changes depending on the phone manufacturer. But I still receive a notification whenever a call comes in.

So if you need such an event, I can do something like AudioFocusChanged, which returns a boolean value indicating focus lost. If it returns true, it means focus has been lost and someone is calling, and if it returns false, it means the call has been disconnected.

Yes, an Event. But to clarify, by "returns" do you mean that the event passes a single boolean parameter? That would be good...I just want to be sure you don't mean a function that returns a boolean value when called?

However, FULL DISCLOSURE:

I have to tell you that the AudioExoPlayer will be running in an Itoo service/process (;which I have implemented).

BUT, earlier I reported what appears to be a bug (Open Source β€’ Background Tasks: Itoo πŸš€ - #1165 by Randal_Andress ) that prevents the PhoneCall component's events IncomingCallAnswered and PhoneCallEnded from working...

If you are using these PhoneCall events in your extension to provide this new event, I'm concerned that it may not work from within Itoo either. If you build it, I am happy to try it, but I would not want you to go to a lot of trouble building it when it may not work from Itoo :frowning: ... and if it is fixed, then I can simply use the PhoneCall component for these events :slight_smile: ... I'd like to give your new event a try, but it may not solve my problem.

-Randal

The previous event had a "focusLost" parameter, which will only be true if losing focus would result in your player being paused (e.g., while someone is calling on the phone or using an instant messenger). Sometimes, losing focus will cause the player to mute, but this won't trigger the event.

If this event is called with an argument of true, it will mean that my player has lost focus and has been paused, correct?

So, if I set the volume to zero and issue a Play command, that should minimize any delay added to the stream that is playing.

Will the event be called when the call or message has ended with a parameter of false? If so, I could then unmute my player.

-Randal

No, it is not possible to play when the player is not have focus. I tried.

You can try a new event.

Thanks, @Patryk_F, for version 2.0! Just downloaded it and the test app... looking forward to trying it tonight!

Tnx,
Randal