Do it without service
http://www.rbgrn.net/content/307-light-racer-20-days-61-64-completion
If you are so serious about doing it with services using media player
1 2 |
Intent svc=new Intent(this, BackgroundSoundService.class); startService(svc); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
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() { } } |
Please call this service in Manifest
1 |
<service android:enabled="true" android:name=".BackgroundSoundService " /> |