Media Player Looping: Android

I have 3 seconds mp3 file. I want to constantly play this mp3 file by clicking the user pause button. Is there any method for looping a single file and replaying it again until the user stops it.

+46
android android-mediaplayer
Feb 27 '12 at 7:14
source share
3 answers
mMediaPlayer.setLooping(true); 
+83
Feb 27 '12 at 7:30
source share

This is the working code that I used in my project

  if (Flags.notificationReceived) { showAlert(Flags.patientModel); Flags.notificationReceived = false; mp.start(); mp.setLooping(true); vibrate(2000); } 
+1
Nov 17 '16 at 20:41
source share

This works on my projects, host mediaPlayer.setLooping (true); after mediaPlayer.start ();

 public static void PlayAudio(Context c, int id){ mediaPlayer = MediaPlayer.create(c, id); soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC,50); if (!mediaPlayer.isPlaying()) { isPlayingAudio = true; mediaPlayer.start(); mediaPlayer.setLooping(true); } } 

Happy coding

0
Nov 12 '17 at 17:09 on
source share



All Articles