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

This code example shows how to use the following methods:release, stop
	 * @param mp 
	 */ 
	private void safeClose(MediaPlayer mp) {
		if (mp != null) {
			try { 
				mp.stop();
			} catch (Exception e) {
				Log.w(TAG, "Failed to stop media player",e);
			} finally { 
				mp.release();
			} 
		} 
	} 
	 
	/** 
	 * Safely close a {@link MediaRecorder} without throwing 
	 * exceptions 
	 * @param mr 
	 */ 
	private void safeClose(MediaRecorder mr, boolean stopIt) {
9
CodeRank
This code example shows how to use the following methods:isPlaying, release, stop
            throw new RuntimeException("Couldn't load music");
        } 
    } 
 
    public void dispose() { 
        if (mediaPlayer.isPlaying())
            mediaPlayer.stop();
        mediaPlayer.release();
    } 
 
    public boolean isLooping() { 
        return mediaPlayer.isLooping();
    } 
 
    public boolean isPlaying() { 
        return mediaPlayer.isPlaying();
    } 
 
    public boolean isStopped() { 
        return !isPrepared;
8
CodeRank
This code example shows how to use the following methods:release
      mPlayer = new MediaPlayer();
    } 
 
    @Override 
    protected void tearDown() throws Exception { 
        mPlayer.release();
        super.tearDown(); 
    } 
 
    // Generate a random number, sends it to the ping test player. 
    @Suppress 
    @MediumTest 
    public void testPing() throws Exception { 
        mPlayer.setDataSource("test:invoke_mock_media_player.so?url=ping");
 
        Parcel request = mPlayer.newRequest();
        Parcel reply = Parcel.obtain();
 
        int val = rnd.nextInt();
        request.writeInt(val);
8
CodeRank
This code example shows how to use the following methods:release, stop
    public void onCompletion(MediaPlayer mediaplayer) {
        Timer endSound = new Timer();
        endSound.schedule(new TimerTask() {
            public void run() { 
                if (mp != null) {
                    mp.stop();
                    mp.release();
                    mp = null;
                } 
            } 
        }, 200); 
 
    } 
 
    /** 
     * Play sound, either locally (from assets) or remotely via URL. 
     *  
     * @param soundUri 
     *            the sound uri 
     */ 
10
CodeRank
This code example shows how to use the following methods:isPlaying, release, stop
	/** 
	 * Get rid of the music 
	 */ 
	public void dispose() { 
		 
		if (mediaPlayer.isPlaying()) {
			 
			mediaPlayer.stop();
		} 
		 
		mediaPlayer.release();
	} 
 
	/** 
	 * Called internal 
	 *  
	 * @param MediaPlayer mediaPlayer 
	 */ 
	public void onCompletion(MediaPlayer mediaPlayer) {
		 
8
CodeRank
This code example shows how to use the following methods:release, stop
		}  
	} 
	 
	void unloadSound(){ 
		if(player!=null){
			player.release();
			player = null;
		} 
 
		if(soundID!=-1){
			pool.unload(soundID);
		} 
		fileName = null;
		soundID = -1;
		streamID = -1;
		bIsLoaded = false;
		bIsPlaying = false;
	} 
	 
	void play(){ 

9
CodeRank
This code example shows how to use the following methods:isPlaying, release, stop
		} 
		return play;
	} 
	public static void cleanup() { 
		if (mMediaPlayer != null) {
			if (mMediaPlayer.isPlaying()) {
				mMediaPlayer.stop();
			} 
			mMediaPlayer.release();
			mMediaPlayer = null;
		} 
	} 
} 
8
CodeRank
This code example shows how to use the following methods:isLooping, isPlaying, pause, release, seekTo
		} 
	} 
	 
	public void stop() throws IOException 
	{ 
		if ( mp.isLooping() || mp.isPlaying() )
		{ 
			state = INVALID;
			mp.pause();
			mp.seekTo(0);
		} 
	} 
	 
	public void loop() throws IOException 
	{ 
		invokePlay( true ); 
	} 
	 
	public void unload() throws IOException 
	{ 

9
CodeRank
This code example shows how to use the following methods:isPlaying, release, stop
            Log.v(TAG, "Tried to release player when it was already released");
            return; 
        } 
        try { 
            if (player != null) {
                if (player.isPlaying()) {
                    player.stop();
                } 
                player.release();
            } 
        } catch (Exception e) {
            Log.e(TAG, e.getMessage(), e);
        } 
        Log.v(TAG, "Released the music.");
        released = true;
    } 
 
    /** 
     * Sets the Volume level in sensible range. Handles special case of someone is calling or if on call. 
     * @param context 
8
CodeRank
This code example shows how to use the following methods:release, stop
		} 
	}  
 
	public void stopPlaying() { 
		if (isPlaying) {
			mPlayer.stop();
			mPlayer.release();
			isPlaying=false;
		} 
	} 
	 
	public void onCompletion(MediaPlayer mPlayer) {
		mPlayer.stop();
		mPlayer.release();
		isPlaying=false;
    }  
	 
	protected long getCurrentPosition() { 
		if (isPlaying) 
		{ 
10
CodeRank

Related MediaPlayer release Questions & Answers:

Other MediaPlayer release Examples

146:	            public void onCompletion(MediaPlayer mp) {
147:	                // TODO Auto-generated method stub
148:	                mp.release();
149:	            }
150:	        });

Read More

13:	            public void onCompletion(MediaPlayer mp) {
14:	                // TODO Auto-generated method stub
15:	                mp.release();
16:	            }
17:	        });

Read More

release Method Overview
Releases resources associated with this MediaPlayer object.
See Code Examples for other Android MediaPlayer Methods: