Android 中的媒体播放器要求
我正在 Android 中开发一个媒体播放器应用程序。解释有点冗长,但请仔细阅读并阅读它。建议解决方案
该应用程序的第一个屏幕显示广播电台列表。当用户单击这些广播电台中的任何一个时,应用程序将转到第二个屏幕,显示播放、暂停和广播。停止控制。第二个屏幕中的活动还会启动一项准备媒体播放器和媒体播放器的服务。开始播放媒体。现在我有两个要求
- ,我想在媒体尚未开始播放时显示进度状态。它应该显示在第二个屏幕的顶部媒体开始播放后应该会消失。我该怎么做?是在启动服务的 Activity 中还是在 Service 本身中执行某些操作?
- 现在,当媒体正在播放时,我想通过按后退按钮返回到第一个屏幕(或者可能退出应用程序)。但是音乐应该继续播放,除非我从第一个屏幕选择其他广播电台(新音乐将开始),或者从通知面板和应用程序返回到应用程序。然后停止音乐。
有人可以建议最好的方法吗?是否有任何示例代码可以实现此目的?
谢谢
I am developing a media player application in Android. Its a bit of a lengthy explanation, but please go through it & suggest a solution
The application has a first screen that displays a list of radio stations. When the user clicks on any of these radio stations, the application goes to the second screen that displays the play, pause & stop controls. The activity in the second screen also initiates a service that prepares the Media Player & starts playing the media. Now I have two requirements
- I want to show a progress status while the media has not started playing. It should be shown on top of the second screen & should disappear once the media has started playing. How do I do that? Is something is to be done in the Activity that started the service or in the Service itself?
- Now when the media is playing, I want to go back to the first screen by pressing the back button(or may be exit the application). But the music should keep on playing unless I select some other radio station form the first screen(new music will start), or come back to the application from the notification panel & then stop the music.
Can someone suggest the best way to do this? Are there any sample codes available to achieve this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要显示状态对话框,请查看从 UI 活动调用的 ProgressDialog。要使服务继续播放,您需要使用startService而不是bindService。
服务生命周期参考
To show a status dialog, look into ProgressDialog called from your UI activity. To cause a service to continue playing, you need to use startService rather than bindService.
Service lifecycle reference
对于你的第二个问题,我有解决方案。
有两种方法可以做到这一点。
正如您所说,创建一个活动,它显示播放/暂停媒体控件。相应的服务将继续在后台运行。
第二种方法是您可以在播放活动中初始化媒体播放器对象。不用担心您的媒体播放器将继续在后台播放,直到它没有被任务管理器杀死。 (请注意,即使您关闭活动,媒体播放器也会继续播放音乐)
对于第二种方式,使您的选择和播放活动都SingleInstance
For your second Question , i have solution .
There are two ways to do it .
As you are telling create one Activity ,which shows play/pause media controls. And Respective Service will continue to play in Background.
Second way is that u can initialize mediaplayer object in your playing activity.Don't worry your mediaplayer will continue to play in background untill and unless it has not been killed from task manager. (Mind it , mediaplayer will continue to play music even if you are closing the activity)
For second way , make your both selection and playing activity SingleInstance