Android Question mediaplayer.IsInitialized

Discussion in 'Android Questions' started by Sebastjan, May 12, 2015.

  1. Sebastjan

    Sebastjan Member Licensed User

    Hey guys, one question..

    i was writing small mediaplayer procedure for playing small wav mp3 ... files like "tada, bling... etc"
    the idea was when user presses command button it also plays this short - 1 second sound.

    my "player" went into "code module" and it was like this:

    Code:
    Sub PlayFile2(sndFileName As String)
        
    Dim myPlayer As MediaPlayer
        myPlayer .Load(
    File.DirAssets,sndFileName)
        Player.Play
    End Sub
    it worked ok, problem was when user fast pressed button several times, media player stopped working until i restarted a program.

    after some trial and error rewrote my sub like this. (we are still in "code module")

    Code:
    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
        Private Player As MediaPlayer  ' <- player obj
        Private PlayerIni As Boolean    ' <- variable for checking initialization
    End Sub

    Sub PlayFile(sndFileName As String)
        
    If Not(PlayerIni) Then
            PlayerIni=
    True
            Player.Initialize()
        
    End If
        
    If Player.IsPlaying Then
            Player.stop
        
    End If
        Player.Load(
    File.DirAssets,sndFileName)
        Player.Play
    End Sub
    and here is my question: i'm missing "mediaplayer.IsInitialized" property. Did i went wrong about this player? what do you use for playing small "tadaaa" sounds in jour app?

    ps: this is not a game i'm making, just an app for company i work for...
     
  2. hogiebaer

    hogiebaer Active Member Licensed User

    try to initialize the player object in the activity_create (in the firststart section)

    Code:
    Sub Activity_Create(FirstTime As Boolean)
       
    If FirstTime = True Then
          Player.Initialize
       
    end if
    ..
    ..
    End Sub


    Sub PlayFile(sndFileName As String)
      
    If Player.IsPlaying Then Player.stop
      Player.Load(
    File.DirAssets,sndFileName)
      Player.Play
    End Sub
     
    Last edited: May 12, 2015
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