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

This code example shows how to use the following methods: prepare, seekTo, start, stop
		} 
	} 
	 
	public void rewindBackgroundMusic(){		 
		if (mBackgroundMediaPlayer != null){
			mBackgroundMediaPlayer.stop();			
			 
			try { 
				mBackgroundMediaPlayer.prepare();
				mBackgroundMediaPlayer.seekTo(0);
				mBackgroundMediaPlayer.start();
				 
				this.mIsPaused = false;
			} catch (Exception e){
				Log.e(TAG, "rewindBackgroundMusic: error state");
			}			 
		} 
	} 
	 
	public boolean isBackgroundMusicPlaying(){ 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: isPlaying, prepare, setAudioStreamType, setDataSource, start
    public boolean isActive() { 
        return false; 
    } 
 
    public boolean isRunning() { 
        return player != null && player.isPlaying();
    } 
 
    public void start() { 
        if (!isOpen()) { 
            throw new IllegalStateException("Clip must be open");
        } 
         
        if (stream == null) {
            throw new IllegalStateException("Need an AudioInputStream to play");
        } 
 
        if (!isRunning()) { 
            /* 
             * This is ugly, but there is no way around it: The javax.sound API 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: isPlaying, prepare, seekTo, stop
	 
	public static void stopMusic() 
	{ 
		if(mPlayer != null)
		{ 
			if(mPlayer.isPlaying())
			{ 
				mPlayer.stop();
				try 
				{ 
					mPlayer.prepare();
					mPlayer.seekTo(0);
				} 
				catch (IOException e)
				{ 
					// do nothing here FIXME 
				} 
			} 
		} 
	} 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getDuration, prepare, release, setDataSource
 
	protected long getDuration(String file) {
		long duration = -2;
		if (!isPlaying & !isStreaming(file)) {
			try { 
				mPlayer = new MediaPlayer();
				mPlayer.setDataSource("/sdcard/" + file);
				mPlayer.prepare();
				duration = mPlayer.getDuration();
				mPlayer.release();
			} catch (Exception e) { e.printStackTrace(); return(-3); }
		} else 
		if (isPlaying & !isStreaming(file)) {
			duration = mPlayer.getDuration();
		} else  
		if (isPlaying & isStreaming(file)) {
			try { 
				duration = mPlayer.getDuration();
			} catch (Exception e) { e.printStackTrace(); return(-4); }
		}else { return -1; } 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: prepare, setAudioStreamType, setDataSource
	private int state;
	 
	public PGPolyphonicVoice( AssetFileDescriptor afd )  throws IOException
	{ 
		state = INVALID;
		mp = new MediaPlayer();
		mp.setDataSource( afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
		mp.setAudioStreamType(AudioManager.STREAM_MUSIC);  
		mp.prepare();
	} 
	 
	public void play() throws IOException 
	{ 
		invokePlay( false ); 
	} 
	 
	private void invokePlay( Boolean loop )
	{ 
		Boolean playing = ( mp.isLooping() || mp.isPlaying() );
		if ( playing )
Full Snippet Info
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: prepare, setDataSource, setVolume
	 
	void loadSound(String fileName, boolean stream){
		try { 
			if(stream){
				if(player!=null) unloadSound();
				player = new MediaPlayer();
				player.setDataSource(fileName);
				player.prepare();
			}else{ 
				if(soundID!=-1) unloadSound();
				soundID = pool.load(fileName, 1);
			} 
			setVolume(volume);
			bIsLoaded = true;
			this.fileName = fileName;
			this.stream = stream;
		} catch (Exception e) {
			Log.e("OF","couldn't load " + fileName,e);
		}  
	} 

9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: prepare, seekTo, setLooping, start, stop
		 
		if (mBackgroundMediaPlayer == null){
			Log.e(TAG, "playBackgroundMusic: background media player is null");
		} else {		 
			// if the music is playing or paused, stop it 
			mBackgroundMediaPlayer.stop();			
			 
			mBackgroundMediaPlayer.setLooping(isLoop);
			 
			try { 
				mBackgroundMediaPlayer.prepare();
				mBackgroundMediaPlayer.seekTo(0);
				mBackgroundMediaPlayer.start();
				 
				this.mIsPaused = false;
			} catch (Exception e){
				Log.e(TAG, "playBackgroundMusic: error state");
			}			 
		} 
	} 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getDuration, prepare, release, setDataSource
	 
	protected long getDuration(String file) {
		long duration = -2;
		if (!isPlaying & !isStreaming(file)) {
			try { 
				mPlayer = new MediaPlayer();
				mPlayer.setDataSource("/sdcard/" + file);
				mPlayer.prepare();
				duration = mPlayer.getDuration();
				mPlayer.release();
			} catch (Exception e) { e.printStackTrace(); return(-3); }
		} else 
		if (isPlaying & !isStreaming(file)) {
			duration = mPlayer.getDuration();
		} else  
		if (isPlaying & isStreaming(file)) {
			try { 
				duration = mPlayer.getDuration();
			} catch (Exception e) { e.printStackTrace(); return(-4); }
		}else { return -1; } 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: isPlaying, prepare, reset, setDataSource, start
		mediaPlayer = new MediaPlayer();
		isPaused  = false;
	} 
		 
	public void play() { 
    	if (!mediaPlayer.isPlaying() && currentTrack != null) {
    		try { 
    			if (!isPaused) {
    				mediaPlayer.reset();
        			mediaPlayer.setDataSource(currentTrack);
        			mediaPlayer.prepare();
        			isPaused = false;
    			} 
    			mediaPlayer.start();    			
			} catch (Exception e) {
				//ignore 
			}    		 
    	} 
    } 
     
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related MediaPlayer prepare Questions & Answers:

Other MediaPlayer prepare Examples

237:			});
238:	
239:			/**
240:			 * Button Click event for Play list click event
241:			 * Launches list activity which displays list of songs

Read More

prepare Method Overview
Prepares the player for playback, synchronously.
See Code Examples for other Android MediaPlayer Methods: