Search in sources :

Example 61 with AudioManager

use of android.media.AudioManager in project android_frameworks_base by DirtyUnicorns.

the class VibratorService method shouldVibrateForRingtone.

private boolean shouldVibrateForRingtone() {
    AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    int ringerMode = audioManager.getRingerModeInternal();
    // "Also vibrate for calls" Setting in Sound
    if (Settings.System.getInt(mContext.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, 0) != 0) {
        return ringerMode != AudioManager.RINGER_MODE_SILENT;
    } else {
        return ringerMode == AudioManager.RINGER_MODE_VIBRATE;
    }
}
Also used : AudioManager(android.media.AudioManager)

Example 62 with AudioManager

use of android.media.AudioManager in project android_frameworks_base by ParanoidAndroid.

the class HTML5Audio method play.

private void play() {
    if (mState == COMPLETE && mLoopEnabled == true) {
        // Play it again, Sam
        mMediaPlayer.start();
        mState = STARTED;
        return;
    }
    if (((mState >= ERROR && mState < PREPARED)) && mUrl != null) {
        resetMediaPlayer();
        setDataSource(mUrl);
        mAskToPlay = true;
    }
    if (mState >= PREPARED) {
        AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
        int result = audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
        if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
            mMediaPlayer.start();
            mState = STARTED;
        }
    }
}
Also used : AudioManager(android.media.AudioManager)

Example 63 with AudioManager

use of android.media.AudioManager in project android_frameworks_base by AOSPA.

the class MediaVisualizerTest method test2_1ListenerCapture.

//Test case 2.1: test capture with listener
@LargeTest
public void test2_1ListenerCapture() throws Exception {
    boolean result = false;
    String msg = "test2_1ListenerCapture()";
    AudioEffect vc = null;
    MediaPlayer mp = null;
    AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
    int ringerMode = am.getRingerMode();
    am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    am.setStreamVolume(AudioManager.STREAM_MUSIC, am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
    try {
        // creating a volume controller on output mix ensures that ro.audio.silent mutes
        // audio after the effects and not before
        vc = new AudioEffect(AudioEffect.EFFECT_TYPE_NULL, VOLUME_EFFECT_UUID, 0, 0);
        vc.setEnabled(true);
        mp = new MediaPlayer();
        mp.setDataSource(MediaNames.SINE_200_1000);
        mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
        getVisualizer(mp.getAudioSessionId());
        createListenerLooper();
        synchronized (lock) {
            try {
                lock.wait(1000);
            } catch (Exception e) {
                Log.e(TAG, "Looper creation: wait was interrupted.");
            }
        }
        assertTrue(mInitialized);
        mVisualizer.setEnabled(true);
        // check capture on silence
        synchronized (lock) {
            try {
                mCaptureWaveform = true;
                lock.wait(1000);
                mCaptureWaveform = false;
            } catch (Exception e) {
                Log.e(TAG, "Capture waveform: wait was interrupted.");
            }
        }
        assertNotNull(msg + ": waveform capture failed", mWaveform);
        int energy = computeEnergy(mWaveform, true);
        assertEquals(msg + ": getWaveForm reports energy for silence", 0, energy);
        synchronized (lock) {
            try {
                mCaptureFft = true;
                lock.wait(1000);
                mCaptureFft = false;
            } catch (Exception e) {
                Log.e(TAG, "Capture FFT: wait was interrupted.");
            }
        }
        assertNotNull(msg + ": FFT capture failed", mFft);
        energy = computeEnergy(mFft, false);
        assertEquals(msg + ": getFft reports energy for silence", 0, energy);
        mp.prepare();
        mp.start();
        Thread.sleep(500);
        // check capture on sound
        synchronized (lock) {
            try {
                mCaptureWaveform = true;
                lock.wait(1000);
                mCaptureWaveform = false;
            } catch (Exception e) {
                Log.e(TAG, "Capture waveform: wait was interrupted.");
            }
        }
        assertNotNull(msg + ": waveform capture failed", mWaveform);
        energy = computeEnergy(mWaveform, true);
        assertTrue(msg + ": getWaveForm reads insufficient level", energy > 0);
        synchronized (lock) {
            try {
                mCaptureFft = true;
                lock.wait(1000);
                mCaptureFft = false;
            } catch (Exception e) {
                Log.e(TAG, "Capture FFT: wait was interrupted.");
            }
        }
        assertNotNull(msg + ": FFT capture failed", mFft);
        energy = computeEnergy(mFft, false);
        assertTrue(msg + ": getFft reads insufficient level", energy > 0);
        result = true;
    } catch (IllegalArgumentException e) {
        msg = msg.concat(": Bad parameter value");
        loge(msg, "Bad parameter value");
    } catch (UnsupportedOperationException e) {
        msg = msg.concat(": get parameter() rejected");
        loge(msg, "get parameter() rejected");
    } catch (IllegalStateException e) {
        msg = msg.concat("get parameter() called in wrong state");
        loge(msg, "get parameter() called in wrong state");
    } catch (InterruptedException e) {
        loge(msg, "sleep() interrupted");
    } finally {
        terminateListenerLooper();
        releaseVisualizer();
        if (mp != null) {
            mp.release();
        }
        if (vc != null) {
            vc.release();
        }
        am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
        am.setRingerMode(ringerMode);
    }
    assertTrue(msg, result);
}
Also used : AudioManager(android.media.AudioManager) AudioEffect(android.media.audiofx.AudioEffect) MediaPlayer(android.media.MediaPlayer) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 64 with AudioManager

use of android.media.AudioManager in project android_frameworks_base by AOSPA.

the class MediaVisualizerTest method test2_2PollingCaptureVolumeScaling.

//Test case 2.2: test capture in polling mode with volume scaling
@LargeTest
public void test2_2PollingCaptureVolumeScaling() throws Exception {
    // test that when playing a sound, the energy measured with Visualizer in
    //   SCALING_MODE_AS_PLAYED mode decreases when lowering the volume
    boolean result = false;
    String msg = "test2_2PollingCaptureVolumeScaling()";
    AudioEffect vc = null;
    MediaPlayer mp = null;
    AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
    int ringerMode = am.getRingerMode();
    am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    final int volMax = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    am.setStreamVolume(AudioManager.STREAM_MUSIC, volMax, 0);
    try {
        // test setup not related to tested functionality:
        // creating a volume controller on output mix ensures that ro.audio.silent mutes
        // audio after the effects and not before
        vc = new AudioEffect(AudioEffect.EFFECT_TYPE_NULL, VOLUME_EFFECT_UUID, 0, 0);
        vc.setEnabled(true);
        mp = new MediaPlayer();
        mp.setDataSource(MediaNames.SINE_200_1000);
        mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
        getVisualizer(mp.getAudioSessionId());
        // verify we successfully set the Visualizer in SCALING_MODE_AS_PLAYED mode
        mVisualizer.setScalingMode(Visualizer.SCALING_MODE_AS_PLAYED);
        assertTrue(msg + " get volume scaling doesn't return SCALING_MODE_AS_PLAYED", mVisualizer.getScalingMode() == Visualizer.SCALING_MODE_AS_PLAYED);
        mVisualizer.setEnabled(true);
        mp.prepare();
        mp.start();
        Thread.sleep(500);
        // check capture on sound with music volume at max
        byte[] data = new byte[mVisualizer.getCaptureSize()];
        mVisualizer.getWaveForm(data);
        int energyAtVolMax = computeEnergy(data, true);
        assertTrue(msg + ": getWaveForm reads insufficient level", energyAtVolMax > 0);
        log(msg, " engergy at max volume = " + energyAtVolMax);
        // check capture on sound with music volume lowered from max
        am.setStreamVolume(AudioManager.STREAM_MUSIC, (volMax * 2) / 3, 0);
        Thread.sleep(500);
        mVisualizer.getWaveForm(data);
        int energyAtLowerVol = computeEnergy(data, true);
        assertTrue(msg + ": getWaveForm at lower volume reads insufficient level", energyAtLowerVol > 0);
        log(msg, "energy at lower volume = " + energyAtLowerVol);
        assertTrue(msg + ": getWaveForm didn't report lower energy when volume decreases", energyAtVolMax > energyAtLowerVol);
        result = true;
    } catch (IllegalArgumentException e) {
        msg = msg.concat(": IllegalArgumentException");
        loge(msg, " hit exception " + e);
    } catch (UnsupportedOperationException e) {
        msg = msg.concat(": UnsupportedOperationException");
        loge(msg, " hit exception " + e);
    } catch (IllegalStateException e) {
        msg = msg.concat("IllegalStateException");
        loge(msg, " hit exception " + e);
    } catch (InterruptedException e) {
        loge(msg, " sleep() interrupted");
    } finally {
        releaseVisualizer();
        if (mp != null) {
            mp.release();
        }
        if (vc != null) {
            vc.release();
        }
        am.setRingerMode(ringerMode);
    }
    assertTrue(msg, result);
}
Also used : AudioManager(android.media.AudioManager) AudioEffect(android.media.audiofx.AudioEffect) MediaPlayer(android.media.MediaPlayer) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 65 with AudioManager

use of android.media.AudioManager in project android_frameworks_base by AOSPA.

the class MediaPresetReverbTest method test2_0AuxiliarySoundModification.

//-----------------------------------------------------------------
// 2 - Effect action
//----------------------------------
//Test case 2.0: test actual auxiliary reverb influence on sound
@LargeTest
public void test2_0AuxiliarySoundModification() throws Exception {
    boolean result = false;
    String msg = "test2_0AuxiliarySoundModification()";
    EnergyProbe probe = null;
    AudioEffect vc = null;
    MediaPlayer mp = null;
    AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
    int ringerMode = am.getRingerMode();
    am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    am.setStreamVolume(AudioManager.STREAM_MUSIC, am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
    getReverb(0);
    try {
        probe = new EnergyProbe(0);
        // creating a volume controller on output mix ensures that ro.audio.silent mutes
        // audio after the effects and not before
        vc = new AudioEffect(AudioEffect.EFFECT_TYPE_NULL, VOLUME_EFFECT_UUID, 0, 0);
        vc.setEnabled(true);
        mp = new MediaPlayer();
        mp.setDataSource(MediaNames.SINE_200_1000);
        mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mp.attachAuxEffect(mReverb.getId());
        mp.setAuxEffectSendLevel(1.0f);
        mReverb.setPreset((short) PresetReverb.PRESET_PLATE);
        mReverb.setEnabled(true);
        mp.prepare();
        mp.start();
        Thread.sleep(1000);
        mp.stop();
        Thread.sleep(200);
        // measure energy around 1kHz after media player was stopped for 200 ms
        int energy1000 = probe.capture(1000);
        assertTrue(msg + ": reverb has no effect", energy1000 > 0);
        result = true;
    } catch (IllegalArgumentException e) {
        msg = msg.concat(": Bad parameter value");
        loge(msg, "Bad parameter value");
    } catch (UnsupportedOperationException e) {
        msg = msg.concat(": get parameter() rejected");
        loge(msg, "get parameter() rejected");
    } catch (IllegalStateException e) {
        msg = msg.concat("get parameter() called in wrong state");
        loge(msg, "get parameter() called in wrong state");
    } catch (InterruptedException e) {
        loge(msg, "sleep() interrupted");
    } finally {
        releaseReverb();
        if (mp != null) {
            mp.release();
        }
        if (vc != null) {
            vc.release();
        }
        if (probe != null) {
            probe.release();
        }
        am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
        am.setRingerMode(ringerMode);
    }
    assertTrue(msg, result);
}
Also used : AudioManager(android.media.AudioManager) EnergyProbe(com.android.mediaframeworktest.functional.EnergyProbe) AudioEffect(android.media.audiofx.AudioEffect) MediaPlayer(android.media.MediaPlayer) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

AudioManager (android.media.AudioManager)159 MediaPlayer (android.media.MediaPlayer)50 AudioEffect (android.media.audiofx.AudioEffect)42 LargeTest (android.test.suitebuilder.annotation.LargeTest)42 EnergyProbe (com.android.mediaframeworktest.functional.EnergyProbe)24 Context (android.content.Context)9 Intent (android.content.Intent)7 IOException (java.io.IOException)7 Cea708CaptionRenderer (android.media.Cea708CaptionRenderer)5 ClosedCaptionRenderer (android.media.ClosedCaptionRenderer)5 MediaFormat (android.media.MediaFormat)5 Ringtone (android.media.Ringtone)5 SubtitleController (android.media.SubtitleController)5 TtmlRenderer (android.media.TtmlRenderer)5 WebVttRenderer (android.media.WebVttRenderer)5 PowerManager (android.os.PowerManager)5 InputStream (java.io.InputStream)5 View (android.view.View)4 NotificationManager (android.app.NotificationManager)3 PendingIntent (android.app.PendingIntent)3