How can I put a song to repeat in an android application?

Andreea picture Andreea · Oct 27, 2012 · Viewed 12k times · Source

I put in background of my android application a song. I don't know how much time the application is open. And I want to put this song to repeat. My code is:

    MediaPlayer mySong;

    mySong = MediaPlayer.create(X_0Activity.this, R.raw.tj);
    mySong.start();

Answer

AnilPatel picture AnilPatel · Apr 6, 2013
Uri mediaUri = createUri(context, R.raw.media); // Audiofile in raw folder
Mediaplayer mPlayer = new MediaPlayer();
mPlayer.setDataSource(context, mediaUri);
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.prepare();

mPlayer.setLooping(true);  // for repeat song 

mPlayer.start();