Android examples for android.media:Audio
mute Audio Focus
import android.annotation.TargetApi; import android.content.Context; import android.media.AudioManager; import android.os.Build; public class Main { @TargetApi(Build.VERSION_CODES.FROYO)//from w w w . j a v a 2 s.c o m public static boolean muteAudioFocus(Context context, boolean bMute) { if (context == null) { return false; } // if (!VersionUtils.isrFroyo()) { // Log.d("ANDROID_LAB", "Android 2.1 and below can not stop music"); // return false; // } boolean bool = false; AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (bMute) { int result = am.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); bool = result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED; } else { int result = am.abandonAudioFocus(null); bool = result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED; } return bool; } }