[Flutter] Audio Cache에서 BGM을 틀 때 아이폰이면 매너 모드를 관통할 수 있어요.
이른바 오디오 캐시
AudioCache는 플루터제 오디오 프레임audioplayers에서 사운드 재생에 사용되는 대상이다.자세한 내용은 여기.의 공식 페이지를 보십시오.
이번에는 제가 평소에 사용하던 말을 소홀히 하도록 허락해 주세요.🙇♂️
아이폰은 매너 모드에서도 재생이 가능합니다.
본론입니다.
AudioCahce BGM을 틀면 진동 모드(음소거 스위치 켜기)라도 음악을 틀어준다.AudioCache _bgmCache = AudioCache(fixedPlayer: new AudioPlayer());
_bgmCache.loop(sound.filePath, volume: volume);    // マナーモード貫通.
 먼저 결론을 쓰면isNotification 사실이고 예의 모드에서는 침묵한다.AudioCache _bgmCache = AudioCache(fixedPlayer: new AudioPlayer());
_bgmCache.loop(sound.filePath, volume: volume, isNotification: true);
 결말이 좋다왜?
말하자면 아이폰의 예의 모델은 왜 시종일관 관철되었을까?
AVAudioSession.Category 설정playback이기 때문이다.audioplayers 포장에 SwiftAudioplayersPlugin#configureAudioSession 설치된 것 같아요.    private func configureAudioSession(
        category: AVAudioSession.Category? = nil,
        options: AVAudioSession.CategoryOptions = [],
        active: Bool? = nil
    ) {
        do {
            let session = AVAudioSession.sharedInstance()
            if let category = category {
                try session.setCategory(category, options: options)
            }
            if let active = active {
                try session.setActive(active)
            }
        } catch {
            log("Error configuring audio session: %@", error)
        }
    }
 또configureAudioSession는 updateCategory라고 불린다.    func updateCategory(
        recordingActive: Bool,
        isNotification: Bool,
        playingRoute: String,
        duckAudio: Bool
    ) {
        #if os(iOS)
        // When using AVAudioSessionCategoryPlayback, by default, this implies that your app’s audio is nonmixable—activating your session
        // will interrupt any other audio sessions which are also nonmixable. AVAudioSessionCategoryPlayback should not be used with
        // AVAudioSessionCategoryOptionMixWithOthers option. If so, it prevents infoCenter from working correctly.
        let category = (playingRoute == "earpiece" || recordingActive) ? AVAudioSession.Category.playAndRecord : (
            isNotification ? AVAudioSession.Category.ambient : AVAudioSession.Category.playback
        )
        let options = isNotification || duckAudio ? AVAudioSession.CategoryOptions.mixWithOthers : []
        
        configureAudioSession(category: category, options: options)
        if isNotification {
            UIApplication.shared.beginReceivingRemoteControlEvents()
        }
        #endif
    }
 다음 부분에 매우 신경을 쓴다.대답이라든가.let category = (playingRoute == "earpiece" || recordingActive) ? AVAudioSession.Category.playAndRecord : (
            isNotification ? AVAudioSession.Category.ambient : AVAudioSession.Category.playback
        )
 설정AVAudioSession.Category.playback 이후에도 백그라운드에서 재생이 계속되며 자동 모드에서도 재생됩니다.참조: https://qiita.com/pandapanda/items/1c87fa0115a8bcba51a6#음소거 모드에서 울리기
그래서
isNotification를 진짜로 만들어 안에 지정ambient한 것 같다.어플리케이션에 따라
soloAmbient도 선택할 수 있습니다.그런데 보통 기본적으로 예의범절을 관철하지 않으려는 사람은 나뿐인가?w
도움이 됐으면 좋겠어요.
Reference
이 문제에 관하여([Flutter] Audio Cache에서 BGM을 틀 때 아이폰이면 매너 모드를 관통할 수 있어요.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/asteroid/articles/3021e4a64a6970텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)