Android的背景音乐服务 [英] Android background music service
本文介绍了Android的背景音乐服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在开发Android的娱乐应用程序。我想播放背景音乐,而我想用服务的。应用程序有3个活动和音乐必须在所有的活动中播放。此外,当活动被暂停,音乐必须暂停并销毁时,停了下来。谁能告诉我如何做到这一点?任何链接或例子?
I am developing an entertainment app in android. I want to play background music, and I want to use service for that. App have 3 activities and music must be played across all activities. Also, when activity is paused, music must PAUSE and stopped when destroyed. Can anyone tell me how to do this ? any links or examples ?
感谢您。
推荐答案
做没有服务
<一个href="http://www.rbgrn.net/content/307-light-racer-20-days-61-64-completion">http://www.rbgrn.net/content/307-light-racer-20-days-61-64-completion
如果你正如此严重的与服务做使用媒体播放器
If you are so serious about doing it with services using mediaplayer
Intent svc=new Intent(this, BackgroundSoundService.class);
startService(svc);
public class BackgroundSoundService extends Service {
private static final String TAG = null;
MediaPlayer player;
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
player = MediaPlayer.create(this, R.raw.idil);
player.setLooping(true); // Set looping
player.setVolume(100,100);
}
public int onStartCommand(Intent intent, int flags, int startId) {
player.start();
return 1;
}
public void onStart(Intent intent, int startId) {
// TO DO
}
public IBinder onUnBind(Intent arg0) {
// TO DO Auto-generated method
return null;
}
public void onStop() {
}
public void onPause() {
}
@Override
public void onDestroy() {
player.stop();
player.release();
}
@Override
public void onLowMemory() {
}
}
这篇关于Android的背景音乐服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文