Android Question media player not working as expected

Discussion in 'Android Questions' started by rleiman, Jul 10, 2015.

  1. rleiman

    rleiman Well-Known Member Licensed User

    Hi Everyone,

    Please look at my coding. I have 2 media players set up but they are not working as expected. Initially I have a select statement set that catches when the time is 5 and 10 minutes past the hour and also on the hour. On the hour, I'm trying to get one media player to play a sound file and have the other player play another sound file only when the first one has finished playing it's sound file. This problem does not occur when only the 5 and 10 minute sound files are play since no other sound file is played afterwards.

    On the hour one sound file gets played and when the code reaches the play statement on the other media player the first media player repeats the sound file that was loaded into it then the second media player plays it's sound file.

    The problem occurs when this statement is executed:

    Code:
    mpHourlyMediaPlayer.Play
    As you can see, there is no other code that plays the first sound file.

    What am I doing wrong?

    Here's the coding:

    Code:
    Sub Service_Create
        
    ToastMessageShow"Sounds Enabled",False)

        blnOkToSound = 
    True

        
    ' Set up the media players.
        '--------------------------
        mpMinutesMediaPlayer.Initialize2("MinutesMediaPlayer")
        mpHourlyMediaPlayer.Initialize

        
    ' Start the timer.
        '-----------------
        tmrTimer.Initialize("EventTimer"1000)
        tmrTimer.Enabled = 
    True
    End Sub
    Code:
    Sub EventTimer_Tick   
        lngTheTimeNow = 
    DateTime.Now
        intHours = 
    DateTime.GetHour(lngTheTimeNow)
        intMinutes = 
    DateTime.GetMinute(lngTheTimeNow)
        intSeconds = 
    DateTime.GetSecond(lngTheTimeNow)
           
        
    Select intMinutes

            
    Case 5
                
    If mpMinutesMediaPlayer.IsPlaying = False _
                
    And intSeconds = 0 Then
                    mpMinutesMediaPlayer.Load(
    File.DirAssets,"5Minutes.mp3")
                    mpMinutesMediaPlayer.Play
                
    End If

            
    Case 10
                
    If mpMinutesMediaPlayer.IsPlaying = False _
                
    And intSeconds = 0 Then
                    mpMinutesMediaPlayer.Load(
    File.DirAssets,"10Minutes.mp3")
                    mpMinutesMediaPlayer.Play
                
    End If

            
    Case 0
                
    If mpMinutesMediaPlayer.IsPlaying = False _
                
    And intSeconds = 0 Then
                    mpMinutesMediaPlayer.Load(
    File.DirAssets,"hourly.mp3")
                    mpMinutesMediaPlayer.Play

                    blnOnTheHour = 
    True
                
    End If
               
        
    End Select ' intMinutes   
    End Sub
    Code:
    Sub MinutesMediaPlayer_Complete

        
    If blnOnTheHour = True Then
            PlayHourlySounds
           
            blnOnTheHour = 
    False
        
    End If
    Code:
    Sub PlayHourlySounds

        
    Select intHours
       
            
    Case 113
                
    If mpHourlyMediaPlayer.IsPlaying = False Then
                    mpHourlyMediaPlayer.Load(
    File.DirAssets, "1oclock.mp3")
                    mpHourlyMediaPlayer.Play
                
    End If
       
            
    Case 214
                
    If mpHourlyMediaPlayer.IsPlaying = False Then
                    mpHourlyMediaPlayer.Load(
    File.DirAssets, "2oclock.mp3")
                    mpHourlyMediaPlayer.Play
                
    End If
       
        
    End Select
     
  2. rleiman

    rleiman Well-Known Member Licensed User

    Looks like we may just use Audacity to string together the sound files into a single file to avoid the issue since I know playing a single sound file works.
     
  3. klaus

    klaus Expert Licensed User

    As you play only one file at the same time, why not using the same MediaPlayer ?
     
  4. rleiman

    rleiman Well-Known Member Licensed User

    Hi Klaus,

    We tried that as well. Since it didn't work, we used Audacity to string together two sound files and played it as one file that had the parts we played separately. We did that for all of the 2 part files.
     
  5. klaus

    klaus Expert Licensed User

    What didn't work ?
    I am estonished because I wrote a 'JukeBox' program where I play a next file at the end of the previous one in MediaPlayer_Complete.
     
  6. rleiman

    rleiman Well-Known Member Licensed User

    Hi,

    Just playing one followed by the other didn't work so we just made single files to play. Next time when we have more time we will try to do it again to see where it went wrong.
     
Loading...