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

AVAudioSessionの全体像を掴む.pdf

entaku
November 03, 2024
38

 AVAudioSessionの全体像を掴む.pdf

entaku

November 03, 2024
Tweet

Transcript

  1. ࣗݾ঺հ • Name: entaku • Work: Voicy • X: https://x.com/entaku_0818

    • Hobby: ԻָϑΣε/ݸਓ։ൃ • Other: SwiftѪ޷ձӡӦ (https://love-swift.connpass.com/)
  2. AVAudioSession 1. ໾ׂɿ • ΞϓϦͱOS/ϋʔυ΢ΣΞؒͷڮ౉͠ • ΞϓϦͷΦʔσΟΦͷҰൠతͳੑ࣭ΛOSʹ఻͑Δ 2. ಛ௃ɿ •

    ۩ମతͳಈ࡞΍ϋʔυ΢ΣΞͱͷৄࡉͳ΍ΓऔΓΛࢦఆ͢Δඞཁ͕ͳ͍ • ͦΕΒͷৄࡉͳ؅ཧ͸ΦʔσΟΦηογϣϯʹҕ೚͞ΕΔ 3. ϝϦοτɿ • OS͕ϢʔβʔͷΦʔσΟΦମݧΛ࠷దʹ؅ཧͰ͖Δ • ։ൃऀ͸௿Ϩϕϧͷ࣮૷ৄࡉΛؾʹ͢Δඞཁ͕ͳ͍ •ΦʔσΟΦηογϣϯ͸ɺΞϓϦͱΦϖϨʔ ςΟϯάγεςϜͱͷؒͷ஥հ໾ͱͯ͠ػೳ͠ ·͢ɻ •ΦʔσΟΦηογϣϯΛ࢖༻͢Δ͜ͱͰɺΦʔ σΟΦϋʔυ΢ΣΞͱͷ۩ମతͳಈ࡞΍ඞཁͳ ૬ޓ࡞༻Λৄࡉʹࣔ͢͜ͱͳ͘ɺΞϓϦͷΦʔ σΟΦͷҰൠతͳੑ࣭ΛΦϖϨʔςΟϯάγε ςϜʹ఻͑Δ͜ͱ͕Ͱ͖·͢ɻ
  3. AVAudioSession Category 1. ambient • ଞΞϓϦͷԻ੠ͱࠞ߹࠶ੜ • BGMɺޮՌԻ޲͚ • αΠϨϯτϞʔυͰ͸࠶ੜఀࢭ

    • ϢʔεέʔεɿิॿతͳޮՌԻ͕ඞཁͳ࣌ 2. soloAmbient • ଞΞϓϦͷԻ੠Λதஅ • σϑΥϧτΧςΰϦ • αΠϨϯτϞʔυͰ͸࠶ੜఀࢭ • Ϣʔεέʔεɿ୯ಠͷԻ੠࠶ੜ 3. playback • όοΫάϥ΢ϯυ࠶ੜରԠ • αΠϨϯτϞʔυͰ΋࠶ੜܧଓ • ଞΞϓϦͷԻ੠Λதஅ • ϢʔεέʔεɿԻָϓϨʔϠʔɺಈըϓϨʔϠʔ 4. record • ࿥ԻʹಛԽ • ଞΞϓϦͷԻ੠Λதஅ • ೖྗʹ࠷దԽ • ϢʔεέʔεɿϘΠεϝϞɺ࿥ԻΞϓϦ 5. playAndRecord • ಉ࣌ʹ࿥Իͱ࠶ੜ͕Մೳ • ૒ํ޲௨৴ʹରԠ • ϏσΦνϟοτɺVoIP޲͚ • Ϣʔεέʔεɿ௨࿩ΞϓϦɺϏσΦձٞ 6. multiRoute • ෳ਺ͷೖग़ྗϧʔτΛಉ࣌࢖༻ • ϓϩ޲͚ΦʔσΟΦػೳ • ߴ౓ͳ੍ޚ͕Մೳ • ϢʔεέʔεɿDJ ΞϓϦɺԻ੍ָ࡞ΞϓϦ
  4. AVAudioSession Category 1. ambient • ଞΞϓϦͷԻ੠ͱࠞ߹࠶ੜ • BGMɺޮՌԻ޲͚ • αΠϨϯτϞʔυͰ͸࠶ੜఀࢭ

    • ϢʔεέʔεɿิॿతͳޮՌԻ͕ඞཁͳ࣌ 2. soloAmbient • ଞΞϓϦͷԻ੠Λதஅ • σϑΥϧτΧςΰϦ • αΠϨϯτϞʔυͰ͸࠶ੜఀࢭ • Ϣʔεέʔεɿ୯ಠͷԻ੠࠶ੜ 3. playback • όοΫάϥ΢ϯυ࠶ੜରԠ • αΠϨϯτϞʔυͰ΋࠶ੜܧଓ • ଞΞϓϦͷԻ੠Λதஅ • ϢʔεέʔεɿԻָϓϨʔϠʔɺಈըϓϨʔ Ϡʔ 4. record • ࿥ԻʹಛԽ • ଞΞϓϦͷԻ੠Λதஅ • ೖྗʹ࠷దԽ • ϢʔεέʔεɿϘΠεϝϞɺ࿥ԻΞϓϦ 5. playAndRecord • ಉ࣌ʹ࿥Իͱ࠶ੜ͕Մೳ • ૒ํ޲௨৴ʹରԠ • ϏσΦνϟοτɺVoIP޲͚ • Ϣʔεέʔεɿ௨࿩ΞϓϦɺϏσΦձٞ 6. multiRoute • ෳ਺ͷೖग़ྗϧʔτΛಉ࣌࢖༻ • ϓϩ޲͚ΦʔσΟΦػೳ • ߴ౓ͳ੍ޚ͕Մೳ • ϢʔεέʔεɿDJ ΞϓϦɺԻ੍ָ࡞ΞϓϦ
  5. AVAudioSession Category 1. ambient • ଞΞϓϦͷԻ੠ͱࠞ߹࠶ੜ • BGMɺޮՌԻ޲͚ • αΠϨϯτϞʔυͰ͸࠶ੜఀࢭ

    • ϢʔεέʔεɿิॿతͳޮՌԻ͕ඞཁͳ࣌ 2. soloAmbient • ଞΞϓϦͷԻ੠Λதஅ • σϑΥϧτΧςΰϦ • αΠϨϯτϞʔυͰ͸࠶ੜఀࢭ • Ϣʔεέʔεɿ୯ಠͷԻ੠࠶ੜ 3. playback • όοΫάϥ΢ϯυ࠶ੜରԠ • αΠϨϯτϞʔυͰ΋࠶ੜܧଓ • ଞΞϓϦͷԻ੠Λதஅ • ϢʔεέʔεɿԻָϓϨʔϠʔɺಈըϓϨʔ Ϡʔ 4. record • ࿥ԻʹಛԽ • ଞΞϓϦͷԻ੠Λதஅ • ೖྗʹ࠷దԽ • ϢʔεέʔεɿϘΠεϝϞɺ࿥ԻΞϓϦ 5. playAndRecord • ಉ࣌ʹ࿥Իͱ࠶ੜ͕Մೳ • ૒ํ޲௨৴ʹରԠ • ϏσΦνϟοτɺVoIP޲͚ • Ϣʔεέʔεɿ௨࿩ΞϓϦɺϏσΦձٞ 6. multiRoute • ෳ਺ͷೖग़ྗϧʔτΛಉ࣌࢖༻ • ϓϩ޲͚ΦʔσΟΦػೳ • ߴ౓ͳ੍ޚ͕Մೳ • ϢʔεέʔεɿDJ ΞϓϦɺԻ੍ָ࡞ΞϓϦ 1. ໾ׂɿ • ΞϓϦͱOS/ϋʔυ΢ΣΞؒͷڮ౉͠ • ΞϓϦͷΦʔσΟΦͷҰൠతͳੑ࣭ΛOSʹ఻͑Δ 2. ಛ௃ɿ • ۩ମతͳಈ࡞΍ϋʔυ΢ΣΞͱͷৄࡉͳ΍ΓऔΓΛࢦఆ͢Δඞཁ͕ͳ͍ • ͦΕΒͷৄࡉͳ؅ཧ͸ΦʔσΟΦηογϣϯʹҕ೚͞ΕΔ 3. ϝϦοτɿ • OS͕ϢʔβʔͷΦʔσΟΦମݧΛ࠷దʹ؅ཧͰ͖Δ • ։ൃऀ͸௿Ϩϕϧͷ࣮૷ৄࡉΛؾʹ͢Δඞཁ͕ͳ͍ ͲΜͳΞϓϦʹ͢Δ͔ʁ ར༻༻్ͰΧςΰϦΛબͿ
  6. AVAudioSession Mode 1. default • جຊతͳԻ੠࠶ੜ༻ • ಛผͳ࠷దԽͳ͠ • ҰൠతͳΞϓϦͷඪ४ઃఆ

    2. moviePlayback • ಈը࠶ੜʹ࠷దԽʢ48kHzʣ • όοϑΝαΠζΛେ͖͘ઃఆ • ಈըϓϨʔϠʔΞϓϦ޲͚ 3. videoRecording • ߴԻ࣭࿥Իʢ96kHzʣ • ࠷খݶͷϨΠςϯγʔ • ΧϝϥΞϓϦͷ࿥ըػೳ޲͚ 4.voiceChat/videoChat • ΤίʔΩϟϯηϧػೳ • ௿ϨΠςϯγʔઃఆ • ௨࿩ΞϓϦɺϏσΦձٞ޲͚ 5.gameChat • ήʔϜޮՌԻͱͷཱ྆ • ௿ϨΠςϯγʔ • ϚϧνϓϨΠϠʔήʔϜ޲͚ 6.measurement • ৴߸ॲཧΛ࠷খݶʹ • ਖ਼֬ͳԻ੠ଌఆ༻ • Ի੠෼ੳΞϓϦ޲͚ 7.spokenAudio • Ի੠໌ྎ౓ॏࢹ • ϙουΩϟετɺΦʔσΟΦϒοΫ޲͚ • Ի੠ίϯςϯπ࠶ੜ༻
  7. AVAudioSession Mode 1. default • جຊతͳԻ੠࠶ੜ༻ • ಛผͳ࠷దԽͳ͠ • ҰൠతͳΞϓϦͷඪ४ઃఆ

    2. moviePlayback • ಈը࠶ੜʹ࠷దԽʢ48kHzʣ • όοϑΝαΠζΛେ͖͘ઃఆ • ಈըϓϨʔϠʔΞϓϦ޲͚ 3. videoRecording • ߴԻ࣭࿥Իʢ96kHzʣ • ࠷খݶͷϨΠςϯγʔ • ΧϝϥΞϓϦͷ࿥ըػೳ޲͚ 4.voiceChat/videoChat • ΤίʔΩϟϯηϧػೳ • ௿ϨΠςϯγʔઃఆ • ௨࿩ΞϓϦɺϏσΦձٞ޲͚ 5.gameChat • ήʔϜޮՌԻͱͷཱ྆ • ௿ϨΠςϯγʔ • ϚϧνϓϨΠϠʔήʔϜ޲͚ 6.measurement • ৴߸ॲཧΛ࠷খݶʹ • ਖ਼֬ͳԻ੠ଌఆ༻ • Ի੠෼ੳΞϓϦ޲͚ 7.spokenAudio • Ի੠໌ྎ౓ॏࢹ • ϙουΩϟετɺΦʔσΟΦϒοΫ޲͚ • Ի੠ίϯςϯπ࠶ੜ༻
  8. AVAudioSession Mode 1. default • جຊతͳԻ੠࠶ੜ༻ • ಛผͳ࠷దԽͳ͠ • ҰൠతͳΞϓϦͷඪ४ઃఆ

    2. moviePlayback • ಈը࠶ੜʹ࠷దԽʢ48kHzʣ • όοϑΝαΠζΛେ͖͘ઃఆ • ಈըϓϨʔϠʔΞϓϦ޲͚ 3. videoRecording • ߴԻ࣭࿥Իʢ96kHzʣ • ࠷খݶͷϨΠςϯγʔ • ΧϝϥΞϓϦͷ࿥ըػೳ޲͚ 4.voiceChat/videoChat • ΤίʔΩϟϯηϧػೳ • ௿ϨΠςϯγʔઃఆ • ௨࿩ΞϓϦɺϏσΦձٞ޲͚ 5.gameChat • ήʔϜޮՌԻͱͷཱ྆ • ௿ϨΠςϯγʔ • ϚϧνϓϨΠϠʔήʔϜ޲͚ 6.measurement • ৴߸ॲཧΛ࠷খݶʹ • ਖ਼֬ͳԻ੠ଌఆ༻ • Ի੠෼ੳΞϓϦ޲͚ 7.spokenAudio • Ի੠໌ྎ౓ॏࢹ • ϙουΩϟετɺΦʔσΟΦϒοΫ޲͚ • Ի੠ίϯςϯπ࠶ੜ༻ 1. ໾ׂɿ • ΞϓϦͱOS/ϋʔυ΢ΣΞؒͷڮ౉͠ • ΞϓϦͷΦʔσΟΦͷҰൠతͳੑ࣭ΛOSʹ఻͑Δ 2. ಛ௃ɿ • ۩ମతͳಈ࡞΍ϋʔυ΢ΣΞͱͷৄࡉͳ΍ΓऔΓΛࢦఆ͢Δඞཁ͕ͳ͍ • ͦΕΒͷৄࡉͳ؅ཧ͸ΦʔσΟΦηογϣϯʹҕ೚͞ΕΔ 3. ϝϦοτɿ • OS͕ϢʔβʔͷΦʔσΟΦମݧΛ࠷దʹ؅ཧͰ͖Δ • ։ൃऀ͸௿Ϩϕϧͷ࣮૷ৄࡉΛؾʹ͢Δඞཁ͕ͳ͍ ͲΜͳΞϓϦʹ͢Δ͔ʁ ར༻༻్ͰϞʔυΛબͿ
  9. AVAudio Option 1. mixWithOthers • ଞΞϓϦͱͷԻ੠ϛΩγϯάΛڐՄ • BGM࠶ੜதʹޮՌԻΛ௥Ճ͢Δ৔߹ͳͲʹ࢖༻ • ambient,

    playback, playAndRecordΧςΰϦͰ࢖༻Մ ೳ 2. duckOthers • ࣗΞϓϦͷԻ੠࠶ੜ࣌ʹଞΞϓϦͷԻྔΛࣗಈతʹԼ ͛Δ • φϏήʔγϣϯΞϓϦͷҊ಺Ի੠ͳͲͰ࢖༻ • playback, playAndRecordΧςΰϦͰ࢖༻Մೳ 3. interruptSpokenAudioAndMixWithOthers • Ի੠ίϯςϯπʢϙουΩϟετͳͲʣΛதஅΛ͢Δ • .mixWithOthersͷ֦ுΦϓγϣϯ • φϏήʔγϣϯΞϓϦͳͲͰ࢖༻ 4. allowBluetooth • BluetoothϔουηοτʢHFP/HSPʣͱͷ઀ଓΛڐՄ • ௨࿩΍ϘΠενϟοτ༻ • playAndRecordΧςΰϦͰओʹ࢖༻ 5. allowBluetoothA2DP • BluetoothεςϨΦΦʔσΟΦʢA2DPʣͷ࢖༻ΛڐՄ • ߴ඼࣭ͳԻָ࠶ੜ༻ • playback, playAndRecordΧςΰϦͰ࢖༻Մೳ 6. allowAirPlay • AirPlayσόΠε΁ͷग़ྗΛڐՄ • ϫΠϠϨε࠶ੜ༻ • playback, playAndRecordΧςΰϦͰ࢖༻Մೳ 7. defaultToSpeaker • ಺ଂεϐʔΧʔΛ༏ઌతʹ࢖༻ • ϏσΦ௨࿩΍ϘΠενϟοτͰ࢖༻ • playAndRecordΧςΰϦͰओʹ࢖༻
  10. AVAudio Option 1. mixWithOthers • ଞΞϓϦͱͷԻ੠ϛΩγϯάΛڐՄ • BGM࠶ੜதʹޮՌԻΛ௥Ճ͢Δ৔߹ͳͲʹ࢖༻ • ambient,

    playback, playAndRecordΧςΰϦͰ࢖༻Մ ೳ 2. duckOthers • ࣗΞϓϦͷԻ੠࠶ੜ࣌ʹଞΞϓϦͷԻྔΛࣗಈతʹԼ ͛Δ • φϏήʔγϣϯΞϓϦͷҊ಺Ի੠ͳͲͰ࢖༻ • playback, playAndRecordΧςΰϦͰ࢖༻Մೳ 3. interruptSpokenAudioAndMixWithOthers • Ի੠ίϯςϯπʢϙουΩϟετͳͲʣΛதஅΛ͢Δ • .mixWithOthersͷ֦ுΦϓγϣϯ • φϏήʔγϣϯΞϓϦͳͲͰ࢖༻ 4. allowBluetooth • BluetoothϔουηοτʢHFP/HSPʣͱͷ઀ଓΛڐՄ • ௨࿩΍ϘΠενϟοτ༻ • playAndRecordΧςΰϦͰओʹ࢖༻ 5. allowBluetoothA2DP • BluetoothεςϨΦΦʔσΟΦʢA2DPʣͷ࢖༻ΛڐՄ • ߴ඼࣭ͳԻָ࠶ੜ༻ • playback, playAndRecordΧςΰϦͰ࢖༻Մೳ 6. allowAirPlay • AirPlayσόΠε΁ͷग़ྗΛڐՄ • ϫΠϠϨε࠶ੜ༻ • playback, playAndRecordΧςΰϦͰ࢖༻Մೳ 7. defaultToSpeaker • ಺ଂεϐʔΧʔΛ༏ઌతʹ࢖༻ • ϏσΦ௨࿩΍ϘΠενϟοτͰ࢖༻ • playAndRecordΧςΰϦͰओʹ࢖༻ 1. ໾ׂɿ • ΞϓϦͱOS/ϋʔυ΢ΣΞؒͷڮ౉͠ • ΞϓϦͷΦʔσΟΦͷҰൠతͳੑ࣭ΛOSʹ఻͑Δ 2. ಛ௃ɿ • ۩ମతͳಈ࡞΍ϋʔυ΢ΣΞͱͷৄࡉͳ΍ΓऔΓΛࢦఆ͢Δඞཁ͕ͳ͍ • ͦΕΒͷৄࡉͳ؅ཧ͸ΦʔσΟΦηογϣϯʹҕ೚͞ΕΔ 3. ϝϦοτɿ • OS͕ϢʔβʔͷΦʔσΟΦମݧΛ࠷దʹ؅ཧͰ͖Δ • ։ൃऀ͸௿Ϩϕϧͷ࣮૷ৄࡉΛؾʹ͢Δඞཁ͕ͳ͍ ΧςΰϦʹΑͬͯͲͷΑ͏ͳΦϓ γϣϯ͕࢖͑Δ͔Θ͔Δ
  11. AVAudioSessionͷઃఆ try audioSession.setCategory(.soloAmbient, mode: .default, options: []) try audioSession.setActive(true) Category

    Mode Options 1. ໾ׂɿ • ΞϓϦͱOS/ϋʔυ΢ΣΞؒͷڮ౉͠ • ΞϓϦͷΦʔσΟΦͷҰൠతͳੑ࣭ΛOSʹ఻͑Δ 2. ಛ௃ɿ • ۩ମతͳಈ࡞΍ϋʔυ΢ΣΞͱͷৄࡉͳ΍ΓऔΓΛࢦఆ͢Δඞཁ͕ͳ͍ • ͦΕΒͷৄࡉͳ؅ཧ͸ΦʔσΟΦηογϣϯʹҕ೚͞ΕΔ 3. ϝϦοτɿ • OS͕ϢʔβʔͷΦʔσΟΦମݧΛ࠷దʹ؅ཧͰ͖Δ • ։ൃऀ͸௿Ϩϕϧͷ࣮૷ৄࡉΛؾʹ͢Δඞཁ͕ͳ͍ ͲΜͳΞϓϦʹ͢Δ͔ʁ ར༻༻్͕෼͔Ε͹ɺ AVAudioSessionͷઃఆ͕Θ͔Δ
  12. Ͱ͸Έͳ͞Μ͜Ε͸Ͳ͏ͳΔͰ͠ΐ͏ʁ try audioSession.setCategory(.playback, mode: .videoRecording) try audioSession.setActive(true) 1. ໾ׂɿ •

    ΞϓϦͱOS/ϋʔυ΢ΣΞؒͷڮ౉͠ • ΞϓϦͷΦʔσΟΦͷҰൠతͳੑ࣭ΛOSʹ఻͑Δ 2. ಛ௃ɿ • ۩ମతͳಈ࡞΍ϋʔυ΢ΣΞͱͷৄࡉͳ΍ΓऔΓΛࢦఆ͢Δඞཁ͕ͳ͍ • ͦΕΒͷৄࡉͳ؅ཧ͸ΦʔσΟΦηογϣϯʹҕ೚͞ΕΔ 3. ϝϦοτɿ • OS͕ϢʔβʔͷΦʔσΟΦମݧΛ࠷దʹ؅ཧͰ͖Δ • ։ൃऀ͸௿Ϩϕϧͷ࣮૷ৄࡉΛؾʹ͢Δඞཁ͕ͳ͍ ͋Γ͑ͳ͍૊Έ߹ΘͤΛઃఆͰ͖ͪΌ͍·͢ɻ ΞϓϦར༻࣌ʹෆ౎߹͕͋Δ͜ͱ͕͋Γ·͢ɻ