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
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();
	} 
} 
8
CodeRank
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
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
This code example shows how to use the following methods:setLooping, setVolume, start
     
       mMediaPlayer = MediaPlayer.create(mContext, inResourceID);
       if (mMediaPlayer==null)
           return -1; 
 
       mMediaPlayer.setVolume((float)inVolLeft,(float)inVolRight);
       if (inLoop<0)
          mMediaPlayer.setLooping(true);
       else if (inLoop>0)
       { 
       } 
       mMediaPlayer.start();
 
       return 0; 
    } 
     
    static public void stopMusic() { 
		Log.v("GameActivity","stop MediaPlayer");
		if (mMediaPlayer != null)
			mMediaPlayer.stop();
7
CodeRank
This code example shows how to use the following methods:setVolume
    } 
 
    public void volume(float val) {
        float fval = val / 100.0f;
        if (_mp != null) {
            _mp.setVolume(fval, fval);
        } 
    } 
 
    public void onPrepared(MediaPlayer mp) {
        Log.debug("prepared " + _uri);
        _prepared = true;
        if(_startme){
        	mp.start();
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:prepare, reset, setDataSource, setLooping, setVolume
This code example shows how to use the following methods:prepare, setAudioStreamType, setDataSource, setOnCompletionListener, setVolume
		if (playBeep && mediaPlayer == null) {
			// The volume on STREAM_SYSTEM is not adjustable, and users found it 
			// too loud, 
			// so we now play on the music stream. 
			setVolumeControlStream(AudioManager.STREAM_MUSIC);
			mediaPlayer = new MediaPlayer();
			mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
			mediaPlayer.setOnCompletionListener(beepListener);
 
			AssetFileDescriptor file = getResources().openRawResourceFd(BridgeR.get("R.raw.beep"));
			try { 
				mediaPlayer.setDataSource(file.getFileDescriptor(),
						file.getStartOffset(), file.getLength());
				file.close();
				mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
				mediaPlayer.prepare();
			} catch (IOException e) {
				mediaPlayer = null;
			} 
		} 
	} 
6
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

Related MediaPlayer setVolume Questions & Answers:

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