[iOS-Dev] AVAudioSession Programming Guide 내맘대로 번역 # 1

in #kr7 years ago (edited)

App개발 중 Background 노래가 재생되는 상태에서
AVPlayer, Recorder 등을 사용하는 경우
재생되던 노래가 종료되는 현상이 있어서,
Guide를 정리하면서 공부하려고 합니다.
혹시나 도움이 되시는 분이 있으면 좋겠네요~

원문
https://developer.apple.com/library/content/documentation/Audio/Conceptual/AudioSessionProgrammingGuide


미리보기

ASPG_intro_2x.png

  • AVAudioSession을 통해 OS / App간 Audio 제어를 쉽게 할 수 있다.
  • Category와 Mode를 설정을 통해 Audio system을 제어 할 수 있다.
    가장 기본적인 Mechanism - Input, Output route를 지시 할 수 있다.
    AVFoundation에서는 session category의 정의해 놓고 전환할 수 있다.
    Audio role을 정하면 하드웨어 리소스에 접근할 수 있다.
    Category들은 custom을 하여서 세부적인 제어가 가능하다.
  • AudioSession 관련 Notification을 받을 수 있다.
    Notification을 통해 Interruption을 다룬다. (AVAudioSessionInterruptionNotification)
    Notification을 통해 Audio Route 변화를 다룬다. (AVAudioSessionRouteChangeNotification)
  • AudioSession은 Singleton
  • Advanced Configuration(Sample rate, I/O buffer, channel) 설정 가능하다.
  • Protect User Privacy. (Grant)

설정

  • Category
    Category별 동작

  • 기본 설정 동작
    playback(o), recording(x)
    진동 / 잠금 모드 - 소리 줄임
    Audio 플레이 시 Background 소리 줄임

  • Category Mode 제어를 통해 다른 모드 제어
    Category Mode

  • Multiroute
    다른 카테고리들은 i/o 대상 기기가 last win rule
    Multiroute는 모든 연결된 루트에서 재생, 다른 루트에 다른 stream을 전송 가능


활성화

  • 오디오간 우선순위 경쟁 해결
    App이 activation을 요청하면
    Category 상태를 확인해서 처리한다.
    Music 앱의 상태를 Deactivate 시킨다.
    App의 Audio session을 재생한다.

  • Audio Session의 활성화 / 비활성화
    VoIP앱의 경우 Call하는 경우 활성화
    녹음앱의 경우 녹음하는 동안

  • 다른 오디오가 재생중인지 확인
    applicationDidBecomeActive 에서 secondaryAudioShouldBeSilencedHint 로 확인 가능
    Notification AVAudioSessionSilenceSecondaryAudioHintNotification 로 핸들링 가능


Interrupt에 대한 대응 (재생 중 전화, 알림 등)

audio_session_interrupted_2x.png

  • Interrupt 를 다루는 법
    Interrupt start : Context 저장, UI 업데이트
    Interrupt end : Context 복구, UI 업데이트, Reactivate audio session

  • Framework 별 처리
    AVFoundation framework : 자동으로 pause, playback
    Audio Queue Services, I/O audio unit : interrupt end 후 다시 reactivating 시켜줘야 한다.
    System Sound Services : 사운드 중단이 시작될때 자동으로 재생된다. 다시 재생할 수 있다.

Sort:  

Congratulations @babysloth! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Coin Marketplace

STEEM 0.19
TRX 0.17
JST 0.033
BTC 64188.14
ETH 2766.12
USDT 1.00
SBD 2.66