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

This code example shows how to use the following methods:setOnCompletionListener
	public void seekTo(final int pMilliseconds) {
		this.mMediaPlayer.seekTo(pMilliseconds);
	} 
 
	public void setOnCompletionListener(final OnCompletionListener pOnCompletionListener) {
		this.mMediaPlayer.setOnCompletionListener(pOnCompletionListener);
	} 
 
	// =========================================================== 
	// Inner and Anonymous Classes 
	// =========================================================== 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setOnCompletionListener
 
	private MediaPlayer mPlayer;
	private String mFilePath;
	 
	public VoicePlayer() { 
		mPlayer = new MediaPlayer();
		mPlayer.setOnCompletionListener(this);
		mFilePath = Environment.getExternalStorageDirectory().toString() + "/RecordVoice/testVoice.3gp";
	} 
	 
	public void play() { 
		// TODO Auto-generated method stub 
		try { 
			mPlayer.setDataSource(mFilePath);
			mPlayer.prepare();
			mPlayer.start();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setOnCompletionListener
 
	private MediaPlayer mPlayer;
	private String mFilePath;
	 
	public VoicePlayer() { 
		mPlayer = new MediaPlayer();
		mPlayer.setOnCompletionListener(this);
		mFilePath = Environment.getExternalStorageDirectory().toString() + "/RecordVoice/testVoice.3gp";
	} 
	 
	public void play() { 
		// TODO Auto-generated method stub 
		try { 
			mPlayer.setDataSource(mFilePath);
			mPlayer.prepare();
			mPlayer.start();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setOnCompletionListener
	} 
 
	// passes in a callback that is called when the song ends 
	public void setOnCompletionListener(final OnCompletionListener listener) {
		if (_state != RELEASED) {
			_mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
				@Override 
				public void onCompletion(MediaPlayer mp) {
					listener.onCompletion(MusicPlayer.this);
				} 
			}); 
		} 
	} 
 
	public int getCurrentPosition() { 
		if (_startTime == 0) {
			return -1; 
		} 
		return (int) (System.currentTimeMillis() - _startTime);
	} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setOnCompletionListener
		} 
		return SingletonHolder.instance;
	} 
 
	private VoicePlayer() { 
		mediaPlayer = new MediaPlayer();
		mediaPlayer.setOnCompletionListener(listener);
	} 
 
	public void playVoice(String wordName, Context context) {
		String filePath = Environment.getExternalStorageDirectory().getPath()
				+ "/GREWords/voices/" + wordName + ".mp3";
		mediaPlayer = MediaPlayer.create(context, Uri.parse(filePath));
		mediaPlayer.start();
	} 
 
	private OnCompletionListener listener = new OnCompletionListener() {
 
		@Override 
		public void onCompletion(MediaPlayer mp) { 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setOnCompletionListener, setOnErrorListener
	@Override 
	public void onCreate() 
	{ 
		super.onCreate(); 
		Log.i(TAG,"onCreate()");
		player = new MediaPlayer();
		setupPlayerListeners(); 
	} 
	 
	private void setupPlayerListeners() 
	{ 
		if(player != null)
		{ 
			player.setOnCompletionListener(new OnCompletionListener() {
 
				@Override 
				public void onCompletion(MediaPlayer mp) {
					Log.i(TAG,"onCompletion called");
					 
				} }); 

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setOnCompletionListener
	public void destroy() { 
		this.player.release();
	} 
 
	public void setCompletionListener(OnCompletionListener listener) {
		this.player.setOnCompletionListener(listener);
	} 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setOnCompletionListener
	private MediaPlayer mPlayer;
	private String mFilePath;	//ファイルパス
 
	public VoicePlayer() { 
		// インスタンスの取得 
        mPlayer = new MediaPlayer();
        // Listenerの登録必要です 
        mPlayer.setOnCompletionListener(this);
		// SDカードのディレクトリ 
		mFilePath = Environment.getExternalStorageDirectory().toString()
    				+ "/RecordVoice/testVoice.3gp"; 
	} 
	 
	//音声ファイル再生 
	public void play() { 
        try { 
            mPlayer.setDataSource(mFilePath);
            // 準備して 
            mPlayer.prepare();
            // 再生スタート! 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:prepareAsync, setAudioStreamType, setDataSource, setOnCompletionListener, setOnPreparedListener
    start(); 
  } 
 
  private void start() { 
    if( mediaPlayer != null ) mediaPlayer.release();
    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnPreparedListener(this);
 
    String packageName = context.getPackageName();
    Uri dataUri = Uri.parse("android.resource://"+ packageName +"/"+ currentSoundID );
 
    try { 
      mediaPlayer.setDataSource(context, dataUri);
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block 
      e.printStackTrace();
      return; 
    } catch (SecurityException e) {

10
CodeRank
Experience pair programming with AI  Get Codota for Java

Related MediaPlayer setOnCompletionListener Questions & Answers:

Other MediaPlayer setOnCompletionListener Examples

141:				mp = MediaPlayer.create(MainActivity.this, R.raw.light_switch_on);
142:			}
143:			mp.setOnCompletionListener(new OnCompletionListener() {
144:	
145:	            @Override

Read More

70:			songProgressBar.setOnSeekBarChangeListener(this); // Important
71:			mp.setOnCompletionListener(this); // Important
72:	
73:			// Getting all songs list
74:			songsList = songManager.getPlayList();

Read More

setOnCompletionListener Method Overview
Register a callback to be invoked when the end of a media source has been reached during playback.
See Code Examples for other Android MediaPlayer Methods: