How to stop a music from a screen on another screen?

Hi everyone!

I’m working on a quiz app and I would like to use 2 differents songs: one for the menus, and one for the quiz; I’m using the Player Component in order to play the songs, I begin to play the first one on the main screen, but bitween the quiz screen and the main screen, there is another screen menu, and I searched for few hours how to change the first song from another screen, and I didn’t succeed…

I tried to use TinyDB to save the song I kept in a list on the main screen in order to stop it on the other screen, but this doesn’t work…
I tried to “get value” the source on the first screen, and tried to find something with the “Play only foreground” option, but nothing too…

Thank you for your help!

There is one block to stop the ongoing music.

While opening another screen use stop player block and open another screen.

1 Like

First set stop player
https://docs.kodular.io/components/media/player/#stop
Second set source to songs 2
https://docs.kodular.io/components/media/player/#source
To end start again the player
https://docs.kodular.io/components/media/player/#start

1 Like

This doesn’t work because the music started from screen1 and I want to stop it from screen2 and start another music for screen3, I know how to stop player when the song started on the same screen, but not on another…

There is another way.Stop the player when you leave screen 1 and add another player in screen2 with the new song you have.And call it to start at screen initialization.

Where should I do that? Because when I do that on screen2, the song from the screen1 doesn’t disappear but the 2nd song come too and I have 2 songs playing at the same time…

BTW, i think this will work.Just close the player while opening another screen.And when screen two initialize, set source to the new sourced you want.And then call the player to start.

I know I can do that, that was what I wanted to do bitween screen2 and screen3, but I want the same song without any cut bitween screen1 and screen2, and change the song on screen3; and doing your method, the song restart from the beginning. :confused:

I tried to pause the song on screen1 when open screen2, and get the value of the source of the screen1Player and use it to play the song where it paused on screen2, but this doesn’t work, the song restart from the beginning…

Okay i understand you now.Here how can you do it:
when you open another screen.instead of opening replace open with a start text whereas the start text is equal to current position block:
https://docs.kodular.io/components/media/player/#current-position
And then when screen one open call the player to start and then use seek to block Player - Kodular Docs to seek to the start value block you will find in the control category.This block will return the current position.So the second player will start playing from the same position.:wink:

Try this:

1 Like

Note: If you close the screens while switching, the sound will stop automatically. However, this does NOT work with Companion, but only with the compiled app (APK).

Thank you Mohamed_Tamer and BodyMindPower for your help!

I have done this but maybe using TinyDB is better!

Screen3

If I don’t close screens when switching, the sound will not stop, but is there any chance to have an issue to keep screens open?

I’m going to try it, and I’m coming back!

Edit: I tested APKs, I tried to switch screen with and without closing the current screen and the result is the same: the sound stop for few milliseconds…

Is it possible to put a sound with foreground option on screen1 and close the screen1 from another screen?
If it is not, I think there is nothing to do, but it is already great!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.