android.media.MediaPlayer.OnCompletionListener Java Examples

The following examples show how to use android.media.MediaPlayer.OnCompletionListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Utilities.java    From Multiwii-Remote with Apache License 2.0 6 votes vote down vote up
public static void playNotification(Activity myActivity) {
	Uri defaultRingtoneUri = RingtoneManager
			.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
	try {
		MediaPlayer mediaPlayer = new MediaPlayer();
		mediaPlayer.setDataSource(myActivity.getBaseContext(),
				defaultRingtoneUri);
		mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
		mediaPlayer.prepare();
		mediaPlayer.setOnCompletionListener(new OnCompletionListener() {

			public void onCompletion(MediaPlayer mp) {
				mp.release();
			}

		});
		mediaPlayer.start();

	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #2
Source File: RedPacketDialog.java    From letv with Apache License 2.0 6 votes vote down vote up
private void soundShake() {
    try {
        this.mPlayer = MediaPlayer.create(RedPacketSdkManager.getInstance().getApplicationContext(), R.raw.shake_sound);
        if (this.mPlayer != null) {
            this.mPlayer.start();
            this.mPlayer.setOnCompletionListener(new OnCompletionListener() {
                public void onCompletion(MediaPlayer mp) {
                    RedPacketDialog.this.mPlayer.release();
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
        if (this.mPlayer != null) {
            this.mPlayer.release();
        }
    }
}
 
Example #3
Source File: ReceiverSelector.java    From media-button-router with Apache License 2.0 6 votes vote down vote up
/**
 * Takes appropriate action to notify user and dismiss activity on timeout.
 */
private void onTimeout() {
    Log.d(TAG, "Media Button Selector: Timed out waiting for user interaction, finishing activity");
    final MediaPlayer timeoutPlayer = MediaPlayer.create(this, R.raw.dismiss);
    timeoutPlayer.start();
    // not having an on error listener results in on completion listener
    // being called anyway
    timeoutPlayer.setOnCompletionListener(new OnCompletionListener() {

        public void onCompletion(MediaPlayer mp) {
            timeoutPlayer.release();
        }
    });

    // If the user has set their preference not to confirm actions, we'll
    // just forward automatically to whoever was last selected. If no one is
    // selected, it just acts like finish anyway.
    if (preferences.getBoolean(Constants.CONFIRM_ACTION_PREF_KEY, true)) {
        finish();
    } else {
        select();
    }
}
 
Example #4
Source File: ODKSeekBar.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
public void reInit(java.io.File recordingFile, final OnCompletionListener ocl) {
	mr.reset();
	this.recordingFile.delete();
	
	initMediaRecorder();
	init(recordingFile, ocl);
}
 
Example #5
Source File: SoundEffectPlayer.java    From CuXtomCam with Apache License 2.0 5 votes vote down vote up
private MediaPlayer createSoundEffect(Context ctx, int resource) {
	final MediaPlayer effect = MediaPlayer.create(ctx, resource);
	effect.setOnCompletionListener(new OnCompletionListener() {
		@Override
		public void onCompletion(MediaPlayer arg0) {
			if (effect != null) {
				effect.seekTo(0);
			}
		}
	});
	return effect;
}
 
Example #6
Source File: MediaPlaybackService.java    From coursera-android with MIT License 5 votes vote down vote up
@Override
public void setOnCompletionListener(OnCompletionListener listener) {
    if (mCompatMode) {
        mCompletion = listener;
    } else {
        super.setOnCompletionListener(listener);
    }
}
 
Example #7
Source File: AudioWife.java    From audio-wife with MIT License 5 votes vote down vote up
/****
 * Add custom playback completion listener. Adding multiple listeners will queue up all the
 * listeners and fire them on media playback completes.
 */
public AudioWife addOnCompletionListener(OnCompletionListener listener) {

	// add default click listener to the top
	// so that it is the one that gets fired first
	mCompletionListeners.add(0, listener);

	return this;
}
 
Example #8
Source File: VideoView.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
public void setOnCompletionListener(OnCompletionListener listener) {
	System.out.println("OnCompletionList...");
	Platform.runLater(new Runnable() {
		@Override
		public void run() {
			try {
				if (mediaPlayer != null) {
					mediaPlayer.stop();
				}
			} catch (Exception e) {
				System.out.println("SetOnCompletionListener\nError Player Video: " + e.toString());
			}
		}
	});
}
 
Example #9
Source File: VideoView.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
public void setOnCompletionListener(OnCompletionListener listener) {
	System.out.println("OnCompletionList...");
	Platform.runLater(new Runnable() {
		@Override
		public void run() {
			try {
				if (mediaPlayer != null) {
					mediaPlayer.stop();
				}
			} catch (Exception e) {
				System.out.println("SetOnCompletionListener\nError Player Video: " + e.toString());
			}
		}
	});
}
 
Example #10
Source File: AudioWife.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
/****
 * Add custom playback completion listener. Adding multiple listeners will queue up all the
 * listeners and fire them on media playback completes.
 */
public AudioWife addOnCompletionListener(OnCompletionListener listener) {

    // add default click listener to the top
    // so that it is the one that gets fired first
    mCompletionListeners.add(0, listener);

    return this;
}
 
Example #11
Source File: AudioWife.java    From datmusic-android with Apache License 2.0 5 votes vote down vote up
/**
 * *
 * Add custom playback completion listener. Adding multiple listeners will queue up all the
 * listeners and fire them on media playback completes.
 */
public AudioWife addOnCompletionListener(OnCompletionListener listener) {

    // add default click listener to the top
    // so that it is the one that gets fired first
    mCompletionListeners.add(0, listener);

    return this;
}
 
Example #12
Source File: AudioWife.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
/****
 * Add custom playback completion listener. Adding multiple listeners will queue up all the
 * listeners and fire them on media playback completes.
 */
public AudioWife addOnCompletionListener(OnCompletionListener listener) {

    // add default click listener to the top
    // so that it is the one that gets fired first
    mCompletionListeners.add(0, listener);

    return this;
}
 
Example #13
Source File: VideoViewH264m3u8Hw.java    From letv with Apache License 2.0 4 votes vote down vote up
public void setOnCompletionListener(OnCompletionListener l) {
    this.mOnCompletionListener = l;
}
 
Example #14
Source File: MusicService.java    From coursera-android with MIT License 4 votes vote down vote up
@Override
public void onCreate() {
	super.onCreate();

	// Set up the Media Player
	mPlayer = MediaPlayer.create(this, R.raw.badnews);

	if (null != mPlayer) {

		mPlayer.setLooping(false);

		// Stop Service when music has finished playing
		mPlayer.setOnCompletionListener(new OnCompletionListener() {

			@Override
			public void onCompletion(MediaPlayer mp) {

				// stop Service if it was started with this ID
				// Otherwise let other start commands proceed
				stopSelf(mStartID);

			}
		});
	}

	// Create a notification area notification so the user 
	// can get back to the MusicServiceClient
	
	final Intent notificationIntent = new Intent(getApplicationContext(),
			MusicServiceClient.class);
	final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
			notificationIntent, 0);

	final Notification notification = new Notification.Builder(
			getApplicationContext())
			.setSmallIcon(android.R.drawable.ic_media_play)
			.setOngoing(true).setContentTitle("Music Playing")
			.setContentText("Click to Access Music Player")
			.setContentIntent(pendingIntent).build();

	// Put this Service in a foreground state, so it won't 
	// readily be killed by the system  
	startForeground(NOTIFICATION_ID, notification);

}
 
Example #15
Source File: AudioWife.java    From zom-android-matrix with Apache License 2.0 4 votes vote down vote up
private void fireCustomCompletionListeners(MediaPlayer mp) {
    for (OnCompletionListener listener : mCompletionListeners) {
        listener.onCompletion(mp);
    }
}
 
Example #16
Source File: Music.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public void setOnCompletionListener(final OnCompletionListener pOnCompletionListener) throws MusicReleasedException {
	this.assertNotReleased();

	this.mMediaPlayer.setOnCompletionListener(pOnCompletionListener);
}
 
Example #17
Source File: AudioWife.java    From audio-wife with MIT License 4 votes vote down vote up
private void fireCustomCompletionListeners(MediaPlayer mp) {
	for (OnCompletionListener listener : mCompletionListeners) {
		listener.onCompletion(mp);
	}
}
 
Example #18
Source File: VideoView.java    From libvlc-android-sdk with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void setOnCompletionListener(OnCompletionListener l) {
}
 
Example #19
Source File: VideoPlayTextureView.java    From FFmpegRecorder with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCompletion(MediaPlayer mp) {
	if (mediaStateLitenser != null)
		mediaStateLitenser.OnCompletionListener();
	currentMediaState = MediaState.COMPLETE;
}
 
Example #20
Source File: VideoViewH264m3u8.java    From letv with Apache License 2.0 4 votes vote down vote up
public void setOnCompletionListener(OnCompletionListener l) {
    this.mOnCompletionListener = l;
}
 
Example #21
Source File: VideoViewH264LeMobile.java    From letv with Apache License 2.0 4 votes vote down vote up
public void setOnCompletionListener(OnCompletionListener l) {
    this.mOnCompletionListener = l;
}
 
Example #22
Source File: FullscreenVideoView.java    From FullscreenVideoView with Apache License 2.0 4 votes vote down vote up
public void setOnCompletionListener(OnCompletionListener l) {
    if (mediaPlayer != null)
        this.completionListener = l;
    else throw new RuntimeException("Media Player is not initialized");
}
 
Example #23
Source File: Music.java    From tilt-game-android with MIT License 4 votes vote down vote up
public void setOnCompletionListener(final OnCompletionListener pOnCompletionListener) throws MusicReleasedException {
	this.assertNotReleased();

	this.mMediaPlayer.setOnCompletionListener(pOnCompletionListener);
}
 
Example #24
Source File: VideoPlayTextureView.java    From VideoRecorder with Apache License 2.0 4 votes vote down vote up
@Override
public void onCompletion(MediaPlayer mp) {
	if (mediaStateLitenser != null)
		mediaStateLitenser.OnCompletionListener();
	currentMediaState = MediaState.COMPLETE;
}
 
Example #25
Source File: VideoView.java    From VCL-Android with Apache License 2.0 4 votes vote down vote up
public void setOnCompletionListener(OnCompletionListener l) {
}
 
Example #26
Source File: AudioWife.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
private void fireCustomCompletionListeners(MediaPlayer mp) {
    for (OnCompletionListener listener : mCompletionListeners) {
        listener.onCompletion(mp);
    }
}
 
Example #27
Source File: VideoView.java    From OTTLivePlayer_vlc with MIT License 4 votes vote down vote up
public void setOnCompletionListener(OnCompletionListener l) {
}
 
Example #28
Source File: VideoViewTV.java    From letv with Apache License 2.0 4 votes vote down vote up
public void setOnCompletionListener(OnCompletionListener l) {
    this.mOnCompletionListener = l;
}
 
Example #29
Source File: VideoViewH264m3u8_4D.java    From letv with Apache License 2.0 4 votes vote down vote up
public void setOnCompletionListener(OnCompletionListener l) {
    this.mOnCompletionListener = l;
}
 
Example #30
Source File: VideoViewH264LeMobile_4D.java    From letv with Apache License 2.0 4 votes vote down vote up
public void setOnCompletionListener(OnCompletionListener l) {
    this.mOnCompletionListener = l;
}