2013-11-29 2 views

답변

5

현재 AVAudioPlayer을 사용하고 있지만 원격 제어 방법 인 - (void)remoteControlReceivedWithEvent:(UIEvent *)event은 사용중인 플레이어의 유형과 관련되어서는 안됩니다.

이 따르 viewDidAppear: :

//Make sure the system follows our playback status - to support the playback when the app enters the background mode. 
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; 
[[AVAudioSession sharedInstance] setActive: YES error: nil]; 

그런 다음 이러한 방법을 추가 (이미 구현하지 않은 경우)

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 

    //Once the view has loaded then we can register to begin recieving controls and we can become the first responder 
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 
    [self becomeFirstResponder]; 
} 

보기 컨트롤러의 viewDidLoad 방법에서

를 다음 코드를 추가합니다 viewWillDisappear: (아직 구현되지 않은 경우)

- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 

    //End recieving events 
    [[UIApplication sharedApplication] endReceivingRemoteControlEvents]; 
    [self resignFirstResponder]; 
} 

그리고 :이 모든 뷰 컨트롤러에서 원격 제어 이벤트를 수신 할 수 있도록하려면 그러나 경우, 내 응용 프로그램에서 잘 작동

//Make sure we can recieve remote control events 
- (BOOL)canBecomeFirstResponder { 
    return YES; 
} 

- (void)remoteControlReceivedWithEvent:(UIEvent *)event { 
    //if it is a remote control event handle it correctly 
    if (event.type == UIEventTypeRemoteControl) 
    { 
     if (event.subtype == UIEventSubtypeRemoteControlPlay) 
     { 
      [self playAudio]; 
     } 
     else if (event.subtype == UIEventSubtypeRemoteControlPause) 
     { 
      [self pauseAudio]; 
     } 
     else if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause) 
     { 
      [self togglePlayPause]; 
     } 

     else if (event.subtype == UIEventSubtypeRemoteControlBeginSeekingBackward) 
     { 
      [self rewindTheAudio]; //You must implement 15" rewinding in this method. 
     } 
     else if (event.subtype == UIEventSubtypeRemoteControlBeginSeekingForward) 
     { 
      [self fastForwardTheAudio]; //You must implement 15" fast-forwarding in this method. 
     } 

    } 
} 

, 당신은 그것을 AppDelegate에 설정해야합니다.