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

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
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: prepare, setDataSource, setOnCompletionListener, setVolume, start
		return player;
	} 
 
	private static void playFile(final MediaPlayer player, final AssetFileDescriptor file) throws IllegalArgumentException, IllegalStateException, IOException {
	    // When the beep has finished playing, rewind to queue up another one. 
		player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
	      @Override 
	      public void onCompletion(MediaPlayer player) {
	        player.release();
	      } 
	    }); 
	    player.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
	    file.close();
	    player.setVolume(0.2f, 0.2f);
	    player.prepare();
	    player.start();
	} 
} 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: prepare, setDataSource, setVolume
This code example shows how to use the following methods: isPlaying, setLooping, setVolume, start
			mp = MediaPlayer.create(context, music);
			if (mp == null) {
				Log.e(TAG, "musciplayer was not created successfully");
			} else { 
				try { 
					mp.setLooping(false);
//					pct = Preferences.getMusicVolume(context); 
				} catch (Exception e) {
					Log.e(TAG, e.getMessage(), e);
				} 
			} 
		} 
 
		if (!mp.isPlaying()) {
//			pct = Preferences.getMusicVolume(context); 
			Log.i(TAG, "Setting music at: " + pct);
			mp.setVolume(pct, pct);
			mp.start();
		} 
 

6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: isPlaying, setVolume
        if (mPlayer == null) {
            throw new IllegalStateException("mPlayer is NULL");
        } 
         
        if (mAudioFocus == AudioFocus.NO_FOCUS) {
            if (mPlayer.isPlaying()) {
                mPlayer.pause();        // have to be polite; but mState is not changed, to resume when focus is received again
            } 
             
        }  else {  
            if (mAudioFocus == AudioFocus.NO_FOCUS_CAN_DUCK) {
                mPlayer.setVolume(DUCK_VOLUME, DUCK_VOLUME);
                 
            } else { 
                mPlayer.setVolume(1.0f, 1.0f); // full volume
            } 
     
            if (!mPlayer.isPlaying()) {
                mPlayer.start();
            } 

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related MediaPlayer setVolume Questions & Answers:

setVolume Method Overview
Sets the volume on this player.
See Code Examples for other Android MediaPlayer Methods: