MediaPlayer setLooping - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for MediaPlayer setLooping method.

This code example shows how to use the following methods:isLooping, isPlaying, pause, seekTo, setLooping
		invokePlay( false ); 
	} 
	 
	private void invokePlay( Boolean loop )
	{ 
		Boolean playing = ( mp.isLooping() || mp.isPlaying() );
		if ( playing )
		{ 
			mp.pause();
			mp.setLooping(loop);
			mp.seekTo(0);
			mp.start();
		} 
		if ( !playing && state == PREPARED )
		{ 
			state = PENDING_LOOP;
			onPrepared( mp );
		} 
		else if ( !playing )
		{ 

9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setLooping
	} 
	 
	void setLoop(boolean bLp){
		if(stream){
			if(player!=null)
				player.setLooping(bLp);
		}else{ 
			if(streamID!=-1) pool.setLoop(streamID, -1);
		} 
		loop = bLp;
	} 
	 
	void setMultiPlay(boolean bMp){
		multiPlay = bMp;
		if(fileName!=null && multiPlay && stream){
			Log.w("OF", "multiplay only supported as no stream, reloading " + fileName + " as no stream");
			String currFileName = fileName;
			unloadSound(); 
			loadSound(currFileName, false);
		} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setLooping, start
	} 
 
	// plays the song once 
	public void play() { 
		if (_state == IDLE || _state == PAUSED) {
			_mediaPlayer.start();
			_state = PLAYING;
 
			_startTime = System.currentTimeMillis();
		} 
	} 
 
	// loops the song infinitely 
	public void loop() { 
		if (_state == IDLE || _state == PAUSED) {
			_mediaPlayer.setLooping(true);
			play(); 
		} 
	} 
	 
	public int getSongLength() { 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:prepare, seekTo, setLooping, start, stop
		 
		if (mBackgroundMediaPlayer == null){
			Log.e(TAG, "playBackgroundMusic: background media player is null");
		} else {		 
			// if the music is playing or paused, stop it 
			mBackgroundMediaPlayer.stop();			
			 
			mBackgroundMediaPlayer.setLooping(isLoop);
			 
			try { 
				mBackgroundMediaPlayer.prepare();
				mBackgroundMediaPlayer.seekTo(0);
				mBackgroundMediaPlayer.start();
				 
				this.mIsPaused = false;
			} catch (Exception e){
				Log.e(TAG, "playBackgroundMusic: error state");
			}			 
		} 
	} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setLooping, start
    //mediaPlayer.release(); 
    //mediaPlayer = null; 
  } 
 
  public void onPrepared(MediaPlayer mp) {
    mediaPlayer.setLooping(loopEnabled);
    mediaPlayer.start();
  } 
} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setLooping
            @Override 
            public void onPrepared(final MediaPlayer mp) {
                // Now VideoView has been laid-out and ready to play, remove background of it to 
                // reveal the video. 
                welcomeVideoView.setBackgroundResource(0);
                mp.setLooping(true);
            } 
        }); 
        welcomeVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            @Override 
            public boolean onError(final MediaPlayer mp, final int what, final int extra) {
                Log.e(TAG, "Playing welcome video causes error: what=" + what + " extra=" + extra);
                hideWelcomeVideoAndShowWelcomeImage(); 
                return true; 
            } 
        }); 
        mWelcomeVideoView = welcomeVideoView;
        mWelcomeImageView = (ImageView)findViewById(R.id.setup_welcome_image);
 
        mActionStart = findViewById(R.id.setup_start_label);
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setLooping, start
		for (int i=0; i<ar.length(); i++) bgmIds[i] = ar.getResourceId(i, 0);
	} 
	void start() { 
		int index = rand.nextInt(bgmIds.length);
		mediaPlayer = MediaPlayer.create(context, bgmIds[index]);
		mediaPlayer.setLooping(true);
		mediaPlayer.start();
	} 
	void stop() { 
		try { 
			mediaPlayer.stop();
		} catch (Exception e) {
			Log.e(TAG, "���f�B�A�v���[���[��stop�Ɏ��s���܂����B", e);
		} finally { 
			mediaPlayer.release();
		} 
	} 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isPlaying, prepare, setAudioStreamType, setDataSource, setLooping
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} 
		} 
		if(!player.isPlaying()) {
            player.start();
        } 
	} 
	//Í£Ö¹ÄÖÁå 
	 public void stopMusic() {    
	        if (player != null) { 
	            player.stop();   
	            try {    
	                // ÔÚµ÷ÓÃstopºóÈç¹ûÐèÒªÔÙ´Îͨ¹ýstart½øÐв¥·Å,ÐèҪ֮ǰµ÷ÓÃprepareº¯Êý    
	                player.prepare();   
	            } catch (IOException ex) {   
	                ex.printStackTrace();   
	            }    
	        } 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setAudioStreamType, setDataSource, setLooping, setOnErrorListener
    vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
    player = createPlayer();
  } 
 
  private MediaPlayer createPlayer() {
    MediaPlayer newPlayer = new MediaPlayer();
    try { 
      Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
      newPlayer.setOnErrorListener(playerErrorListener);
      newPlayer.setDataSource(context, ringtoneUri);
      newPlayer.setLooping(true);
      newPlayer.setAudioStreamType(AudioManager.STREAM_RING);
      return newPlayer;
    } catch (IOException e) {
      Log.e(TAG, "Failed to create player for incoming call ringer");
      return null; 
    } 
  } 
 
  public void start() { 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:prepare, setAudioStreamType, setDataSource, setLooping, start
                Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
 
        if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) {
            mPlayer.setAudioStreamType(silentModeStreams);
        } else { 
            mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
        } 
        try { 
            mPlayer.setDataSource(this, url);
            mPlayer.prepare();
            mPlayer.setLooping(true);
            mPlayer.start();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block 
            e.printStackTrace();
        } catch (SecurityException e) {
            // TODO Auto-generated catch block 
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related MediaPlayer setLooping Questions & Answers:

setLooping Method Overview
Sets the player to be looping or non-looping.
See Code Examples for other Android MediaPlayer Methods: