How do I initialize sound only once?

Hello guys im trying to make a sound that play only when we open an app

the idea is to make when app is open which basically means Screen1 is operating,im using when Screen1 is initialize the sound will be played

image

however the problem is when i have multiple screen which leads to another screen and when close it will back to screen1 which make the sound to play again and again each time i close a screen :sweat_smile: :sweat_smile:


each button leads to other screen and when close will back to Screen1

image

i did think about making virtual screen .However ,i really need to use multiple screen.Is there any solution to this problem,thanks alot :smiley:

really ?

To fix your sound play issue, use a variable to set a flag which is tested. When app first opened play the sound, after that do not. reset the flag when you close the app.

thanks for answering, but do u have example regarding the method that u suggested :blush:

No, this should not happen unless you close Screen1, as Screen1 will not be reinitialized. So show all (relevant) blocks.

1 Like

Not tested but something like this:

1 Like

to make it easier i will share aia project file

initialize_sound.aia (98.0 KB)

this happens only in the companion app, but not after building the app...
notes taken from here App Inventor Tutorials | Pura Vida Apps

Current limitations of the AI Companion app:

  1. The close screen block triggers the Initialize event instead of the OtherScreenClosed event.
  2. The close screen with value block triggers both the Initialize and OtherScreenClosed events instead of only the OtherScreenClosed event.
  3. The close application block does not work, a message 'Closing forms is not currently supported during development' will be displayed instead.

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

i did compile the apps and the issue still occur

I just tested your app...

  1. in the companion app I get this message (on Samsung A51 running Android 11)
    I currently do not know, why that happens...

  2. and after building the app I get the drum sound only after opening the app and not anymore after coming back from another screen... (which means as I said earlier)
    here is the apk to download https://drive.google.com/file/d/1jTOaCthttnp4B6x1wPE_s_Q9OrcDPQAE/view?usp=sharing

Taifun

1 Like

yes the apk work well !i will recheck my other apps that have the same issue hopefully it will work just fine,,thanks

Yes it should be like that. But try this app (build the APK and test it).
initialize_sound2.aia (134.2 KB)

After e.g. Screen2 is closed and you return to Screen1, Sound2 (in my test app: clock.mp3) is triggered again for a few milliseconds (of course that doesn't happen to the Player component). Therefore there is a bug here.

1 Like

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