Code example for AudioManager

Methods: getStreamMaxVolumegetStreamVolumesetStreamVolume

0
        Uri alertSound = SmsCallHelper.returnUserRingtone(this);
 
        if (mPlaying) {
            stopAlarm(); 
        } else { 
            mAlarmVolumeSetting = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);
        } 
 
        if (mMediaPlayer == null) {
            mMediaPlayer = new MediaPlayer();
            mMediaPlayer.setOnErrorListener(new OnErrorListener() {
                @Override 
                public boolean onError(MediaPlayer mp, int what, int extra) {
                    mp.stop();
                    mp.release();
                    mMediaPlayer = null;
                    return true; 
                } 
            }); 
        } 
 
        mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM,
                mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM), 0);
 
        mMediaPlayer.setDataSource(this, alertSound);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
 
        if (SmsCallHelper.returnUserRingtoneLoop(this)) {
Contextual code suggestions in your IDE  Get Codota for Java