对于您的第二个问题,我有解决方案。有两种方法可以做到这一点。
正如您所说,创建一个 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
}
}