我正在使用
allowsPictureInPicturePlayback = YES;
的AVPlayerViewController,当我点击画中画按钮时,AVPlayerViewController
将被关闭并显示小型播放器。但是,当我在小型播放器中点击恢复按钮时,它会关闭而不显示AVPlayerViewController。那么,在单击小型播放器中的恢复按钮后,如何恢复AVPlayerViewController呢?以下是我的代码:#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
@interface ViewController ()<AVPlayerViewControllerDelegate>{
AVPlayerViewController *_AVPlayerViewController;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
// create a movie player
NSURL *url = [NSURL URLWithString:@"http://38.96.175.119:1935/aletejahtv/aletejahtv3/playlist.m3u8"];
_AVPlayerViewController = [AVPlayerViewController new];
_AVPlayerViewController.delegate = self;
_AVPlayerViewController.showsPlaybackControls = YES;
_AVPlayerViewController.allowsPictureInPicturePlayback = YES;
_AVPlayerViewController.videoGravity = AVLayerVideoGravityResizeAspect;
_AVPlayerViewController.player = [AVPlayer playerWithURL:url];
[_AVPlayerViewController.player play];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self presentViewController:_AVPlayerViewController animated:YES completion:nil];
});
}
- (void)playerViewControllerWillStartPictureInPicture:(AVPlayerViewController *)playerViewController{
NSLog(@"playerViewControllerWillStartPictureInPicture");
}
- (void)playerViewControllerDidStartPictureInPicture:(AVPlayerViewController *)playerViewController{
NSLog(@"playerViewControllerDidStartPictureInPicture");
}
- (void)playerViewController:(AVPlayerViewController *)playerViewController failedToStartPictureInPictureWithError:(NSError *)error{
NSLog(@"failedToStartPictureInPictureWithError");
}
- (void)playerViewControllerWillStopPictureInPicture:(AVPlayerViewController *)playerViewController{
NSLog(@"playerViewControllerWillStopPictureInPicture");
}
- (void)playerViewControllerDidStopPictureInPicture:(AVPlayerViewController *)playerViewController{
NSLog(@"playerViewControllerDidStopPictureInPicture");
}
- (BOOL)playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart:(AVPlayerViewController *)playerViewController{
return YES;
}
- (void)playerViewController:(AVPlayerViewController *)playerViewController restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL restored))completionHandler{
NSLog(@"restoreUserInterfaceForPictureInPictureStopWithCompletionHandler");
}
@end
playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart
上返回 false。 - ricardopereira