Best code examples for MediaPlayer setOnCompletionListener method (android.media.MediaPlayer.setOnCompletionListener)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for MediaPlayer setOnCompletionListener method.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

MediaPlayer setOnCompletionListener examples from Open Source projects
This code example shows how to use the following methods: setOnCompletionListener
111:	this.mMediaPlayer.setOnCompletionListener(pOnCompletionListener); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setOnCompletionListener
15:	mPlayer = new MediaPlayer(); 
16:	mPlayer.setOnCompletionListener(this); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnCompletionListener
15:	mPlayer = new MediaPlayer(); 
16:	mPlayer.setOnCompletionListener(this); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnCompletionListener
42:	_mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnBufferingUpdateListener, setOnCompletionListener, start
155:	mPlayer.setOnCompletionListener(this); 
156:	mPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() 
-
164:	mPlayer.start(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setOnCompletionListener
25:	mediaPlayer = new MediaPlayer(); 
26:	mediaPlayer.setOnCompletionListener(listener); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnCompletionListener, setOnErrorListener
30:	player = new MediaPlayer(); 
-
38:	player.setOnCompletionListener(new OnCompletionListener() { 
-
46:	player.setOnErrorListener(new OnErrorListener() { 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setOnCompletionListener
39:	this.player.setOnCompletionListener(listener); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnCompletionListener
16:	mPlayer = new MediaPlayer(); 
-
18:	mPlayer.setOnCompletionListener(this); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: prepareAsync, setAudioStreamType, setDataSource, setOnCompletionListener, setOnPreparedListener
87:	mediaPlayer = new MediaPlayer(); 
88:	mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL); 
89:	mediaPlayer.setOnCompletionListener(this); 
90:	mediaPlayer.setOnPreparedListener(this); 
-
96:	mediaPlayer.setDataSource(context, dataUri); 
-
114:	mediaPlayer.prepareAsync(); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: prepare, setAudioStreamType, setDataSource, setOnCompletionListener, start
57:	MediaPlayer mediaPlayer = new MediaPlayer(); 
-
59:	mediaPlayer.setDataSource(context, 
-
70:	mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION); 
-
72:	mediaPlayer.prepare(); 
-
78:	mediaPlayer.start(); 
79:	mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setAudioStreamType, setOnBufferingUpdateListener, setOnCompletionListener, setOnErrorListener, setOnPreparedListener
22:	mMediaPlayer = new MediaPlayer(); 
23:	mMediaPlayer.setOnBufferingUpdateListener(this); 
24:	mMediaPlayer.setOnCompletionListener(this); 
25:	mMediaPlayer.setOnPreparedListener(this); 
26:	mMediaPlayer.setOnErrorListener(this); 
27:	mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setOnCompletionListener
16:	mPlayer = new MediaPlayer(); 
-
18:	mPlayer.setOnCompletionListener(this); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnCompletionListener
58:	mp.setOnCompletionListener(listener); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: prepare, setDataSource, setOnCompletionListener, setVolume, start
52:	player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 
-
58:	player.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength()); 
-
60:	player.setVolume(0.2f, 0.2f); 
61:	player.prepare(); 
62:	player.start(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: prepare, setDataSource, setOnCompletionListener, setOnErrorListener, start
214:	mPlayer = new MediaPlayer(); 
-
216:	mPlayer.setDataSource(mSampleFile.getAbsolutePath()); 
217:	mPlayer.setOnCompletionListener(this); 
218:	mPlayer.setOnErrorListener(this); 
219:	mPlayer.prepare(); 
220:	mPlayer.start(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setOnCompletionListener, setOnErrorListener
133:	player.setOnCompletionListener(onCompletionListener); 
-
135:	player.setOnErrorListener(onErrorListener); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: prepare, setDataSource, setOnCompletionListener, setOnPreparedListener, setOnSeekCompleteListener
19:	mediaPlayer = new MediaPlayer(); 
-
21:	mediaPlayer.setDataSource(assetDescriptor.getFileDescriptor(), 
-
24:	mediaPlayer.prepare(); 
-
26:	mediaPlayer.setOnCompletionListener(this); 
27:	mediaPlayer.setOnSeekCompleteListener(this); 
28:	mediaPlayer.setOnPreparedListener(this); 
29:	mediaPlayer.setOnVideoSizeChangedListener(this); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setOnCompletionListener
26:	player = new MediaPlayer(); 
-
29:	player.setOnCompletionListener(this); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnBufferingUpdateListener, setOnCompletionListener, start
155:	mPlayer.setOnCompletionListener(this); 
156:	mPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() 
-
164:	mPlayer.start(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setOnCompletionListener, setOnErrorListener, setOnPreparedListener, setWakeMode
297:	mPlayer = new MediaPlayer(); 
-
300:	mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); 
-
303:	mPlayer.setOnPreparedListener(this); 
304:	mPlayer.setOnCompletionListener(this); 
305:	mPlayer.setOnErrorListener(this); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnCompletionListener
57:	m_wrappedPlayer = new MediaPlayer(); 
58:	m_wrappedPlayer.setOnCompletionListener(new CListener()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: prepare, setAudioStreamType, setDataSource, setOnCompletionListener, setVolume
161:	mediaPlayer = new MediaPlayer(); 
162:	mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
163:	mediaPlayer.setOnCompletionListener(beepListener); 
-
167:	mediaPlayer.setDataSource(file.getFileDescriptor(), 
-
170:	mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME); 
171:	mediaPlayer.prepare(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: prepareAsync, setAudioStreamType, setDataSource, setOnCompletionListener, setOnErrorListener
73:	m_media_player = new MediaPlayer(); 
74:	m_media_player.setDataSource(url_string); 
75:	m_media_player.setAudioStreamType(AudioManager.STREAM_MUSIC); 
76:	m_media_player.setOnPreparedListener(this); 
77:	m_media_player.setOnCompletionListener(this); 
78:	m_media_player.setOnErrorListener(this); 
79:	m_media_player.prepareAsync(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setLooping, setOnCompletionListener, setVolume
38:	mp.setLooping(true); 
-
41:	mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 
-
61:	mp.setVolume((float)leftVol, (float)rightVol); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: prepare, setAudioStreamType, setDataSource, setLooping, setOnCompletionListener
22:	MediaPlayer mp = new MediaPlayer(); 
-
26:	mp.setDataSource(context, alert); 
27:	mp.setLooping(false); 
28:	mp.setAudioStreamType(AudioManager.STREAM_NOTIFICATION); 
29:	mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 
-
36:	mp.prepare(); 
37:	mp.start(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnCompletionListener
112:	mp = new MediaPlayer(); 
113:	mp.setOnCompletionListener(this); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnCompletionListener, setOnErrorListener, setOnPreparedListener, setWakeMode
161:	mPlayer = new MediaPlayer(); 
-
168:	mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); 
-
172:	mPlayer.setOnPreparedListener(this); 
173:	mPlayer.setOnCompletionListener(this); 
174:	mPlayer.setOnErrorListener(this); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: prepare, setDataSource, setOnCompletionListener, setOnErrorListener, start
182:	mPlayer = new MediaPlayer(); 
-
184:	mPlayer.setDataSource(mSampleFile.getAbsolutePath()); 
185:	mPlayer.setOnCompletionListener(this); 
186:	mPlayer.setOnErrorListener(this); 
187:	mPlayer.prepare(); 
188:	mPlayer.start(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: prepare, setAudioStreamType, setDataSource, setOnCompletionListener, setVolume
165:	mediaPlayer = new MediaPlayer(); 
166:	mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
167:	mediaPlayer.setOnCompletionListener(beepListener); 
-
171:	mediaPlayer.setDataSource(file.getFileDescriptor(), 
-
174:	mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME); 
175:	mediaPlayer.prepare(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: prepare, setAudioStreamType, setDataSource, setDisplay, setOnBufferingUpdateListener
65:	mMediaPlayer = new MediaPlayer(); 
66:	mMediaPlayer.setDataSource(path); 
-
68:	mMediaPlayer.setDisplay(holder); 
69:	mMediaPlayer.prepare(); 
70:	mMediaPlayer.setOnBufferingUpdateListener(this); 
71:	mMediaPlayer.setOnCompletionListener(this); 
72:	mMediaPlayer.setOnPreparedListener(this); 
73:	mMediaPlayer.setOnVideoSizeChangedListener(this); 
74:	mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setAudioStreamType, setOnCompletionListener, setOnErrorListener, start
93:	mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
94:	mMediaPlayer.setOnCompletionListener(new OnCompletionListener() { 
-
99:	mMediaPlayer.setOnErrorListener(new OnErrorListener() { 
-
107:	mMediaPlayer.start(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setLooping, setOnCompletionListener, setVolume
38:	mp.setLooping(true); 
-
41:	mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 
-
61:	mp.setVolume((float)leftVol, (float)rightVol); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setOnCompletionListener
85:	mMediaPlayer = new MediaPlayer(); 
-
87:	mMediaPlayer.setOnCompletionListener(this); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnBufferingUpdateListener, setOnCompletionListener, start
155:	mPlayer.setOnCompletionListener(this); 
156:	mPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() 
-
164:	mPlayer.start(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setOnBufferingUpdateListener, setOnCompletionListener, setOnErrorListener, setOnPreparedListener, setOnSeekCompleteListener
59:	androidMediaPlayer.setOnPreparedListener(this); 
60:	androidMediaPlayer.setOnBufferingUpdateListener(this); 
61:	androidMediaPlayer.setOnCompletionListener(this); 
62:	androidMediaPlayer.setOnSeekCompleteListener(this); 
63:	androidMediaPlayer.setOnErrorListener(this); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: prepareAsync, setDataSource, setDisplay, setOnCompletionListener, setOnPreparedListener
109:	mediaPlayer.setDisplay(holder); 
110:	mediaPlayer.setDataSource(videoURL); 
111:	mediaPlayer.setOnPreparedListener(new VideoPlayerPrepareListener( 
-
113:	mediaPlayer.setOnCompletionListener(new VideoPlayerOnCompletionListener()); 
114:	mediaPlayer.prepareAsync(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: prepare, setDataSource, setDisplay, setOnCompletionListener, start
60:	mediaPlayer = new MediaPlayer(); 
61:	mediaPlayer.setOnCompletionListener(this); 
62:	mediaPlayer.setDisplay(holder); 
63:	mediaPlayer.setDataSource(videoPath); 
64:	mediaPlayer.prepare(); 
65:	mediaPlayer.start(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setOnCompletionListener
309:	mMediaPlayer = new MediaPlayer(); 
310:	mMediaPlayer.setOnCompletionListener(this); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: prepareAsync, setDataSource, setOnCompletionListener, setOnErrorListener, setOnInfoListener
29:	player = new MediaPlayer(); 
30:	player.setDataSource(path); 
-
32:	player.setOnPreparedListener(listenerActivity); 
33:	player.setOnInfoListener(listenerActivity); 
34:	player.setOnErrorListener(listenerActivity); 
35:	player.setOnCompletionListener(listenerActivity); 
-
44:	player.prepareAsync(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: prepareAsync, setDataSource, setOnCompletionListener, setOnErrorListener, setOnPreparedListener
120:	mMediaPlayer = new MediaPlayer(); 
121:	mMediaPlayer.setOnPreparedListener(this); 
122:	mMediaPlayer.setOnCompletionListener(this); 
123:	mMediaPlayer.setOnErrorListener(this); 
-
134:	mMediaPlayer.setDataSource(mMediaLocation); 
135:	mMediaPlayer.prepareAsync(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setOnCompletionListener, setOnErrorListener, setOnPreparedListener, setWakeMode
138:	mPlayer = new MediaPlayer(); 
-
145:	mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); 
-
149:	mPlayer.setOnPreparedListener(this); 
150:	mPlayer.setOnCompletionListener(this); 
151:	mPlayer.setOnErrorListener(this); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: prepare, setAudioStreamType, setDataSource, setDisplay, setOnBufferingUpdateListener
39:	mMediaPlayer = new MediaPlayer(); 
40:	mMediaPlayer.setDataSource(path); 
41:	mMediaPlayer.setDisplay(holder); 
42:	mMediaPlayer.prepare(); 
43:	mMediaPlayer.setOnBufferingUpdateListener(this); 
44:	mMediaPlayer.setOnCompletionListener(this); 
45:	mMediaPlayer.setOnPreparedListener(this); 
46:	mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setOnBufferingUpdateListener, setOnCompletionListener, start
155:	mPlayer.setOnCompletionListener(this); 
156:	mPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() 
-
164:	mPlayer.start(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setOnCompletionListener
45:	mMediaPlayer = new MediaPlayer(); 
46:	mMediaPlayer.setOnCompletionListener(onCompletionListener); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setOnCompletionListener, setOnErrorListener, setOnPreparedListener, setWakeMode
168:	mPlayer = new MediaPlayer(); 
-
178:	mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); 
-
183:	mPlayer.setOnPreparedListener(this); 
184:	mPlayer.setOnCompletionListener(this); 
185:	mPlayer.setOnErrorListener(this); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: setOnBufferingUpdateListener, setOnCompletionListener, start
148:	mPlayer.setOnCompletionListener(this); 
149:	mPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() 
-
157:	mPlayer.start(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setOnCompletionListener, setOnErrorListener, setOnPreparedListener, setWakeMode
163:	mPlayer = new MediaPlayer(); 
-
170:	mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); 
-
174:	mPlayer.setOnPreparedListener(this); 
175:	mPlayer.setOnCompletionListener(this); 
176:	mPlayer.setOnErrorListener(this); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: setOnCompletionListener
88:	this.mPlayer = new MediaPlayer(); 
89:	this.mPlayer.setOnCompletionListener(this); 
Full Snippet Info
7
CodeRank
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

MediaPlayer class can be used to control playback of audio/video files and streams. An example on how to use the methods in this class can be found in VideoView.

Topics covered here are: State Diagram Valid and Invalid States Permissions Register informational and error callbacks Developer Guides For more information about how to use MediaPlayer, read the Media Playback developer guide. State Diagram Playback control of audio/video files and streams is managed as a state machine. The following diagram shows the life cycle and the states of a MediaPlayer object driven by the supported playback control operations. The ovals represent the states a MediaPlayer object may reside in. The arcs represent the playback control operations that drive the object state transition. There are two types of arcs. The arcs with a single arrow head represent synchronous method calls, while those with a double arrow head represent asynchronous method calls.From this state diagram, one can...
setOnCompletionListener Method Overview
Register a callback to be invoked when the end of a media source has been reached during playback.
See Also
  • isLooping
    Checks whether the MediaPlayer is looping or non-looping.
  • isPlaying
    Checks whether the MediaPlayer is playing.
  • prepare
    Prepares the player for playback, synchronously.
  • prepareAsync
    Prepares the player for playback, asynchronously.
  • release
    Releases resources associated with this MediaPlayer object.
  • reset
    Resets the MediaPlayer to its uninitialized state.
  • seekTo
    Seeks to specified time position.
  • setDataSource
    Sets the data source (file-path or http/rtsp URL) to use.
  • setDisplay
    Sets the SurfaceHolder to use for displaying the video portion of the media.
  • setLooping
    Sets the player to be looping or non-looping.
  • setOnErrorListener
    Register a callback to be invoked when an error has happened during an asynchronous operation.
  • setOnInfoListener
    Register a callback to be invoked when an info/warning is available.
  • setScreenOnWhilePlaying
    Control whether we should use the attached SurfaceHolder to keep the screen on while video playback is occurring.
  • setWakeMode
    Set the low-level power management behavior for this MediaPlayer.
  • start
    Starts or resumes playback.
  • stop
    Stops playback after playback has been stopped or paused.