Skip to content

Getting Started

  1. Install the package

    Terminal window
    npm i @capgo/capacitor-mute
  2. Sync with native projects

    Terminal window
    npx cap sync

Import the plugin and use its methods to check mute state:

import { CapacitorMute } from '@capgo/capacitor-mute';
// Check if device is muted
const checkMuteState = async () => {
const { value } = await CapacitorMute.isMuted();
if (value) {
console.log('Device is muted/silent');
// Adjust app behavior for silent mode
} else {
console.log('Device sound is on');
}
};

Checks if the device is currently muted/in silent mode.

const result = await CapacitorMute.isMuted();
// Returns: { value: boolean }
import { CapacitorMute } from '@capgo/capacitor-mute';
export class SoundManager {
private isMuted = false;
async initialize() {
// Get initial mute state
await this.checkMuteState();
}
async checkMuteState() {
try {
const { value } = await CapacitorMute.isMuted();
this.isMuted = value;
this.updateAppBehavior();
} catch (error) {
console.error('Failed to check mute state:', error);
}
}
private updateAppBehavior() {
if (this.isMuted) {
// Device is muted - adjust app behavior
this.disableSoundEffects();
this.showVisualNotifications();
} else {
// Device sound is on
this.enableSoundEffects();
this.useAudioNotifications();
}
}
private disableSoundEffects() {
// Disable in-app sounds
console.log('Disabling sound effects');
}
private enableSoundEffects() {
// Enable in-app sounds
console.log('Enabling sound effects');
}
private showVisualNotifications() {
// Use visual feedback instead of audio
console.log('Using visual notifications');
}
private useAudioNotifications() {
// Use audio notifications
console.log('Using audio notifications');
}
}
// Usage
const soundManager = new SoundManager();
await soundManager.initialize();
// Poll periodically to check for changes
setInterval(() => {
soundManager.checkMuteState();
}, 5000); // Check every 5 seconds
  • Detects the physical mute switch state
  • No real-time change events (polling required)
  • Works on iPhone and iPad with mute switch
  • Checks if ringer mode is set to silent or vibrate
  • No change events (polling required)
  • Based on AudioManager ringer mode
  1. Poll for changes Since the plugin doesn’t provide real-time events, poll periodically if you need to track changes:

    // Check mute state periodically
    setInterval(async () => {
    const { value } = await CapacitorMute.isMuted();
    if (value !== previousMuteState) {
    handleMuteStateChange(value);
    }
    }, 5000);
  2. Respect user preferences Always honor the mute state and adjust your app’s audio behavior accordingly.

  3. Provide visual alternatives

    const { value: isMuted } = await CapacitorMute.isMuted();
    if (isMuted) {
    // Show visual notifications
    showToast('New message received');
    } else {
    // Play sound notification
    playNotificationSound();
    }
  1. Game Sound Management

    const shouldPlaySound = async () => {
    const { value: isMuted } = await CapacitorMute.isMuted();
    return !isMuted && userPreferences.soundEnabled;
    };
  2. Notification Handling

    const sendNotification = async (message: string) => {
    const { value: isMuted } = await CapacitorMute.isMuted();
    if (isMuted) {
    // Use vibration or visual notification
    await Haptics.vibrate();
    showBanner(message);
    } else {
    // Play notification sound
    await playSound('notification.mp3');
    }
    };
  3. Video Player

    const initVideoPlayer = async () => {
    const { value: isMuted } = await CapacitorMute.isMuted();
    videoPlayer.setMuted(isMuted);
    if (isMuted) {
    showSubtitles(true);
    showMuteIndicator();
    }
    };
  1. Always returns false on Android

    • Check if device ringer mode is actually set to silent
    • Some Android devices may have different behavior
  2. No change events available

    • The plugin does not provide real-time change events
    • Implement polling if you need to detect changes
  3. Not working on simulator

    • iOS Simulator doesn’t have a mute switch
    • Test on real devices for accurate results