我正在使用 AVPlayerViewController 和 allowsPictureInPicturePlayback = YES; ,
所以当我点击 PictureInPicture 按钮时,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)playerViewControllerWillStartPictureInPictureAVPlayerViewController *)playerViewController{
NSLog(@"playerViewControllerWillStartPictureInPicture");
}
- (void)playerViewControllerDidStartPictureInPictureAVPlayerViewController *)playerViewController{
NSLog(@"playerViewControllerDidStartPictureInPicture");
}
- (void)playerViewControllerAVPlayerViewController *)playerViewController failedToStartPictureInPictureWithErrorNSError *)error{
NSLog(@"failedToStartPictureInPictureWithError");
}
- (void)playerViewControllerWillStopPictureInPictureAVPlayerViewController *)playerViewController{
NSLog(@"playerViewControllerWillStopPictureInPicture");
}
- (void)playerViewControllerDidStopPictureInPictureAVPlayerViewController *)playerViewController{
NSLog(@"playerViewControllerDidStopPictureInPicture");
}
- (BOOL)playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStartAVPlayerViewController *)playerViewController{
return YES;
}
- (void)playerViewControllerAVPlayerViewController *)playerViewController restoreUserInterfaceForPictureInPictureStopWithCompletionHandlervoid (^)(BOOL restored))completionHandler{
NSLog(@"restoreUserInterfaceForPictureInPictureStopWithCompletionHandler");
}
@end
Best Answer-推荐答案 strong>
我能够通过在委托(delegate)中的 playerViewController:restoreUserInterfaceForPictureInPictureStopWithCompletionHandler: 中使用 presentViewController: animated: 来解决此问题
所以它会在之前被解除后再次代表AVPlayerViewController
我的新代码:
- (void)playerViewControllerAVPlayerViewController *)playerViewController restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL restored))completionHandler{
[self presentViewController:playerViewController animated:YES completion:nil];
NSLog(@"restoreUserInterfaceForPictureInPictureStopWithCompletionHandler");
}
关于ios - 画中画后如何恢复全屏视频播放器,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/32672645/
|