Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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();
like image 598
Andreea Avatar asked Dec 20 '22 14:12

Andreea


2 Answers

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();
like image 135
AnilPatel Avatar answered Jan 10 '23 16:01

AnilPatel


mySong.setLooping(true) // repeat Song

mySong.start(),

And now you are ready with repeat mode on.

like image 30
Jatin Khattar Avatar answered Jan 10 '23 16:01

Jatin Khattar