菜鸟教程小白 发表于 2022-12-13 10:57:18

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 &#34;ViewController.h&#34;
#import &lt;AVFoundation/AVFoundation.h&gt;
#import &lt;AVKit/AVKit.h&gt;

@interface ViewController ()&lt;AVPlayerViewControllerDelegate&gt;{
    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(@&#34;playerViewControllerWillStartPictureInPicture&#34;);
}

- (void)playerViewControllerDidStartPictureInPicture:(AVPlayerViewController *)playerViewController{
    NSLog(@&#34;playerViewControllerDidStartPictureInPicture&#34;);
}

- (void)playerViewController:(AVPlayerViewController *)playerViewController failedToStartPictureInPictureWithError:(NSError *)error{
    NSLog(@&#34;failedToStartPictureInPictureWithError&#34;);
}

- (void)playerViewControllerWillStopPictureInPicture:(AVPlayerViewController *)playerViewController{
    NSLog(@&#34;playerViewControllerWillStopPictureInPicture&#34;);
}

- (void)playerViewControllerDidStopPictureInPicture:(AVPlayerViewController *)playerViewController{
    NSLog(@&#34;playerViewControllerDidStopPictureInPicture&#34;);
}

- (BOOL)playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart:(AVPlayerViewController *)playerViewController{
    return YES;
}

- (void)playerViewController:(AVPlayerViewController *)playerViewController restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL restored))completionHandler{
    NSLog(@&#34;restoreUserInterfaceForPictureInPictureStopWithCompletionHandler&#34;);
}

@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(@&#34;restoreUserInterfaceForPictureInPictureStopWithCompletionHandler&#34;);
}
</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]
查看完整版本: ios - 画中画后如何恢复全屏视频播放器