private void restoreVolume() {
		if (mPrefs.getBoolean("cbxChangeVolume", false) && mAudioManager != null) {
			while (mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC) > oldStreamMusicVolume)
				mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, 0);
			while (mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC) < oldStreamMusicVolume)
				mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, 0);
			while (mAudioManager.getStreamVolume(AudioManager.STREAM_RING) < oldStreamRingtoneVolume)
				mAudioManager.adjustStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_RAISE, 0);			
		}
	}
	private void storeAndUpdateVolume() {
		if (mPrefs.getBoolean("cbxChangeVolume", false) && mAudioManager != null && mRingtoneThread == null) {
			int intOptionsTTSVolume = Math.min(mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC), Math.max(0, Integer.parseInt(mPrefs.getString("intOptionsTTSVolume", "14"))));
			oldStreamMusicVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
			oldStreamRingtoneVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_RING);
			while (mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC) < intOptionsTTSVolume)
				mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, 0);
			while (mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC) > intOptionsTTSVolume)
				mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, 0);
		}
	}
Example #3
0
 @Override
 public void onClick(View view) {
   switch (view.getId()) {
     case R.id.imgPlay:
       if (countClickButtonPlay % 2 == 0) {
         if (!mediaPlayer.isPlaying()) {
           seekBar.setMax((int) TimeUnit.MILLISECONDS.toSeconds(mediaPlayer.getDuration()));
           mediaPlayer.start();
           isPlaying = true;
           updateSeekBarThread = new Thread(updateSeekBar);
           updateSeekBarThread.start();
           imgPlay.setImageResource(R.drawable.ic_media_pause);
         }
       } else {
         if (mediaPlayer.isPlaying()) {
           mediaPlayer.pause();
           imgPlay.setImageResource(R.drawable.ic_media_play);
         }
       }
       countClickButtonPlay++;
       break;
     case R.id.imgSpeaker:
       AudioManager audioManager =
           (AudioManager) PlayActivity.this.getSystemService(Context.AUDIO_SERVICE);
       audioManager.adjustStreamVolume(
           AudioManager.STREAM_MUSIC, AudioManager.ADJUST_SAME, AudioManager.FLAG_SHOW_UI);
       break;
   }
 }
Example #4
0
  public void adjustStreamVolume(int streamType, int direction, int flags) {
    broadcastVolumeWillBeUpdated(streamType, EXTRA_VALUE_UNKNOWN);
    audioManager.adjustStreamVolume(streamType, direction, flags);
    if (streamType == AudioManager.STREAM_RING) {
      // Update ringer
      ringer.updateRingerMode();
    }

    int inCallStream = Compatibility.getInCallStream(userWantBluetooth);
    if (streamType == inCallStream) {
      int maxLevel = audioManager.getStreamMaxVolume(inCallStream);
      float modifiedLevel = (audioManager.getStreamVolume(inCallStream) / (float) maxLevel) * 10.0f;
      // Update default stream level
      service.getPrefs().setPreferenceFloatValue(SipConfigManager.SND_STREAM_LEVEL, modifiedLevel);
    }
  }
    @Override
    public boolean onPreferenceClick(Preference pref) {
      final Activity activity = getActivity();
      if (activity == null) {
        return false;
      }

      if (KEY_ALARM_VOLUME.equals(pref.getKey())) {
        final AudioManager audioManager =
            (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
        audioManager.adjustStreamVolume(
            AudioManager.STREAM_ALARM, AudioManager.ADJUST_SAME, AudioManager.FLAG_SHOW_UI);
        return true;
      }
      return false;
    }
  public static void adjust(int keyCode, boolean down) {
    AudioManager mAudioManager =
        (AudioManager) Receiver.mContext.getSystemService(Context.AUDIO_SERVICE);

    if (RtpStreamReceiver.speakermode == AudioManager.MODE_NORMAL)
      if (down ^ mAudioManager.getStreamVolume(stream()) == 0)
        mAudioManager.setStreamMute(stream(), down);
    if (down && down_time == 0) down_time = SystemClock.elapsedRealtime();
    if (!down ^ RtpStreamReceiver.speakermode != AudioManager.MODE_NORMAL)
      if (SystemClock.elapsedRealtime() - down_time < 500) {
        if (!down) down_time = 0;
        if (ogain > 1)
          if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            if (gain != ogain) {
              gain = ogain;
              return;
            }
            if (mAudioManager.getStreamVolume(stream())
                == mAudioManager.getStreamMaxVolume(stream())) return;
            gain = ogain / 2;
          } else {
            if (gain == ogain) {
              gain = ogain / 2;
              return;
            }
            if (mAudioManager.getStreamVolume(stream()) == 0) return;
            gain = ogain;
          }
        mAudioManager.adjustStreamVolume(
            stream(),
            keyCode == KeyEvent.KEYCODE_VOLUME_UP
                ? AudioManager.ADJUST_RAISE
                : AudioManager.ADJUST_LOWER,
            AudioManager.FLAG_SHOW_UI);
      }
    if (!down) down_time = 0;
  }
 /**
  * 调整程序声音类型为媒体播放声音,并且与媒体播放声音大小一致
  *
  * @param context
  */
 public static void adjustVoiceToSystemSame(Context context) {
   AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
   audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_SAME, 0);
 }
  /**
   * Allows the media keys to work when the keyguard is showing. The media keys should be of no
   * interest to the actual keyguard view(s), so intercepting them here should not be of any harm.
   *
   * @param event The key event
   * @return whether the event was consumed as a media key.
   */
  private boolean interceptMediaKey(KeyEvent event) {
    final int keyCode = event.getKeyCode();
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
      switch (keyCode) {
        case KeyEvent.KEYCODE_MEDIA_PLAY:
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
          /* Suppress PLAY/PAUSE toggle when phone is ringing or
           * in-call to avoid music playback */
          if (mTelephonyManager == null) {
            mTelephonyManager =
                (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
          }
          if (mTelephonyManager != null
              && mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE) {
            return true; // suppress key event
          }
        case KeyEvent.KEYCODE_MUTE:
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_STOP:
        case KeyEvent.KEYCODE_MEDIA_NEXT:
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
        case KeyEvent.KEYCODE_MEDIA_REWIND:
        case KeyEvent.KEYCODE_MEDIA_RECORD:
        case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
          {
            Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
            intent.putExtra(Intent.EXTRA_KEY_EVENT, event);
            getContext().sendOrderedBroadcast(intent, null);
            return true;
          }

        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_DOWN:
        case KeyEvent.KEYCODE_VOLUME_MUTE:
          {
            if (KEYGUARD_MANAGES_VOLUME) {
              synchronized (this) {
                if (mAudioManager == null) {
                  mAudioManager =
                      (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
                }
              }
              // Volume buttons should only function for music.
              if (mAudioManager.isMusicActive()) {
                if (keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
                  mAudioManager.toggleMute(AudioManager.STREAM_MUSIC);
                } else {
                  mAudioManager.adjustStreamVolume(
                      AudioManager.STREAM_MUSIC,
                      keyCode == KeyEvent.KEYCODE_VOLUME_UP
                          ? AudioManager.ADJUST_RAISE
                          : AudioManager.ADJUST_LOWER,
                      0);
                }
              }
              // Don't execute default volume behavior
              return true;
            } else {
              return false;
            }
          }
      }
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
      switch (keyCode) {
        case KeyEvent.KEYCODE_MUTE:
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY:
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
        case KeyEvent.KEYCODE_MEDIA_STOP:
        case KeyEvent.KEYCODE_MEDIA_NEXT:
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
        case KeyEvent.KEYCODE_MEDIA_REWIND:
        case KeyEvent.KEYCODE_MEDIA_RECORD:
        case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
          {
            Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
            intent.putExtra(Intent.EXTRA_KEY_EVENT, event);
            getContext().sendOrderedBroadcast(intent, null);
            return true;
          }
      }
    }
    return false;
  }
Example #9
0
    @Override
    public void run() {

      Log.d(
          "TEST_timer_func",
          "Task_started, count_pressed_func: "
              + count_pressed_func
              + ", isLong: "
              + long_pressed_func);

      if (long_pressed_func && count_pressed_func == 0) { // Долгое нажатие + 0 коротких
        Log.d("TEST_timer_func", "Lower volume");
        runOnUiThread(
            new Runnable() {

              @Override
              public void run() {
                tvAction.setText("Уменьшение громкости");
              }
            });
        audioManager.adjustStreamVolume(
            AudioManager.STREAM_MUSIC,
            AudioManager.ADJUST_LOWER,
            AudioManager.FLAG_SHOW_UI); // Уменьшается звук
      }

      switch (count_pressed_func) {
        case 2: // Кнопка зажата 1 раз
          Log.d("TEST_timer_main", "Action: previous track");
          runOnUiThread(
              new Runnable() {

                @Override
                public void run() {
                  tvAction.setText("Предыдущий трек");
                }
              });

          KeyEvent keyEvent3 =
              new KeyEvent(
                  KeyEvent.ACTION_DOWN,
                  KeyEvent
                      .KEYCODE_MEDIA_PREVIOUS); // Имитируется НАЖАТИЕ на кнопку с кодом
                                                // KEYCODE_MEDIA_PREVIOUS
          Intent intent3 = new Intent(Intent.ACTION_MEDIA_BUTTON);
          intent3.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent3);
          MainActivity.this.sendOrderedBroadcast(intent3, null);

          keyEvent3 =
              new KeyEvent(
                  KeyEvent.ACTION_UP,
                  KeyEvent
                      .KEYCODE_MEDIA_PREVIOUS); // Имитируется ОТЖАТИЕ на кнопку с кодом
                                                // KEYCODE_MEDIA_PREVIOUS
          intent3 = new Intent(Intent.ACTION_MEDIA_BUTTON);
          intent3.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent3);
          MainActivity.this.sendOrderedBroadcast(intent3, null);

          break;
      }

      count_signals_func = 0; // Устанавливется начальное количество полученных сигналов
      count_pressed_func = 0; // Устанавливется начальное кол-во нажатий: 0 шт
      long_pressed_func = false; // Устанавливется начальный флаг нажатий: false

      Timer temp2 = new Timer();
      temp2.schedule(new ActionTimer(), 2000);
    }
Example #10
0
    @Override
    public void run() {

      Log.d(
          "TEST_timer",
          "Task_started, count_pressed_main: "
              + count_pressed_main
              + ", isLong: "
              + long_pressed_main);

      if (long_pressed_main && count_pressed_main == 0) { // Долгое нажатие + 0 коротких
        Log.d("TEST_timer_main", "Raise volume");
        runOnUiThread(
            new Runnable() {

              @Override
              public void run() {
                tvAction.setText("Увеличение громкости"); // Отображение действия на экране
              }
            });

        audioManager.adjustStreamVolume(
            AudioManager.STREAM_MUSIC,
            AudioManager.ADJUST_RAISE,
            AudioManager.FLAG_SHOW_UI); // Увеличитвается звук
      }

      switch (count_pressed_main) {
        case 1: // Кнопка была нажата 1 раз
          Log.d("TEST_timer_main", "Action: play/pause");

          runOnUiThread(
              new Runnable() {

                @Override
                public void run() {
                  tvAction.setText("Воспроизведение/пуза"); // Отображение действия на экране
                }
              });

          int KeyCode; // Код кнопки зависит от

          if (audioManager
              .isMusicActive()) { // того, запущен ли плеер TODO: точно ли не музыка проигрывается?
            KeyCode = KeyEvent.KEYCODE_MEDIA_PAUSE; // Воспроизвести/Пауза
          } else {
            KeyCode = KeyEvent.KEYCODE_MEDIA_PLAY; // Принять вызов
          }

          KeyEvent keyEvent =
              new KeyEvent(
                  KeyEvent.ACTION_DOWN, KeyCode); // Имитируется НАЖАТИЕ на кнопку с кодом KeyCode
          Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
          intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
          MainActivity.this.sendOrderedBroadcast(intent, null);

          keyEvent =
              new KeyEvent(
                  KeyEvent.ACTION_UP, KeyCode); // Имитируется ОТЖАТИЕ на кнопку с кодом KeyCode
          intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
          intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
          MainActivity.this.sendOrderedBroadcast(intent, null);

          break;

        case 2:
          Log.d("TEST_timer_main", "Action: next track");
          runOnUiThread(
              new Runnable() {

                @Override
                public void run() {
                  tvAction.setText("Следующий трек"); // Отображение действия на экране
                }
              });

          KeyEvent keyEvent2 =
              new KeyEvent(
                  KeyEvent.ACTION_DOWN,
                  KeyEvent
                      .KEYCODE_MEDIA_NEXT); // Имитируется НАЖАТИЕ на кнопку с кодом
                                            // KEYCODE_MEDIA_NEXT
          Intent intent2 = new Intent(Intent.ACTION_MEDIA_BUTTON);
          intent2.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent2);
          MainActivity.this.sendOrderedBroadcast(intent2, null);

          keyEvent2 =
              new KeyEvent(
                  KeyEvent.ACTION_UP,
                  KeyEvent
                      .KEYCODE_MEDIA_NEXT); // Имитируется ОТЖАТИЕ на кнопку с кодом
                                            // KEYCODE_MEDIA_NEXT
          intent2 = new Intent(Intent.ACTION_MEDIA_BUTTON);
          intent2.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent2);
          MainActivity.this.sendOrderedBroadcast(intent2, null);

          break;
      }

      count_signals_main = 0; // Устанавливется начальное количество полученных сигналов
      count_pressed_main = 0; // Устанавливется начальное кол-во нажатий: 0 шт
      long_pressed_main = false; // Устанавливется начальный флаг нажатий: false

      Timer temp1 = new Timer();
      temp1.schedule(new ActionTimer(), 500);
    }
  @TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "setStreamVolume",
        args = {int.class, int.class, int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "getStreamMaxVolume",
        args = {int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "getStreamVolume",
        args = {int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "adjustStreamVolume",
        args = {int.class, int.class, int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "adjustSuggestedStreamVolume",
        args = {int.class, int.class, int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "adjustVolume",
        args = {int.class, int.class})
  })
  public void testVolume() throws Exception {
    int[] streams = {
      AudioManager.STREAM_ALARM,
      AudioManager.STREAM_MUSIC,
      AudioManager.STREAM_SYSTEM,
      AudioManager.STREAM_VOICE_CALL,
      AudioManager.STREAM_RING
    };

    mAudioManager.adjustVolume(ADJUST_RAISE, 100);
    mAudioManager.adjustSuggestedStreamVolume(ADJUST_LOWER, USE_DEFAULT_STREAM_TYPE, FLAG_SHOW_UI);

    for (int i = 0; i < streams.length; i++) {
      int maxVolume = mAudioManager.getStreamMaxVolume(streams[i]);

      mAudioManager.setStreamVolume(streams[i], 1, FLAG_SHOW_UI);
      assertEquals(1, mAudioManager.getStreamVolume(streams[i]));

      mAudioManager.setStreamVolume(streams[i], maxVolume, FLAG_SHOW_UI);
      mAudioManager.adjustStreamVolume(streams[i], ADJUST_RAISE, FLAG_SHOW_UI);
      assertEquals(maxVolume, mAudioManager.getStreamVolume(streams[i]));

      mAudioManager.adjustSuggestedStreamVolume(ADJUST_LOWER, streams[i], FLAG_SHOW_UI);
      assertEquals(maxVolume - 1, mAudioManager.getStreamVolume(streams[i]));

      // volume lower
      mAudioManager.setStreamVolume(streams[i], maxVolume, FLAG_SHOW_UI);
      for (int k = maxVolume; k > 0; k--) {
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_SHOW_UI);
        assertEquals(k - 1, mAudioManager.getStreamVolume(streams[i]));
      }

      mAudioManager.setRingerMode(RINGER_MODE_NORMAL);
      assertEquals(RINGER_MODE_NORMAL, mAudioManager.getRingerMode());
      mAudioManager.setStreamVolume(streams[i], 1, FLAG_SHOW_UI);
      assertEquals(1, mAudioManager.getStreamVolume(streams[i]));
      if (streams[i] == AudioManager.STREAM_RING) {
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_SHOW_UI);
        assertEquals(0, mAudioManager.getStreamVolume(streams[i]));
        // adjusting the volume to zero should result in either silent or vibrate mode
        assertTrue(
            mAudioManager.getRingerMode() == RINGER_MODE_VIBRATE
                || mAudioManager.getRingerMode() == RINGER_MODE_SILENT);
        mAudioManager.setRingerMode(RINGER_MODE_NORMAL);
        assertEquals(RINGER_MODE_NORMAL, mAudioManager.getRingerMode());
        assertEquals(1, mAudioManager.getStreamVolume(streams[i]));
      } else {
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_SHOW_UI);
        assertEquals(0, mAudioManager.getStreamVolume(streams[i]));
        // lowering the volume should NOT have changed the ringer mode
        assertEquals(RINGER_MODE_NORMAL, mAudioManager.getRingerMode());
        // API quirk: volume must be decremented from 1 to get ringer mode change
        mAudioManager.setStreamVolume(streams[i], 1, FLAG_SHOW_UI);
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_ALLOW_RINGER_MODES);
        // lowering the volume should have changed the ringer mode
        assertTrue(
            mAudioManager.getRingerMode() == RINGER_MODE_VIBRATE
                || mAudioManager.getRingerMode() == RINGER_MODE_SILENT);
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_ALLOW_RINGER_MODES);
        // adjusting the volume to zero should result in either silent or vibrate mode
        assertTrue(
            mAudioManager.getRingerMode() == RINGER_MODE_VIBRATE
                || mAudioManager.getRingerMode() == RINGER_MODE_SILENT);
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_RAISE, FLAG_ALLOW_RINGER_MODES);
        // There are two possible ways the device may work. It may have a silent/vibrate
        // mode or it may have distinct silent and vibrate modes.
        assertTrue(
            mAudioManager.getRingerMode() == RINGER_MODE_NORMAL
                || mAudioManager.getRingerMode() == RINGER_MODE_VIBRATE);
        // Increase the volume one more time to get out of the vibrate mode which may
        // be separate from silent mode.
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_RAISE, FLAG_ALLOW_RINGER_MODES);
        assertEquals(RINGER_MODE_NORMAL, mAudioManager.getRingerMode());
      }

      // volume raise
      mAudioManager.setStreamVolume(streams[i], 0, FLAG_SHOW_UI);
      for (int k = 0; k < maxVolume; k++) {
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_RAISE, FLAG_SHOW_UI);
        assertEquals(1 + k, mAudioManager.getStreamVolume(streams[i]));
      }

      // volume same
      mAudioManager.setStreamVolume(streams[i], maxVolume, FLAG_SHOW_UI);
      for (int k = 0; k < maxVolume; k++) {
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_SAME, FLAG_SHOW_UI);
        assertEquals(maxVolume, mAudioManager.getStreamVolume(streams[i]));
      }

      mAudioManager.setStreamVolume(streams[i], maxVolume, FLAG_SHOW_UI);
    }

    // adjust volume
    int maxVolume = mAudioManager.getStreamMaxVolume(STREAM_MUSIC);
    mAudioManager.adjustVolume(ADJUST_RAISE, 100);

    MediaPlayer mp = MediaPlayer.create(mContext, MP3_TO_PLAY);
    mp.setAudioStreamType(STREAM_MUSIC);
    mp.setLooping(true);
    mp.start();
    Thread.sleep(TIME_TO_PLAY);
    assertTrue(mAudioManager.isMusicActive());

    // adjust volume as ADJUST_SAME
    for (int k = 0; k < maxVolume; k++) {
      mAudioManager.adjustVolume(ADJUST_SAME, FLAG_SHOW_UI);
      assertEquals(maxVolume, mAudioManager.getStreamVolume(STREAM_MUSIC));
    }

    // adjust volume as ADJUST_RAISE
    mAudioManager.setStreamVolume(STREAM_MUSIC, 1, FLAG_SHOW_UI);
    for (int k = 0; k < maxVolume - 1; k++) {
      mAudioManager.adjustVolume(ADJUST_RAISE, FLAG_SHOW_UI);
      assertEquals(2 + k, mAudioManager.getStreamVolume(STREAM_MUSIC));
    }

    // adjust volume as ADJUST_LOWER
    mAudioManager.setStreamVolume(STREAM_MUSIC, maxVolume, FLAG_SHOW_UI);
    maxVolume = mAudioManager.getStreamVolume(STREAM_MUSIC);

    mAudioManager.adjustVolume(ADJUST_LOWER, FLAG_SHOW_UI);
    assertEquals(maxVolume - 1, mAudioManager.getStreamVolume(STREAM_MUSIC));
    mp.stop();
    mp.release();
    Thread.sleep(TIME_TO_PLAY);
    assertFalse(mAudioManager.isMusicActive());
  }