B Brian Dean Well-Known Member Licensed User Longtime User Apr 21, 2020 #1 I used the example given here to build a media-player service, although I did not really understand why it worked. But it works very well - so well that I cannot find a way to stop it when I want to. I have also read this post which might or might not be relevant, and again I don't really understand it. I have tried using Service.StopForeground and StopService(Me) but that has the opposite effect; I get multiple instances like some mythological monster that grows two heads for every one you cut off. So, having started a persistent foreground service, how do I stop it?
I used the example given here to build a media-player service, although I did not really understand why it worked. But it works very well - so well that I cannot find a way to stop it when I want to. I have also read this post which might or might not be relevant, and again I don't really understand it. I have tried using Service.StopForeground and StopService(Me) but that has the opposite effect; I get multiple instances like some mythological monster that grows two heads for every one you cut off. So, having started a persistent foreground service, how do I stop it?
ac9ts Active Member Licensed User Longtime User Apr 21, 2020 #2 Have you tried using StopService from the same activity that you started the service from? Upvote 0
B Brian Dean Well-Known Member Licensed User Longtime User Apr 21, 2020 #3 @ac9ts - Well, I have just tried what you suggest. Service Destroy runs, but other than that it doesn't even blink - just goes on playing. Upvote 0
@ac9ts - Well, I have just tried what you suggest. Service Destroy runs, but other than that it doesn't even blink - just goes on playing.
B Brian Dean Well-Known Member Licensed User Longtime User Apr 21, 2020 #4 @ac9ts : What you said might have given me a clue. I am not sure where the Service is getting started; that is the problem when you don't really understand what you are doing. I will take a another look and maybe re-post with some sample code if I cannot make sense of it. Thanks for your suggestion. Upvote 0
@ac9ts : What you said might have given me a clue. I am not sure where the Service is getting started; that is the problem when you don't really understand what you are doing. I will take a another look and maybe re-post with some sample code if I cannot make sense of it. Thanks for your suggestion.
ac9ts Active Member Licensed User Longtime User Apr 21, 2020 #5 Try stopping and releasing the player in the Service_Destroy sub Upload the project (File -> Export as Zip) for us to take a look at what's what. Upvote 0
Try stopping and releasing the player in the Service_Destroy sub Upload the project (File -> Export as Zip) for us to take a look at what's what.
B Brian Dean Well-Known Member Licensed User Longtime User Apr 23, 2020 #6 I attach a modified form of my project. It runs from the Assets file so it will run on any device - it doesn't have to scan for mp3 files. I have disabled the id3 tag reader so the the app looks a bit bare but it still illustrates my problem. Question : How should I stop the player from within the app? I have left in one of my attempts : B4X: Copy Public Sub stop Service.StopForeground(id) StopService(Me) End Sub Rather than stop the Player service this seems to create yet another instance, which is quite bizarre. This app is just for my own education, so not important, but any guidance would be appreciated. Attachments MP3Player.zip MP3Player.zip 36 KB · Views: 419 Upvote 0
I attach a modified form of my project. It runs from the Assets file so it will run on any device - it doesn't have to scan for mp3 files. I have disabled the id3 tag reader so the the app looks a bit bare but it still illustrates my problem. Question : How should I stop the player from within the app? I have left in one of my attempts : B4X: Copy Public Sub stop Service.StopForeground(id) StopService(Me) End Sub Rather than stop the Player service this seems to create yet another instance, which is quite bizarre. This app is just for my own education, so not important, but any guidance would be appreciated.
Erel B4X founder Staff member Licensed User Longtime User Apr 23, 2020 #7 Stopping the service will not stop the MediaPlayer. You need to explicitly stop it. Upvote 0
B Brian Dean Well-Known Member Licensed User Longtime User Apr 23, 2020 #8 Thanks - I will do that. Upvote 0