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

This code example shows how to use the following methods:prepare, prepareAsync, setAudioStreamType, setDataSource, setOnPreparedListener
	}	 
	 
	protected void startPlaying(String file) {
		if (isPlaying==false) {
			try { 
				mPlayer = new MediaPlayer();
				isPlaying=true;
				Log.d("Audio startPlaying", "audio: " + file);
				if (isStreaming(file))
				{ 
					Log.d("AudioStartPlaying", "Streaming");
					// Streaming prepare async 
					mPlayer.setDataSource(file);
					mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);  
					mPlayer.prepareAsync();
				} else { 
					Log.d("AudioStartPlaying", "File");
					// Not streaming prepare synchronous, abstract base directory 
					mPlayer.setDataSource("/sdcard/" + file);
					mPlayer.prepare();

9
CodeRank
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
This code example shows how to use the following methods:setAudioStreamType, setOnBufferingUpdateListener, setOnCompletionListener, setOnErrorListener, setOnPreparedListener
This code example shows how to use the following methods:prepare, prepareAsync, setAudioStreamType, setDataSource, setOnPreparedListener
	}	 
	 
	protected void startPlaying(String file) {
		if (isPlaying==false) {
			try { 
				mPlayer = new MediaPlayer();
				isPlaying=true;
				Log.d("Audio startPlaying", "audio: " + file);
				if (isStreaming(file))
				{ 
					Log.d("AudioStartPlaying", "Streaming");
					// Streaming prepare async 
					mPlayer.setDataSource(file);
					mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);  
					mPlayer.prepareAsync();
				} else { 
					Log.d("AudioStartPlaying", "File");
					// Not streaming prepare synchronous, abstract base directory 
					mPlayer.setDataSource("/sdcard/" + file);
					mPlayer.prepare();

6
CodeRank
This code example shows how to use the following methods:prepare, setDataSource, setOnCompletionListener, setOnPreparedListener, setOnSeekCompleteListener
This code example shows how to use the following methods:prepareAsync, setDataSource, setLooping, setOnPreparedListener
    final static String FILE = "file://";
 
    public Play(String uri, Context ctx) throws Exception {
        super(uri);
        _uri = uri;
        _mp = new MediaPlayer();
        if (uri.startsWith(FILE)) {
            _mp.setDataSource(uri);
            _mp.prepare();
            _prepared = true;
        } else { 
            _mp.setDataSource(uri);
            _mp.setOnPreparedListener(this);
            _mp.prepareAsync();
        } 
        _mp.setLooping(true);
        //_mp.setAudioStreamType(AudioManager.MODE_RINGTONE); 
    } 
 
    public void stop() { 
        if (_mp != null) {
8
CodeRank
This code example shows how to use the following methods:setOnCompletionListener, setOnErrorListener, setOnPreparedListener, setWakeMode
     * Makes sure the media player exists and has been reset. This will create the media player 
     * if needed. reset the existing media player if one already exists. 
     */ 
    protected void createMediaPlayerIfNeeded() { 
        if (mPlayer == null) {
            mPlayer = new MediaPlayer();
 
            // make sure the CPU won't go to sleep while media is playing 
            mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
 
            // the media player will notify the service when it's ready preparing, and when it's done playing 
            mPlayer.setOnPreparedListener(this);
            mPlayer.setOnCompletionListener(this);
            mPlayer.setOnErrorListener(this);
             
        } else { 
            mPlayer.reset();
        } 
    } 
 
7
CodeRank
This code example shows how to use the following methods:prepareAsync, setAudioStreamType, setDataSource, setOnErrorListener, setOnPreparedListener
			Log.i(TAG, "MediaStreamerService.play() - AudioFocus request denied");
			 
			notifyStreamError(AUDIO_FOCUS_DENIED_ERROR);
		} 
		 
		mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setOnErrorListener(this);
        mMediaPlayer.setOnPreparedListener(this);
         
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);  
        mMediaPlayer.setVolume(1.0f, 1.0f);
    	try { 
        	mMediaPlayer.setDataSource(this, Uri.parse(urlToStream));
		} catch (Exception e){
    		Log.e(TAG, "MediaStreamerService.play() - Error setting data source for the media player", e);
    		stop(); 
    		notifyStreamError(MEDIA_PLAYER_ERROR);
    		return; 
    	} 
    	try{ 

6
CodeRank
This code example shows how to use the following methods:prepareAsync, setAudioStreamType, setDataSource, setOnCompletionListener, setOnErrorListener
			Log.d("start", "OK I hear you, lets start!");
			m_state = STARTING;
			try { 
				if (m_media_player == null) {
					Log.d("start", "I didn't exist yet so let me get prepared.");
					m_media_player = new MediaPlayer();
					m_media_player.setDataSource(url_string);
					m_media_player.setAudioStreamType(AudioManager.STREAM_MUSIC);
					m_media_player.setOnPreparedListener(this);
					m_media_player.setOnCompletionListener(this);
					m_media_player.setOnErrorListener(this);
					m_media_player.prepareAsync();
 
				} else if (!m_media_player.isPlaying()) {
					Log.d("start", "I exist but i'm not playing? let me fix that...");
					 
					if (m_state != STOPPED) {
						Log.d("start", "Killing current connection...");
						m_media_player.reset();
						m_media_player.release();
6
CodeRank
This code example shows how to use the following methods:prepareAsync, setAudioStreamType, setDataSource, setDisplay, setOnPreparedListener
		Log.d(TAG, "Play video on full, path: " + path);
		File videoFile = new File(path);
        FileInputStream fis;
		try { 
			fis = new FileInputStream(videoFile);
	        mMediaPlayer.setDataSource(fis.getFD());
	        mMediaPlayer.setDisplay(sHolder);
	         
	        mMediaPlayer.prepareAsync();
	         
	        mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
				@Override 
				public void onPrepared(MediaPlayer mp) {
					onCancel(); 
					mMediaPlayer.start();
					setSurfaceViewScale(); 
					mMediaPlayer.seekTo(position);
					mc.setMediaPlayer(getMediaPlayerControl());
					mc.setAnchorView(video);
					 

7
CodeRank

Related MediaPlayer setOnPreparedListener Questions & Answers:

setOnPreparedListener Method Overview
Register a callback to be invoked when the media source is ready for playback.
See Code Examples for other Android MediaPlayer Methods: