1

I made Media Android TV application by using SimpleExoPlayer,

It can play some musics, some videos,

I want to track user when Mute|UnNute by using remote to trigger.

Therefore, I want to detect Mute|UnMute mode on current TV devices.

I research many pages, still not find out that,

Hope someone can help me the way,

Thank you,

p/s : These codes did not detect for Android TV

You can use AudioManager to check volume is mute or not mute.

AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
switch( audio.getRingerMode() ){
case AudioManager.RINGER_MODE_NORMAL:
break;
case AudioManager.RINGER_MODE_SILENT:
break;
case AudioManager.RINGER_MODE_VIBRATE:
break;
}
Huy Tower
  • 7,769
  • 16
  • 61
  • 86
  • Have you check [this SO post (Android: How to get app to remember if mute button has been pressed or not)](https://stackoverflow.com/questions/26849253/android-how-to-get-app-to-remember-if-mute-button-has-been-pressed-or-not)? – MαπμQμαπkγVπ.0 Feb 27 '19 at 09:02
  • I just find the way in the answer. – Huy Tower Feb 27 '19 at 10:30

1 Answers1

1

Currently I only get only this way to detect Mute|UnMute of Android system.

public static boolean isSoundOn(Context context) {
    AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    /*
     * It can detect
     *   - from Android 6.0 : Check Stream Music
     * */
    boolean isSoundOn = false;
    if (NlbUtil.isAndroidMarshmallow()) {
        // from Android 6.0 : Stream Music
        isSoundOn = am.getStreamVolume(AudioManager.STREAM_MUSIC) != 0;   // If no sound system, return true
        // isSoundOn = !am.isStreamMute(AudioManager.STREAM_MUSIC);
    }

    return isSoundOn;
}
Huy Tower
  • 7,769
  • 16
  • 61
  • 86