Upgrade to Pro — share decks privately, control downloads, hide ads and more …

音声アプリにおけるバックグラウンド再生Tips.pdf

entaku
February 22, 2022
850

 音声アプリにおけるバックグラウンド再生Tips.pdf

entaku

February 22, 2022
Tweet

More Decks by entaku

Transcript

  1. Ի੠ΞϓϦʹ͓͚Δ όοΫάϥ΢ϯυ࠶ੜ Tips entaku

  2. entaku • Name: entaku • Job: iOS/AndroidΤϯδχΞͳͲ • SIer໿6೥ •

    εϙʔπϚονϯάΞϓϦ1೥ • ෺ྲྀITαʔϏε ໿2೥ • Voicy ->New • Twitter • @entaku_0818
  3. Voicy https://corp.voicy.jp/ https://voicy.jp/

  4. Voicy https://apps.apple.com/jp/app/voicy-recorder/id1115553195 iOS Android

  5. ࠓճͷςʔϚ

  6. ໰୊ • Voicyௌ͖ͳ͕ΒଞͷԻָྲྀΕΔܥίϯςϯπ ͷβοϐϯά͕Ͱ͖ͳ͍

  7. AVAudioSession https://developer.apple.com/documentation/avfaudio/avaudiose • ΞϓϦͰར༻͢ΔԻ੠ͷछྨͳͲΛઃఆ

  8. AVAudioSession ͷαϯϓϧίʔυ /// Set session category. @available(iOS 3.0, *) open

    func setCategory(_ category: AVAudioSession.Category) throws /// Set session category with options. @available(iOS 6.0, *) open func setCategory(_ category: AVAudioSession.Category, options: AVAudioSession.CategoryOptions = []) throws /// Set session category and mode with options. @available(iOS 10.0, *) open func setCategory(_ category: AVAudioSession.Category, mode: AVAudioSession.Mode, options: AVAudioSession.CategoryOptions = []) throws
  9. AVAudioSession ͷαϯϓϧίʔυ /// Set session category. @available(iOS 3.0, *) open

    func setCategory(_ category: AVAudioSession.Category) throws /// Set session category with options. @available(iOS 6.0, *) open func setCategory(_ category: AVAudioSession.Category, options: AVAudioSession.CategoryOptions = []) throws /// Set session category and mode with options. @available(iOS 10.0, *) open func setCategory(_ category: AVAudioSession.Category, mode: AVAudioSession.Mode, options: AVAudioSession.CategoryOptions = []) throws • VoicyͰར༻
  10. AVAudioSession - category • soloAmbient • ΦʔσΟΦΛόοΫάϥϯυΦʔσΟΦͱϛοΫε͠ͳ͍ΞϓϦ༻ʢσϑΥϧτʣ ͷΧςΰϦͰ͢ɻ • ambient

    • ΦʔσΟΦΛόοΫάϥϯυΦʔσΟΦͱϛοΫε͢ΔΞϓϦ༻ʢϘλϯԻ΍ ΧʔφϏԻ੠Ҋ಺ͷΈͳͲʣͷΧςΰϦͰ͢ɻ • playback • ΦʔσΟΦ࠶ੜ༻ͷΧςΰϦͰ͢ɻ • record • ΦʔσΟΦ࿥Ի༻ͷΧςΰϦͰ͢ɻ https://developer.apple.com/documentation/avfaudio/avaudiosession/category
  11. AVAudioSession - category • playAndRecord • ΦʔσΟΦ࠶ੜͱ࿥ԻΛ྆ํߦ͏ΞϓϦ༻ʢVoIPͳͲʣͷΧςΰϦͰ͢ɻ • multiRoute •

    ΦʔσΟΦΛҟͳΔσόΠεʹಉ࣌ग़ྗ͢ΔΞϓϦ༻ͷΧςΰϦͰ͢ɻ https://developer.apple.com/documentation/avfaudio/avaudiosession/category
  12. AVAudioSession - Mode • default • σϑΥϧτͷϞʔυͰ͢ɻ • gameChat •

    ήʔϜνϟοτͰͷར༻Λࣔ͢ϞʔυͰ͢ɻ • measurement • ΦʔσΟΦೖग़ྗͷଌఆͰͷར༻Λࣔ͢ϞʔυͰ͢ɻ • moviePlayback • өը࠶ੜͰͷར༻Λࣔ͢ϞʔυͰ͢ɻ https://developer.apple.com/documentation/avfaudio/avaudiosession/category
  13. AVAudioSession - Mode • spokenAudio • Ի੠ͷׂΓࠐΈ͕͋ΔΞϓϦͰͷར༻Λࣔ͢ϞʔυͰ͢ɻΧʔφϏԻ੠Ҋ಺ͳͲɺ୹ׂ͍ΓࠐΈͷࡍʹ࠶ੜதͷ΋ ͷΛҰ࣌ఀࢭ͠ɺऴΘΓ࣍ୈ࠶։͠·͢ɻ • videoChat

    • ΦϯϥΠϯϏσΦձٞͰͷར༻Λࣔ͢ϞʔυͰ͢ɻ • videoRecording • ಈը࿥ըͰͷར༻Λࣔ͢ϞʔυͰ͢ɻ • voiceChat • VoIPͳͲͷ૒ํ޲ͷԻ੠௨৴Ͱͷར༻Λࣔ͢ϞʔυͰ͢ɻ • voicePrompt • ςΩετಡΈ্͛Λ࢖༻ͨ͠Ի੠࠶ੜͰͷར༻Λࣔ͢ϞʔυͰ͢ɻ https://developer.apple.com/documentation/avfaudio/avaudiosession/mode/
  14. AVAudioSession - Option • mixWithOthers • ΦʔσΟΦ͕όοΫάϥ΢ϯυΦʔσΟΦͱϛοΫε͢Δ͜ͱΛࣔ͢Φϓγϣϯɻ • duckOthers •

    ΦʔσΟΦ࠶ੜ࣌ʹɺόοΫάϥ΢ϯυΦʔσΟΦͷԻྔΛԼ͛ΔΦϓγϣϯɻ • InterruptSpokenAudioAndMixWithOthers • ΦʔσΟΦΛ࠶ੜ࣌ʹɺόοΫάϥ΢ϯυΦʔσΟΦΛҰ࣌ఀࢭ͢Δ͔Ͳ͏͔Λܾఆ͢ΔΦ ϓγϣϯɻ • allowBluetooth • BluetoothϋϯζϑϦʔσόΠεΛ࢖༻Մೳͳೖྗϧʔτͱͯ͠දࣔ͢Δ͔Ͳ͏͔Λܾఆ͢Δ Φϓγϣϯɻ https://developer.apple.com/documentation/avfaudio/avaudiosession/ categoryoptions
  15. AVAudioSession - Option • spokenAudio • Ի੠ͷׂΓࠐΈ͕͋ΔΞϓϦͰͷར༻Λࣔ͢ϞʔυͰ͢ɻΧʔφϏԻ੠Ҋ಺ͳͲɺ୹ׂ͍ΓࠐΈͷࡍʹ࠶ੜதͷ΋ ͷΛҰ࣌ఀࢭ͠ɺऴΘΓ࣍ୈ࠶։͠·͢ɻ • videoChat

    • ΦϯϥΠϯϏσΦձٞͰͷར༻Λࣔ͢ϞʔυͰ͢ɻ • videoRecording • ಈը࿥ըͰͷར༻Λࣔ͢ϞʔυͰ͢ɻ • voiceChat • VoIPͳͲͷ૒ํ޲ͷԻ੠௨৴Ͱͷར༻Λࣔ͢ϞʔυͰ͢ɻ • voicePrompt • ςΩετಡΈ্͛Λ࢖༻ͨ͠Ի੠࠶ੜͰͷར༻Λࣔ͢ϞʔυͰ͢ɻ https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions
  16. AVAudioSessionͬͯͨ͘͞Μ ઃఆ͕͋ΔΜͩͶʂ

  17. Ͱ݁ہͲ͏͢Μͷʁ

  18. AVAudioSession ͷαϯϓϧίʔυ ɹɹɹɹɹtry? audioSession.setCategory(AVAudioSession.Category.playback) OR ɹɹɹɹɹtry? audioSession.setCategory(AVAudioSession.Category.soloAmbient) OR ɹɹɹɹ// background

    try? audioSession.setCategory(AVAudioSession.Category.ambient, options: AVAudioSession.CategoryOptions.mixWithOthers) ※ίʔυ͸ΠϝʔδͰ͢
  19. backGround͔Ͳ͏͔ͷ൑ఆ ɹɹɹɹɹif (secondaryAudioShouldBeSilencedHint){ ɹ// background try? audioSession.setCategory(AVAudioSession.Category.ambient, options: AVAudioSession.CategoryOptions.mixWithOthers) }else{

    // forground // Ϣʔβʔͷঢ়ଶʹΑͬͯ࢖͍෼͚ try? audioSession.setCategory(AVAudioSession.Category.playback) OR ɹɹɹɹɹtry? audioSession.setCategory(AVAudioSession.Category.soloAmbient) } ɹɹɹ ※ίʔυ͸ΠϝʔδͰ͢
  20. backGround͔Ͳ͏͔ͷ൑ఆ https://developer.apple.com/documentation/avfaudio/avaudiosession/1616600-secondaryaudioshouldbesilencedhi • This property returns true if any other

    audio is playing, including audio from an app using the ambient category. Most apps should instead use the secondaryAudioShouldBeSilencedHint property, because it’s more restrictive when considering whether primary audio from another app is playing. https://developer.apple.com/documentation/avfaudio/avaudiosession/1616610-isotheraudioplaying • secondaryAudioShouldBeSilencedHintΛ ࢖͏
  21. BackGround࠶ੜͰؾΛ͚ͭΔ ͜ͱ • AVAudioSessionͷछྨ͸ͨ͘͞Μ͋ΔͷͰࣗ෼ͷΞϓϦͰͲͷ ઃఆ͕߹͍ͬͯΔͷ͔͸֬ೝ͢Δඞཁ͕͋Δ • Ի੠͕όοΫάϥ΢ϯυʹདྷ͍ͯΔ͔Ͳ͏͔͸ secondaryAudioShouldBeSilencedHintΛ࢖͏ • isOtherAudioPlayingࣄྫ͋ͬͨΒڭ͍͑ͯͩ͘͠

  22. ࠷ޙʹ

  23. https://voicy.jp/search/entaku ฉ͍ͯ͘ΕΑͳ😊

  24. https://www.wantedly.com/projects/619248 Ԡԉ͚ͩͯ͘͠ΕΑͳ😊