1
MPMoviePlayer를 통해 스트리밍 오디오를 실행 중입니다. 원격 이벤트를 잠금 화면 및 독에 전송하여 제목과 작성자를 볼 수있게하고 배경 모드에서 오디오를 재생할 수 있지만 나에게있어 잠금 화면/독 재생 버튼을 시작하고 재생할 수는 없습니다. 오디오를 멈추십시오. 완전히 빠진 것이 있습니까?MPMoviePlayer 잠금 화면 오디오 재생/일시 중지
#import "teachingsDetailViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "RSSItem.h"
#import "RSSLoader.h"
@implementation teachingsDetailViewController
@synthesize moviePlayerController;
-(void)viewDidLoad:(BOOL)animated
{
//Make sure the system follows our playback status
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
NSLog(@"The System ran this");
//Load the audio into memory
[moviePlayerController prepareToPlay];
[super viewDidLoad];
}
-(void)viewDidAppear:(BOOL)animated {
[super loadView];
RSSItem* item = (RSSItem*)self.detailItem;
self.title = item.title;
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:item.link];
NSLog(@"The url is %@", item.link);
[self.view addSubview:moviePlayerController.view];
moviePlayerController.movieSourceType = MPMovieSourceTypeUnknown;
moviePlayerController.fullscreen = YES;
if ([[UIApplication sharedApplication] respondsToSelector:@selector(beginReceivingRemoteControlEvents)]){
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
NSLog(@"The System ran this");
[self becomeFirstResponder];
NSLog(@"Responds!");
}
[moviePlayerController play];
//here
Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
if (playingInfoCenter) {
NSError *error= nil;
if ([[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&error]) {
NSLog(@"Error setting audio session: %@", error);
}
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] init];
[songInfo setObject:self.title forKey:MPMediaItemPropertyTitle];
[songInfo setObject:@"AU One Place" forKey:MPMediaItemPropertyArtist];
[songInfo setObject:@"Teachings" forKey:MPMediaItemPropertyAlbumTitle];
[songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
}
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
//End recieving events
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
NSLog(@"Stopped receiving remote control events");
[self resignFirstResponder];
}
-(void)viewDidDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
[self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidUnload {
[super viewDidUnload];
}