• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - 画中画后如何恢复全屏视频播放器

[复制链接]
菜鸟教程小白 发表于 2022-12-13 10:57:18 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在使用 AVPlayerViewControllerallowsPictureInPicturePlayback = 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-推荐答案


我能够通过在委托(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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap