我正在Android中开发媒体播放器应用程序。这是一个冗长的解释,但请通过它&提出解决方案
应用程序有第一个显示电台列表的屏幕。当用户点击任何这些无线电台时,应用程序进入显示播放,暂停和播放的第二个屏幕。停止控制。第二个屏幕中的活动还启动了准备媒体播放器和播放器的服务。开始播放媒体。现在我有两个要求
有人可以建议最好的方法吗?是否有可用于实现此目的的示例代码?
由于
答案 0 :(得分:1)
要显示状态对话框,请查看从UI活动调用的ProgressDialog。要使服务继续播放,您需要使用startService而不是bindService。
答案 1 :(得分:0)
对于你的第二个问题,我有解决方案。 有两种方法可以做到。
正如您所说的创建一个Activity,它显示播放/暂停媒体控件。各个服务将继续在后台发挥作用。
第二种方式是你可以在你的游戏活动中初始化媒体播放器对象。不要担心你的媒体播放器将继续在后台播放,直到它没有被杀死来自任务经理。 (介意,即使您正在关闭活动,媒体播放器也会继续播放音乐)
第二种方式,进行选择和播放活动 SingleInstance
static MediaPlayer mediaplayer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.radio_play_layout);
//here check for one thing, **mediaplayer is null or not**. If mediaplayer is null than ur activity is **starting** and u need to have data from selection activity that i need to play this station & If your mediaplayer is not null than you are coming from **notification or widget** , put some IntExtra with pendingIntent to verify that you are actually starting activity from notification or widget.
if(mediaplayer!=null && (getIntent.getIntExtra("verifier",0)==786)){
//show ur currently playing stations details and control butttons.becaz activity is started from notification or widget.
}else{
//Initialize your mediaplayer , setlayout & startplaying
}
}