MDP
MDP

Reputation: 4267

My service (for background music) doesn't start

I create a class for playing background music

public class Background_music extends Service {

    MediaPlayer player;
    public IBinder onBind(Intent arg0) {    
        return null;
    }

    @Override
    public void onCreate() {       
        super.onCreate();      
        player = MediaPlayer.create(this, R.raw.background_music);
        player.setLooping(true);        
        player.start();       
    }

    @Override
    public void onStart(Intent intent, int startId) {    
        super.onStart(intent, startId);     
    }

    public  void onStop(){  
        player.stop();
        player.release();
    }


    public void onPause() {  
          player.stop();  
    }

    public void onResume(){
        player.start();
    }

    @Override
    public void onDestroy() {
      player.stop();
      player.release();
    }
}

And in my main class i call the service this way

Intent musica_backGround=new Intent(this, Background_music.class);
startService(musica_backGround);

But the music doesn't start. I Think the problem is that i can't start the service, because even if i try to do other stuff Background_music class, nothing happen

On LogCat i get this message showStatusIcon on inactive InputConnection

Upvotes: 0

Views: 155

Answers (2)

sdabet
sdabet

Reputation: 18670

You need to register your service in the manifest file:

    <service android:name=".Background_music">
        . . .
    </service>

Upvotes: 2

MDP
MDP

Reputation: 4267

The user fiddler remembered me to register my service in the manifest file.

Now it works

Upvotes: 0

Related Questions