开发者

Player widget over several activities

开发者 https://www.devze.com 2023-04-01 00:41 出处:网络
working on a podcast app I\'m currently thinking how to implement a small player (which includes a progressbar for current time playing, play, pause, rewind and forward button) which开发者_开发知识库

working on a podcast app I'm currently thinking how to implement a small player (which includes a progressbar for current time playing, play, pause, rewind and forward button) which开发者_开发知识库 will be displayed in several activities through my app. For playing podcasts in the background I've already implemented a Service which takes care of the MediaPlayer and the currently played podcast.

What is the best method for updating a small player over several activities and be able to pause and move the currently played podcast?

Thanks in advance.


You're on the right track. Every Activity that can control or see the mediaplayer should bind to the running service. If you implement the Observer design pattern in your service. Then you can make direct calls to the service and perform callbacks from the service to your activity.

Please make sure you play your audio/video in the background in a seperate thread because a service and an activity run in the same thread.

For your progressbar i should implement a callback function like progress(int secondsFromStart, int totalTimeSeconds) that will be called immediately after binding the service. Then the UI could update it's progressbar until it reaches totalTimeSeconds or shenever some kind of pauze call was received from the service.


If you want to use the same Player widget in several activities, then you should try Fragments API. That will alow you to compose complex UI. All your Activities will become Fragments with minor changes in code.

0

精彩评论

暂无评论...
验证码 换一张
取 消