I am making a Radio application in Android. I am facing a peculiar problem. I know this could be as easy but just not able to figure out how to do this. I am sure somebody would have faced a similar problem earlier and I will get a solution here
I have a first page that displays the list of stations. Once I click on any of these stations, a new Activity is started that has a View that has Play, Pause, Stop controls. When this activity is started, I also immediately invoke a new Service using startSevice()
method. All the media player handling is done in this Service.
Now, I have a requirement of showing a Progress Dialog (Buffering) before the actual Media play starts. To show that I am trying to create a ProgressDialog in the Service, but it is asking for a context to be passed, I suppose I need to pass the Context of the activity that has invoked this service, because when I pass the current Context to it, it throws an Error.
How to achieve this? Is there a way to get hold of the Context of the Activity that started the Service?
If not, what could be some other way to achieve this, that is showing the Buffering status while the Media has not started playing
Use Broadcast intents. Bind the service to the activity and broadcast the buffering progress at 1 second intervals to the activity. Create a receiver in the activity that receives the broadcast and translates it to the progress bar in the activity.
I have a question maybe you can answer: I'm streaming using a service, just the way you are, but when the buffering first starts, I'm not clear on how to capture when the audio starts playing so that I can remove the "buffering" notification. I tried OnBufferingUpdate but that has a percentage value the whether the audio is playing or not. Thanks.