* Audio route 변경 시 Notification 수신 방법. (예. Headphones plugged/unplugged) 

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(routeChanged:) name:AVAudioSessionRouteChangeNotification object:nil];


- (void)routeChanged:(NSNotification *)notification

{

   NSNumber *reason = [notification.userInfo objectForKey:AVAudioSessionRouteChangeReasonKey];

   

   if ([reason unsignedIntegerValue] == AVAudioSessionRouteChangeReasonNewDeviceAvailable) {

   } else if ([reason unsignedIntegerValue] == AVAudioSessionRouteChangeReasonOldDeviceUnavailable) {       

   }

}


   - 연관 Notification : AVAudioSessionSilenceSecondaryAudioHintNotification, AVAudioSessionMediaServicesWereLostNotification, AVAudioSessionMediaServicesWereResetNotification, AVAudioSessionInterruptionNotification

Posted by 프리지크
:

* Headphone 이용 시 이벤트 수신 방법.

   // Headphones의 played/paused event 수신. (예. Apple EarPods 일 경우, Center Button 한번 클릭)

   // !!특이점

   //   - Apple EarPods 일 경우, togglePlayPauseCommand를 수신.

   //   - 일반 Bluetooth Headphones 일 경우, 아래의 playCommand/pauseCommand를 수신. (왜??? ;;;;)

   MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];

   [commandCenter.togglePlayPauseCommand addTarget:self action:@selector(command)];

   

   // Headphones의 played event 수신

   commandCenter.playCommand.enabled = YES;

   [commandCenter.playCommand addTarget:self action:@selector(playCommand)];

   

   // Headphones의 paused event 수신

   commandCenter.pauseCommand.enabled = YES;

   [commandCenter.pauseCommand addTarget:self action:@selector(pauseCommand)];

   

   // Headphones의 Next track event 수신. (예. Apple EarPods 일 경우, Volume up 버튼을 두번 클릭)

   commandCenter.nextTrackCommand.enabled = YES;

   [commandCenter.nextTrackCommand addTarget:self action:@selector(nextTrackCommand)];

   

   // Headphones의 Previous track event 수신. (예. Apple EarPods 일 경우, Volume down 버튼을 두번 클릭)

   commandCenter.previousTrackCommand.enabled = YES;

   [commandCenter.previousTrackCommand addTarget:self action:@selector(previousTrackCommand)];


또는, 


UIResponse를 상속받는 AppDelegate 에서 아래 메소드를 통해 이벤트를 받을 수 있음.


- (void)remoteControlReceivedWithEvent:(nullable UIEvent *)event


Posted by 프리지크
:

BLOG main image
인생에서는 찾고, 노력하고, 희생할 각오가 되어 있는 것만 얻을 수 있다. (조시 매슈 애덤스) by 프리지크

공지사항

카테고리

분류 전체보기 (121)
끄적끄적 (16)
좋은 글 (9)
자료 (19)
런닝&피트니스 (18)
기술 (43)
기사 스크랩 (1)
내가 본 공연 후기 (1)
내가 가 본 맛집 (5)
괜찮아 보이는 펜션들 (4)
(4)
한장한장 (0)
비공개 스크랩 (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

Total :
Today : Yesterday :