【问题标题】:AVPlayer view in UIView is missing controlsUIView 中的 AVPlayer 视图缺少控件
【发布时间】:2018-10-25 11:48:50
【问题描述】:

如果将 AVPlayer 添加到 UIView,在 AVPlayer 中默认的视频前进滑块和播放按钮不会显示

NSURL *videourl= [NSURL URLWithString:strUrl];
AVPlayer *player = [AVPlayer playerWithURL:videourl];         

AVPlayerViewController *playerViewController = [AVPlayerViewController new];            

playerViewController.player = player;

playerViewController.view.frame = ViewAV.bounds;

AVPlayerLayer* playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = ViewAV.bounds;

playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
//externalPlaybackVideoGravity
playerLayer.contentsGravity = AVLayerVideoGravityResizeAspect;

[ViewAV.layer addSublayer:playerLayer];
[ViewAV addSubview:playerViewController.view];

[playerViewController.player play];

【问题讨论】:

    标签: ios objective-c uiview avplayer


    【解决方案1】:

    尝试将showsPlaybackControlsrequiresLinearPlayback 设置为true,

    playerViewController.showsPlaybackControls = YES;
    playerViewController.requiresLinearPlayback = YES;
    

    目前,您没有将playerViewController 添加为子viewController,因此您将看不到任何内容。添加如下,

    [self addChildViewController:playerViewController];
    [self.view.layer addSublayer:playerLayer];
    [self.view addSubview:playerViewController.view];
    

    【讨论】:

    • @ishanbhatt 您可以尝试添加为 childViewController,因为我在答案中更新了吗?
    猜你喜欢
    • 1970-01-01
    • 2019-05-19
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-22
    • 2012-07-18
    • 1970-01-01
    相关资源
    最近更新 更多