Okey, this is my problem. I have one service class where Ive managed to create media player to play music in background all time. Here is code:
package com.test.brzoracunanje;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
public class BackgroundSoundService extends Service {
private static final String TAG = null;
MediaPlayer player;
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
player = MediaPlayer.create(this, R.raw.test_cbr);
player.setLooping(true); // Set looping
player.setVolume(100,100);
player.start();
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
}
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
protected void onNewIntent() {
player.pause();
}
}
But now I have problem when I click on HOME
, or BACK
button. It still plays music. Does anyone knows how to solve that problem?
And here is code how i call this service on class where I want to play music;
Intent svc=new Intent(this, BackgroundSoundService.class);
startService(svc);