MediaPlayer start - 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 start method.

This code example shows how to use the following methods:start
		if(stream){
			if(player==null) return;
			if(bP)
				player.pause();
			else 
				player.start();
		}else if(streamID!=-1){
			if(bP){
				pool.pause(streamID);
			}else{ 
				pool.resume(streamID);
			} 
			bIsPlaying = !bP;
		} 
	} 
	 
	void setLoop(boolean bLp){
		if(stream){
			if(player!=null)
				player.setLooping(bLp);
7
CodeRank
This code example shows how to use the following methods:start
     * android.media.MediaPlayer.OnPreparedListener#onPrepared(android.media 
     * .MediaPlayer) 
     */ 
    public void onPrepared(MediaPlayer mediaplayer) {
        if (mp != null) {
            mp.start();
        } 
    } 
 
    /* 
     * (non-Javadoc) 
     *  
     * @see 
     * android.media.MediaPlayer.OnCompletionListener#onCompletion(android.media 
     * .MediaPlayer) 
     */ 
    public void onCompletion(MediaPlayer mediaplayer) {
        Timer endSound = new Timer();
        endSound.schedule(new TimerTask() {
            public void run() { 
8
CodeRank
This code example shows how to use the following methods:start
	@Override 
	public void show() { 
		super.show(); 
		 
		if(isSound){
			mPlayer.start();
		} 
	} 
	 
	/** 
	 * 设置是否播放声音 
	 */ 
	public void setIsSound(boolean isSound) {
		this.isSound = isSound;
	} 
	 
	/** 
	 * 获取控件实例 
	 * @param context 
	 * @param text 提示消息 
8
CodeRank
This code example shows how to use the following methods:seekTo, setLooping, start
			mp.start();
			state = PLAYING;
		} 
		else if ( state == PENDING_LOOP )
		{ 
			mp.setLooping(true);
			mp.seekTo(0);
			mp.start();
			state = LOOPING;
		} 
		else 
		{ 
			state = PREPARED;
			mp.seekTo(0);
		} 
	} 
	 
	public void onCompletion(MediaPlayer mPlayer)
	{ 
		if (state != LOOPING)
10
CodeRank
This code example shows how to use the following methods:prepare, seekTo, start, stop
		} 
	} 
	 
	public void rewindBackgroundMusic(){		 
		if (mBackgroundMediaPlayer != null){
			mBackgroundMediaPlayer.stop();			
			 
			try { 
				mBackgroundMediaPlayer.prepare();
				mBackgroundMediaPlayer.seekTo(0);
				mBackgroundMediaPlayer.start();
				 
				this.mIsPaused = false;
			} catch (Exception e){
				Log.e(TAG, "rewindBackgroundMusic: error state");
			}			 
		} 
	} 
	 
	public boolean isBackgroundMusicPlaying(){ 
7
CodeRank
This code example shows how to use the following methods:isPlaying, prepare, setAudioStreamType, setDataSource, start
    public boolean isActive() { 
        return false; 
    } 
 
    public boolean isRunning() { 
        return player != null && player.isPlaying();
    } 
 
    public void start() { 
        if (!isOpen()) { 
            throw new IllegalStateException("Clip must be open");
        } 
         
        if (stream == null) {
            throw new IllegalStateException("Need an AudioInputStream to play");
        } 
 
        if (!isRunning()) { 
            /* 
             * This is ugly, but there is no way around it: The javax.sound API 

7
CodeRank
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
This code example shows how to use the following methods:start
         
        public void onPrepared(MediaPlayer mp) {
            mAudioSrvState = PLAYING;
            Time duration = new Time(mp.getDuration());
            Log.v(TAG, "Prepared mediaplayer for track of duration =["+duration+"]");
            mMediaPlayer.start();
        } 
         
        public void onBufferingUpdate(MediaPlayer mp, int percent) {
            Log.v(TAG, "Buffered additional=["+percent+"%]");
            mAudioSrvState = BUFFERING;
        } 
         
        public void onCompletion(MediaPlayer mp) {
            Log.i(TAG, "Completed playback");
            mMediaPlayer.stop();
            mMediaPlayer.reset();
            mAudioSrvState = NOT_PLAYING;
        } 
         
8
CodeRank
This code example shows how to use the following methods:setOnBufferingUpdateListener, setOnCompletionListener, start
		return duration;
	} 
 
	public void onPrepared(MediaPlayer mPlayer) {
		if (isPlaying) {
			mPlayer.setOnCompletionListener(this);
			mPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener()
			{ 
				public void onBufferingUpdate(MediaPlayer mPlayer, int percent)
				{ 
					/* TODO: call back, e.g. update outer progress bar */ 
					Log.d("AudioOnBufferingUpdate", "percent: " + percent); 
				} 
			}); 
			mPlayer.start();
		} 
	} 
 
	public boolean onError(MediaPlayer mPlayer, int arg1, int arg2) {
		Log.e("AUDIO onError", "error " + arg1 + " " + arg2);
8
CodeRank
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

Related MediaPlayer start Questions & Answers:

Other MediaPlayer start Examples

149:	            }
150:	        }); 
151:			mp.start();
152:		}
153:

Read More

97:						if(mp!=null){
98:							mp.start();
99:							// Changing button image to pause button
100:							btnPlay.setImageResource(R.drawable.btn_pause);
101:						}
-
238:	
239:			/**
240:			 * Button Click event for Play list click event
241:			 * Launches list activity which displays list of songs
242:			 * */

Read More

start Method Overview
Starts or resumes playback.
See Code Examples for other Android MediaPlayer Methods: