Best code examples for Android MediaPlayer class (android.media.MediaPlayer)

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

Android MediaPlayer examples from Open Source projects
Examples using Android MediaPlayer release method:
This code example shows how to use the following methods: release, stop
122:	mp.stop(); 
123:	mp.release(); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: release, stop
43:	player.release(); 
-
73:	player.stop(); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: isPlaying, release, stop
39:	if (mediaPlayer.isPlaying()) { 
40:	mediaPlayer.stop(); 
-
42:	mediaPlayer.release(); 
Full Snippet Info
9
CodeRank
Examples using Android MediaPlayer isPlaying method:
This code example shows how to use the following methods: isPlaying, release, stop
81:	if (mMediaPlayer.isPlaying()) { 
82:	mMediaPlayer.stop(); 
-
84:	mMediaPlayer.release(); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: isPlaying, stop
40:	if (player.isPlaying()) { 
41:	player.stop(); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: isPlaying, setAudioStreamType, setDataSource, setLooping, setOnErrorListener
96:	if(!player.isPlaying()) { 
Full Snippet Info
9
CodeRank
Examples using Android MediaPlayer isLooping method:
This code example shows how to use the following methods: isLooping, isPlaying, pause, release, seekTo
75:	if ( mp.isLooping() || mp.isPlaying() ) 
-
78:	mp.pause(); 
79:	mp.seekTo(0); 
-
91:	mp.release(); 
Full Snippet Info
9
CodeRank
Examples using Android MediaPlayer prepare method:
This code example shows how to use the following methods: prepare, prepareAsync, setAudioStreamType, setDataSource, setOnPreparedListener
77:	mPlayer = new MediaPlayer(); 
-
84:	mPlayer.setDataSource(file); 
85:	mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
86:	mPlayer.prepareAsync(); 
-
90:	mPlayer.setDataSource("/sdcard/" + file); 
91:	mPlayer.prepare(); 
-
93:	mPlayer.setOnPreparedListener(this); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: prepare, setDataSource, start
62:	MediaPlayer mediaPlayer = new MediaPlayer(); 
-
65:	mediaPlayer.setDataSource(file); 
66:	mediaPlayer.prepare(); 
67:	mediaPlayer.start(); 
Full Snippet Info
10
CodeRank
Examples using Android MediaPlayer prepareAsync method:
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
Examples using Android MediaPlayer stop method:
This code example shows how to use the following methods: isPlaying, stop
174:	if (mMediaPlayer.isPlaying()) 
-
176:	mMediaPlayer.stop(); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: stop
39:	player.stop(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: release, stop
153:	mPlayer.stop(); 
154:	mPlayer.release(); 
Full Snippet Info
9
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
Examples for other Android MediaPlayer methods:
Related Android MediaPlayer Questions & Answers:
Other Android MediaPlayer Examples
11:	
12:	            @Override
13:	            public void onCompletion(MediaPlayer mp) {
14:	                // TODO Auto-generated method stub
15:	                mp.release();

Read More

4:		@Override
5:		public void onCompletion(MediaPlayer arg0) {
6:	
7:			// check for repeat is ON or OFF
8:			if(isRepeat){

Read More

21:		private boolean hasFlash;
22:		Parameters params;
23:		MediaPlayer mp;
24:	
25:		@Override
-
144:	
145:	            @Override
146:	            public void onCompletion(MediaPlayer mp) {
147:	                // TODO Auto-generated method stub
148:	                mp.release();

Read More

MediaPlayer Class Overview
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...
Methods
  • 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.
  • setOnCompletionListener
    Register a callback to be invoked when the end of a media source has been reached during playback.
  • 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.