M mae08 New Member Mar 17, 2019 #1 Hello, can you help me? I badly want to fix it right now because this project should be pass tomorrow morning. I made an lyrics application and then if I press twice the play button of the MediaPlayer, the music will play like a boomerang. What should I do? This is the code I used: Dim Mp As MediaPlayer Dim Pause1 As Button Dim Play1 As Button Dim Stop1 As Button Sub Pause1_Click Mp.Load(File.DirAssets, "BTS - ANPANMAN.mp3") Mp.Pause End Sub Sub Play1_Click Mp.Initialize Mp.Load(File.DirAssets, "BTS - ANPANMAN.mp3") Mp.Play End Sub Sub Stop1_Click Mp.Load(File.DirAssets, "BTS - ANPANMAN.mp3") Mp.Stop End Sub
Hello, can you help me? I badly want to fix it right now because this project should be pass tomorrow morning. I made an lyrics application and then if I press twice the play button of the MediaPlayer, the music will play like a boomerang. What should I do? This is the code I used: Dim Mp As MediaPlayer Dim Pause1 As Button Dim Play1 As Button Dim Stop1 As Button Sub Pause1_Click Mp.Load(File.DirAssets, "BTS - ANPANMAN.mp3") Mp.Pause End Sub Sub Play1_Click Mp.Initialize Mp.Load(File.DirAssets, "BTS - ANPANMAN.mp3") Mp.Play End Sub Sub Stop1_Click Mp.Load(File.DirAssets, "BTS - ANPANMAN.mp3") Mp.Stop End Sub
Erel B4X founder Staff member Licensed User Longtime User Mar 18, 2019 #2 Please use [code]code here...[/code] tags when posting code. I'm sorry but I don't understand the question. Upvote 0
Please use [code]code here...[/code] tags when posting code. I'm sorry but I don't understand the question.
ac9ts Active Member Licensed User Longtime User Mar 18, 2019 #3 It's been awhile since I used MediaPlayer but your boomerang might be because you are reloading the sound file each time a button is pressed. Load the sound file from a different sub and have your buttons do the single task. This is very simplified. Code: Copy Dim Mp As MediaPlayer Dim Pause1 As Button Dim Play1 As Button Dim Stop1 As Button Sub LoadSound Mp.Initialize Mp.Load(File.DirAssets, "BTS - ANPANMAN.mp3") End Sub Sub Pause1_Click Mp.Pause End Sub Sub Play1_Click Mp.Play End Sub Sub Stop1_Click Mp.Stop End Sub Also, if you want to know when the sound file is done playing on its own (not when you press stop), modify LoadSound and add MP_Complete Code: Copy Sub LoadSound MP.Initialize2("MP") Mp.Load(File.DirAssets, "BTS - ANPANMAN.mp3") End Sub Sub MP_Complete ' Do something here like loading the next track, informing the user the track is complete, etc. End Sub Last edited: Mar 18, 2019 Upvote 0
It's been awhile since I used MediaPlayer but your boomerang might be because you are reloading the sound file each time a button is pressed. Load the sound file from a different sub and have your buttons do the single task. This is very simplified. Code: Copy Dim Mp As MediaPlayer Dim Pause1 As Button Dim Play1 As Button Dim Stop1 As Button Sub LoadSound Mp.Initialize Mp.Load(File.DirAssets, "BTS - ANPANMAN.mp3") End Sub Sub Pause1_Click Mp.Pause End Sub Sub Play1_Click Mp.Play End Sub Sub Stop1_Click Mp.Stop End Sub Also, if you want to know when the sound file is done playing on its own (not when you press stop), modify LoadSound and add MP_Complete Code: Copy Sub LoadSound MP.Initialize2("MP") Mp.Load(File.DirAssets, "BTS - ANPANMAN.mp3") End Sub Sub MP_Complete ' Do something here like loading the next track, informing the user the track is complete, etc. End Sub
Harris Expert Licensed User Longtime User Mar 18, 2019 #4 ac9ts said: Sub Play1_Click mp.Pause ' no ill effects if something isn't playing... Mp.Play End Sub Click to expand... If something is playing, it will be stopped. There are much better options than MediaPlayer - like ExoPlayer. Upvote 0
ac9ts said: Sub Play1_Click mp.Pause ' no ill effects if something isn't playing... Mp.Play End Sub Click to expand... If something is playing, it will be stopped. There are much better options than MediaPlayer - like ExoPlayer.
ac9ts Active Member Licensed User Longtime User Mar 19, 2019 #5 Harris said: If something is playing, it will be stopped. There are much better options than MediaPlayer - like ExoPlayer. Click to expand... ExoPlayer is what I use but OP was using MediaPlayer so I answered with MediaPlayer. Upvote 0
Harris said: If something is playing, it will be stopped. There are much better options than MediaPlayer - like ExoPlayer. Click to expand... ExoPlayer is what I use but OP was using MediaPlayer so I answered with MediaPlayer.