ios - 画中画后如何恢复全屏视频播放器
<p><p>我正在使用 <strong>AVPlayerViewController</strong> 和 <code>allowsPictureInPicturePlayback = YES;</code>,</p>
<p>所以当我点击 PictureInPicture 按钮时,<code>AVPlayerViewController</code> 将被关闭并显示小播放器..</p>
<p>但是当我点击小播放器中的恢复按钮时,它会被关闭而不再显示<strong>AVPlayerViewController</strong>..</p>
<p>那么在小播放器中点击恢复按钮后如何恢复<strong>AVPlayerViewController</strong>??</p>
<p>我的代码:</p>
<pre><code>#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
@interface ViewController ()<AVPlayerViewControllerDelegate>{
AVPlayerViewController *_AVPlayerViewController;
}
@end
@implementation ViewController
- (void)viewDidLoad {
;
[ setCategory:AVAudioSessionCategoryPlayback error:nil];
[ setActive: YES error: nil];
// create a movie player
NSURL *url = ;
_AVPlayerViewController = ;
_AVPlayerViewController.delegate = self;
_AVPlayerViewController.showsPlaybackControls = YES;
_AVPlayerViewController.allowsPictureInPicturePlayback = YES;
_AVPlayerViewController.videoGravity = AVLayerVideoGravityResizeAspect;
_AVPlayerViewController.player = ;
;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
;
});
}
- (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
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我能够通过在委托(delegate)中的 <code>playerViewController:restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:</code> 中使用 <code>presentViewController: animated:</code> 来解决此问题</p>
<p>所以它会在之前被解除后再次代表<strong>AVPlayerViewController</strong></p>
<p>我的新代码:</p>
<pre><code>- (void)playerViewController:(AVPlayerViewController *)playerViewController restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL restored))completionHandler{
;
NSLog(@"restoreUserInterfaceForPictureInPictureStopWithCompletionHandler");
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 画中画后如何恢复全屏视频播放器,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/32672645/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/32672645/
</a>
</p>
页:
[1]