Android Question MediaPlayer

Discussion in 'Android Questions' started by mae08, Mar 17, 2019.

  1. mae08

    mae08 New Member

    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.

    I'm sorry but I don't understand the question.
     
  3. ac9ts

    ac9ts Active Member Licensed User

    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:
    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:
    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
  4. Harris

    Harris Well-Known Member Licensed User

    If something is playing, it will be stopped.
    There are much better options than MediaPlayer - like ExoPlayer.
     
  5. ac9ts

    ac9ts Active Member Licensed User

    ExoPlayer is what I use but OP was using MediaPlayer so I answered with MediaPlayer.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice