E ernschd Active Member Licensed User Longtime User Sep 17, 2013 #1 Hello, i've got two Problems. First, i have an application with an Activity, a MediaPlayer and a Layout "PlayerLayout". I'm calling then MediaPlayer as a service because it should stay active in the background. My Activity: Code: Copy Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("PlayerLayout") If FirstTime Then playerService.MediaPlayer1.Initialize2("MP") End If End Sub Sub MP_Complete ' Play next Song End Sub The Service: Code: Copy Sub Service_Create End Sub Sub Service_Start (StartingIntent As Intent) MediaPlayer1.Play End Sub Sub Service_Destroy MediaPlayer1.Pause End Sub After the Screen is locked, the Event MP_Complete never gets invoked. I wanted to update the Player-GUI with a Timer in the Activity. Do i have to do this out of the Service? Second Problem: i like do implement a Headphone control: Code: Copy Sub Activity_KeyPress (KeyCode As Int) As Boolean If KeyCode = 79 Then ' next Song End If End Sub Is it possible to do this in a Service? Thanks and Regards
Hello, i've got two Problems. First, i have an application with an Activity, a MediaPlayer and a Layout "PlayerLayout". I'm calling then MediaPlayer as a service because it should stay active in the background. My Activity: Code: Copy Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("PlayerLayout") If FirstTime Then playerService.MediaPlayer1.Initialize2("MP") End If End Sub Sub MP_Complete ' Play next Song End Sub The Service: Code: Copy Sub Service_Create End Sub Sub Service_Start (StartingIntent As Intent) MediaPlayer1.Play End Sub Sub Service_Destroy MediaPlayer1.Pause End Sub After the Screen is locked, the Event MP_Complete never gets invoked. I wanted to update the Player-GUI with a Timer in the Activity. Do i have to do this out of the Service? Second Problem: i like do implement a Headphone control: Code: Copy Sub Activity_KeyPress (KeyCode As Int) As Boolean If KeyCode = 79 Then ' next Song End If End Sub Is it possible to do this in a Service? Thanks and Regards
Erel B4X founder Staff member Licensed User Longtime User Sep 18, 2013 #2 You should initialize MediaPlayer in the service and also handle the event in the service. You can use CallSubDelayed to call a sub in the service. Upvote 0
You should initialize MediaPlayer in the service and also handle the event in the service. You can use CallSubDelayed to call a sub in the service.