Search in sources :

Example 71 with AudioManager

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

the class MediaEnvReverbTest method test2_1InsertSoundModification.

//Test case 2.1: test actual insert reverb influence on sound
@LargeTest
public void test2_1InsertSoundModification() throws Exception {
    boolean result = false;
    String msg = "test2_1InsertSoundModification()";
    EnergyProbe probe = null;
    AudioEffect vc = null;
    MediaPlayer mp = null;
    AudioEffect rvb = 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);
        // create reverb with UUID instead of EnvironmentalReverb constructor otherwise an
        // auxiliary reverb will be chosen by the effect framework as we are on session 0
        rvb = new AudioEffect(AudioEffect.EFFECT_TYPE_NULL, ENV_REVERB_EFFECT_UUID, 0, 0);
        rvb.setParameter(EnvironmentalReverb.PARAM_ROOM_LEVEL, (short) 0);
        rvb.setParameter(EnvironmentalReverb.PARAM_REVERB_LEVEL, (short) 0);
        rvb.setParameter(EnvironmentalReverb.PARAM_DECAY_TIME, 2000);
        rvb.setEnabled(true);
        // create probe after reverb so that it is chained behind the reverb in the
        // effect chain
        probe = new EnergyProbe(0);
        mp.prepare();
        mp.start();
        Thread.sleep(1000);
        mp.stop();
        Thread.sleep(300);
        // measure energy around 1kHz after media player was stopped for 300 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 {
        if (mp != null) {
            mp.release();
        }
        if (vc != null) {
            vc.release();
        }
        if (rvb != null) {
            rvb.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)

Example 72 with AudioManager

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

the class MediaEnvReverbTest 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.setRoomLevel((short) 0);
        mReverb.setReverbLevel((short) 0);
        mReverb.setDecayTime(2000);
        mReverb.setEnabled(true);
        mp.prepare();
        mp.start();
        Thread.sleep(1000);
        mp.stop();
        Thread.sleep(300);
        // measure energy around 1kHz after media player was stopped for 300 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)

Example 73 with AudioManager

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

the class MediaPresetReverbTest method test2_1InsertSoundModification.

//Test case 2.1: test actual insert reverb influence on sound
@LargeTest
public void test2_1InsertSoundModification() throws Exception {
    boolean result = false;
    String msg = "test2_1InsertSoundModification()";
    EnergyProbe probe = null;
    AudioEffect vc = null;
    MediaPlayer mp = null;
    AudioEffect rvb = 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);
        // create reverb with UUID instead of PresetReverb constructor otherwise an auxiliary
        // reverb will be chosen by the effect framework as we are on session 0
        rvb = new AudioEffect(AudioEffect.EFFECT_TYPE_NULL, PRESET_REVERB_EFFECT_UUID, 0, 0);
        rvb.setParameter(PresetReverb.PARAM_PRESET, PresetReverb.PRESET_PLATE);
        rvb.setEnabled(true);
        // create probe after reverb so that it is chained behind the reverb in the
        // effect chain
        probe = new EnergyProbe(0);
        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 {
        if (mp != null) {
            mp.release();
        }
        if (vc != null) {
            vc.release();
        }
        if (rvb != null) {
            rvb.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)

Example 74 with AudioManager

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

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 75 with AudioManager

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

the class BluetoothTestUtils method startStopSco.

/**
     * Helper method for {@link #startSco(BluetoothAdapter, BluetoothDevice)} and
     * {@link #stopSco(BluetoothAdapter, BluetoothDevice)}.
     *
     * @param adapter The BT adapter.
     * @param device The remote device.
     * @param isStart Whether the SCO channel should be opened.
     */
private void startStopSco(BluetoothAdapter adapter, BluetoothDevice device, boolean isStart) {
    long start = -1;
    int mask;
    String methodName;
    if (isStart) {
        methodName = String.format("startSco(device=%s)", device);
        mask = StartStopScoReceiver.STATE_CONNECTED_FLAG;
    } else {
        methodName = String.format("stopSco(device=%s)", device);
        mask = StartStopScoReceiver.STATE_DISCONNECTED_FLAG;
    }
    if (!adapter.isEnabled()) {
        fail(String.format("%s bluetooth not enabled", methodName));
    }
    if (!adapter.getBondedDevices().contains(device)) {
        fail(String.format("%s device not paired", methodName));
    }
    AudioManager manager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    assertNotNull(manager);
    if (!manager.isBluetoothScoAvailableOffCall()) {
        fail(String.format("%s device does not support SCO", methodName));
    }
    boolean isScoOn = manager.isBluetoothScoOn();
    if (isStart == isScoOn) {
        return;
    }
    StartStopScoReceiver receiver = getStartStopScoReceiver(mask);
    start = System.currentTimeMillis();
    if (isStart) {
        manager.startBluetoothSco();
    } else {
        manager.stopBluetoothSco();
    }
    long s = System.currentTimeMillis();
    while (System.currentTimeMillis() - s < START_STOP_SCO_TIMEOUT) {
        isScoOn = manager.isBluetoothScoOn();
        if (isStart == isScoOn && (receiver.getFiredFlags() & mask) == mask) {
            long finish = receiver.getCompletedTime();
            if (start != -1 && finish != -1) {
                writeOutput(String.format("%s completed in %d ms", methodName, (finish - start)));
            } else {
                writeOutput(String.format("%s completed", methodName));
            }
            removeReceiver(receiver);
            return;
        }
        sleep(POLL_TIME);
    }
    int firedFlags = receiver.getFiredFlags();
    removeReceiver(receiver);
    fail(String.format("%s timeout: on=%b (expected %b), flags=0x%x (expected 0x%x)", methodName, isScoOn, isStart, firedFlags, mask));
}
Also used : AudioManager(android.media.AudioManager)

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