을 통해 iPhone 잠금 화면에 내 AVPlayer
표현을 실현했습니다. 하지만 표준 음악 앱처럼 ± 15 초 뒤로 되감기 버튼을 추가하는 방법을 찾지 못했습니다. 그러면 잠금 화면에이 단추를 추가하는 방법에 대해 궁금한 점이 있습니까?되감기 버튼을 화면 잠금에 추가하는 방법은 무엇입니까?
2
A
답변
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
에 설정해야합니다.