Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Media Player Looping : Android

I am having 3 secs of mp3 file. I want to play that mp3 file continuously still the user click pause button. Is there any method to loop the single file and play it again again till user pauses it.

like image 664
Dray Avatar asked Feb 27 '12 07:02

Dray


People also ask

How do I reset my MediaPlayer on Android?

Just use pause to stop, followed by seekTo(0) before restarting: mediaPlayer. seekTo(0); mediaPlayer.

What is a method for MediaPlayer in Android?

Android is providing MediaPlayer class to access built-in mediaplayer services like playing audio,video e.t.c. In order to use MediaPlayer, we have to call a static Method create() of this class. This method returns an instance of MediaPlayer class. Its syntax is as follows − MediaPlayer mediaPlayer = MediaPlayer.


3 Answers

mMediaPlayer.setLooping(true); 
like image 163
Sandeep P Avatar answered Oct 13 '22 08:10

Sandeep P


This is working on my projects, place 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

like image 45
Supriyanto Avatar answered Oct 13 '22 10:10

Supriyanto


This is a working code that i used in my project

 if (Flags.notificationReceived) {
                        showAlert(Flags.patientModel);
                        Flags.notificationReceived = false;
                        mp.start();
                        mp.setLooping(true);
                        vibrate(2000);
                    }
like image 37
Jeffy Avatar answered Oct 13 '22 09:10

Jeffy