Android Question MediaPlayer Complete Event not triggering

epiCode

Active Member
Licensed User
Hey !
Somehow, I am unable to get mediaplayer to fire "complete" event.
It stops after playing first audio file.
Would be nice if someone can point out what am I doing wrong here.

My service module code is like this:

Service Module:
#Region  Service Attributes
#StartAtBoot: False
#End Region

Sub Process_Globals
    Private nid As Int = 1
    Private lock As PhoneWakeState
    Private pl As MediaPlayer
   
End Sub

Sub Service_Create
 
    lock.KeepAlive(False)
    pl.Initialize2("mp")
End Sub

Sub Service_Start (StartingIntent As Intent)
    Service.StopAutomaticForeground
End Sub

Public Sub Play
    Service.StartForeground(nid, CreateNotification("Playing music - Radio Paradise"))

    Dim rp As RuntimePermissions
    for xx = 1 to 10                                       'there are 10 mp3 files like 1.mp3, 2.mp3 and so on
    pl.Load(rp.GetSafeDirDefaultExternal("mp3"), xx & ".mp3")
    pl.Play
    next
   
End Sub


Sub mp_Complete
    Log("Playing complete")
End Sub

Public Sub Stop
    pl.stop
    Service.StopForeground(nid)
    lock.ReleaseKeepAlive
End Sub


Sub CreateNotification (Body As String) As Notification
    Dim notification As Notification
    notification.Initialize2(notification.IMPORTANCE_LOW)
    notification.Icon = "icon"
    notification.SetInfo("Playing Audio...", Body, Main)
    Return notification
End Sub

Sub Service_Destroy
    pl.stop
    lock.ReleaseKeepAlive
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
It stops after playing first audio file.
you are loading ONE mp3 and PLAY it. You are NOT setting up a playlist. Don´t know if mediaplayer has a playlist though.

Start with loading ony file and play it. Does the mp_Complete sub raise? If so then load the next track here and call play on it.
 
Upvote 0

epiCode

Active Member
Licensed User
you are loading ONE mp3 and PLAY it. You are NOT setting up a playlist. Don´t know if mediaplayer has a playlist though.

Start with loading ony file and play it. Does the mp_Complete sub raise? If so then load the next track here and call play on it.
Hi DonManfred
Playlist is there in exoplayer but not in Media Player afaik. But I am looping it ten times since files are numerically named.

Complete event does fire when I play just one file outside of the loop.
 
Upvote 0
Top