How to stop audio when pressing button

sailorbrnk

New Member
Licensed User
Longtime User
Hi. I have the following code to start my audio, which works great.

Dim sounds As MediaPlayer
sounds.Initialize
sounds.Load(File.DirAssets, "correct.mp3")
sounds.Play

However, I want the audio to STOP when I press a button, to switch to a new function in my App. I've tried numerous things, but I just can't get it to stop playing the audio.

Also, when numerous sounds play every few seconds, after about 10 instances, the audio completely stops altogether, and I can no longer hear audio. The stop ability is most important for a response, but if you can fix the other issue, that would be great also.:sign0085:
 

yttrium

Active Member
Licensed User
Longtime User
Does this not work?

B4X:
Dim sounds As MediaPlayer
sounds.Initialize
sounds.Load(File.DirAssets, "correct.mp3")
sounds.Play
'do whatever
sounds.Stop
sounds.Release
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If you are using a lot of relatively short sound files, it would be better to use soundpool.

-------------------
Sent via Tapatalk
 
Upvote 0
Top