시작하기
-
패키지 설치
Terminal window npm i @capgo/capacitor-muteTerminal window pnpm add @capgo/capacitor-muteTerminal window yarn add @capgo/capacitor-muteTerminal window bun add @capgo/capacitor-mute -
네이티브 프로젝트와 동기화
Terminal window npx cap syncTerminal window pnpm cap syncTerminal window yarn cap syncTerminal window bunx cap sync
플러그인을 가져와서 메서드를 사용하여 무음 상태를 확인하세요:
import { CapacitorMute } from '@capgo/capacitor-mute';
// 기기가 무음인지 확인const checkMuteState = async () => { const { value } = await CapacitorMute.isMuted();
if (value) { console.log('Device is muted/silent'); // 무음 모드에 맞게 앱 동작 조정 } else { console.log('Device sound is on'); }};API 참조
Section titled “API 참조”isMuted()
Section titled “isMuted()”기기가 현재 무음/무음 모드인지 확인합니다.
const result = await CapacitorMute.isMuted();// 반환: { value: boolean }완전한 예제
Section titled “완전한 예제”import { CapacitorMute } from '@capgo/capacitor-mute';
export class SoundManager { private isMuted = false;
async initialize() { // 초기 무음 상태 가져오기 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) { // 기기가 무음 - 앱 동작 조정 this.disableSoundEffects(); this.showVisualNotifications(); } else { // 기기 사운드가 켜짐 this.enableSoundEffects(); this.useAudioNotifications(); } }
private disableSoundEffects() { // 앱 내 사운드 비활성화 console.log('Disabling sound effects'); }
private enableSoundEffects() { // 앱 내 사운드 활성화 console.log('Enabling sound effects'); }
private showVisualNotifications() { // 오디오 대신 시각적 피드백 사용 console.log('Using visual notifications'); }
private useAudioNotifications() { // 오디오 알림 사용 console.log('Using audio notifications'); }}
// 사용법const soundManager = new SoundManager();await soundManager.initialize();
// 주기적으로 폴링하여 변경 사항 확인setInterval(() => { soundManager.checkMuteState();}, 5000); // 5초마다 확인플랫폼 동작
Section titled “플랫폼 동작”- 물리적 무음 스위치 상태 감지
- 실시간 변경 이벤트 없음 (폴링 필요)
- 무음 스위치가 있는 iPhone 및 iPad에서 작동
Android
Section titled “Android”- 벨소리 모드가 무음 또는 진동으로 설정되어 있는지 확인
- 변경 이벤트 없음 (폴링 필요)
- AudioManager 벨소리 모드 기반
-
변경 사항 폴링 플러그인이 실시간 이벤트를 제공하지 않으므로 변경 사항을 추적해야 하는 경우 주기적으로 폴링하세요:
// 주기적으로 무음 상태 확인setInterval(async () => {const { value } = await CapacitorMute.isMuted();if (value !== previousMuteState) {handleMuteStateChange(value);}}, 5000); -
사용자 기본 설정 존중 항상 무음 상태를 존중하고 앱의 오디오 동작을 그에 맞게 조정하세요.
-
시각적 대안 제공
const { value: isMuted } = await CapacitorMute.isMuted();if (isMuted) {// 시각적 알림 표시showToast('New message received');} else {// 사운드 알림 재생playNotificationSound();}
-
게임 사운드 관리
const shouldPlaySound = async () => {const { value: isMuted } = await CapacitorMute.isMuted();return !isMuted && userPreferences.soundEnabled;}; -
알림 처리
const sendNotification = async (message: string) => {const { value: isMuted } = await CapacitorMute.isMuted();if (isMuted) {// 진동 또는 시각적 알림 사용await Haptics.vibrate();showBanner(message);} else {// 알림 사운드 재생await playSound('notification.mp3');}}; -
비디오 플레이어
const initVideoPlayer = async () => {const { value: isMuted } = await CapacitorMute.isMuted();videoPlayer.setMuted(isMuted);if (isMuted) {showSubtitles(true);showMuteIndicator();}};
-
Android에서 항상 false 반환
- 기기 벨소리 모드가 실제로 무음으로 설정되어 있는지 확인
- 일부 Android 기기는 다른 동작을 보일 수 있음
-
변경 이벤트를 사용할 수 없음
- 플러그인은 실시간 변경 이벤트를 제공하지 않음
- 변경 사항을 감지해야 하는 경우 폴링 구현
-
시뮬레이터에서 작동하지 않음
- iOS 시뮬레이터에는 무음 스위치가 없음
- 정확한 결과를 얻으려면 실제 기기에서 테스트