【发布时间】:2015-12-16 19:41:37
【问题描述】:
我正在使用 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)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
【问题讨论】:
标签: ios objective-c iphone cocoa-touch ios9