우선 저는 며칠 동안 (여기를 포함하여) 내 문제에 대한 해결책을 찾고있었습니다. 같은 문제를 다루는 몇 가지 주제를 찾았지만 전혀 해결하지 못했습니다.백그라운드에서 계속 듣기 위해 MPMoviePlayerViewController 오디오를 추출하십시오.
저는 앱에 저장된 mp4 비디오와 mp4 온라인 비디오를 재생하는 앱을 개발 중입니다.
나는 MPMoviePlayerViewController를 사용하여 비디오를 재생하고 응용 프로그램에있을 때 완벽하게 작동하지만 홈 버튼 (배경)을 누르면 문제가 발생합니다. 소리가 멈추고 내 목표는 앱에 없을 때 (아이폰이 잠겨 있거나 내가 배경에있을 때) 비디오 오디오를 계속 듣는 것입니다.
plist 파일의 백그라운드에서 오디오를 계속 듣고 오디오 세션을 만들려고했지만 아무것도 작동하지 않도록 옵션을 구성했습니다.
내 검색에서 사과가 앱에 없는데도 동영상을 계속 재생할 수 없다는 것을 발견했습니다.이를 달성하려면 오디오를 분리하고 동영상없이 계속 재생해야합니다. 사용자가 응용 프로그램으로 돌아와서 오디오 순간부터 비디오를 다시 시작하지만이 방법에 대한 많은 정보를 찾을 수 없습니다.
나는 그것을 할 수있는 다른 일을 시도 할 수있는 샘플 프로젝트를 생성 한 순간 내 코드는 다음과 같습니다
시간. 파일 :
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) AVAudioSession *audioPlayer;
@end
m. 파일
-(void)playVideo {
NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"video"
ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:urlStr];
_moviePlayer= [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:_moviePlayer.view];
int posTitulo = (int) roundf(self.titleLabel.frame.origin.y);
int altTitulo = (int) roundf(self.titleLabel.frame.size.height);
int anchTitulo = (int) roundf(self.titleLabel.frame.size.width);
_moviePlayer.view.frame = CGRectMake(0,posTitulo+altTitulo, anchTitulo, anchTitulo * 0.65);
[_moviePlayer play];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
NSError *activationError = nil;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:&activationError];
[audioSession setActive:YES error:&activationError];
}
누군가가 이와 같은 것을 달성했다면, 나는 그의 도움에 감사 할 것입니다.
고맙습니다.