How do I create a mute (music or sound) button for all screens

I’ve added a player component at Home screen, and left the screen open while browsing on other screens so that the music keeps playing.

Is there a way to close that Home screen to stop the music while on another ‘Settings’ screen?

And is there a better way to add music to app without letting the Home screen open, while also being able to pause/stop it?

Thanks.

You can use this block to do that:
Capturar

In my apps I prefer to switch arrangements instead of screens. This way if I want to pause/stop sound I won’t find any trouble.

Could you please elaborate on the ‘Start Value’ approach? You mean navigating back to Home screen when mute button is pressed, with a variable?
Like this?:

Edit: I did a mistake on the code blocks so I edited the comment to change the picture.

You have to send the value to Settings Screen that the music is mute and when you go back to Home Screen you have to send the value back so you can check it.

Or

You can use the tinyDB to store if the music is mute, so when you come back to Home Screen you get that value and do the if test.

OK, I did a lot of experimenting with the ‘start value’ idea, and the main problem I encounter is that when I open ‘Screen 2’ for a second time, instead of navigating to the old ‘Screen 2’ I left open, it creates a whole new ‘Screen 2’.
So any values I try to change only affect the second instance of ‘Screen 2’, which means the music keeps playing.

Does the tiny DB solve that problem?

It does but Check this out first!

In both cases you have to switch screens correctly to avoid runtime errors.

I’ve actually used this method with every other screen switch, except with the home screen, in order to keep the music playing.

Could you expand on the Tiny DB proposition?
How can I manipulate values from other screens by using it?

Thanks in advance.

Create a tag in tinyDB to be the variable to check the sound status (e.g. soundOn), and write the value yes or no there before you switch to Settings Screen. Once the tag is set with a value, you can call it from every screen you need it.

OK, I made the tag at Home Screen:
home

And changed the value at settings screen:settings.

But I need an event to trigger the If argument, since the ‘screen’ is already initialized.

Btw is this what you had in mind when mentioning this approach?

I would just set the Player1.start before the if test.

That’s why I prefer to work with arrangements, because this process of checking tag in tinyDB will work if you close every screen you switch even the Home one.

unfortunately my app is pretty code heavy thats why I decided to use multiple screens to make it run smoother.

So, try to close every screen you switch and to continue the audio that was playing in screen 1, store the audio position in tinyDB before you switch screens and use the block seek to in the audio player in the new Screen (you will need one player component in each screen).

Edit: Close even Home Screen

  • Sorry if I can’t help you showing blocks right now, I won’t be able to use my computer until next Monday.

OK, thanks for your help,I guess I’ll give it a few more tries with the old approach, and if none succeeds I’ll go with that way.

1 Like

Would having the ability to Play/Pause the music via a Notification be helpful?
If so check out my MediaStyleNotification Extension here:

1 Like

Unfortunately it doesn’t suit my app UI, but thanks for suggesting.

1 Like

PLEASE don’t tell me tht you have more than 20 Screens??!
:astonished: :astonished: :astonished:

yosh