美文网首页
AVPlayer 去黑边

AVPlayer 去黑边

作者: woo_5857 | 来源:发表于2022-12-15 17:14 被阅读0次

        varbgView=UIView()

        var palyerItem :AVPlayerItem?

        varplayer:AVPlayer?

        var playerLayer :AVPlayerLayer?

    //创建媒体资源管理对象

            self.palyerItem = AVPlayerItem(url: URL.init(fileURLWithPath: urlString))

            //创建ACplayer:负责视频播放

            self.player = AVPlayer.init(playerItem: self.palyerItem!)

            self.player?.rate = 1.0//播放速度 播放前设置

            //创建显示视频的图层

            self.playerLayer?.backgroundColor = UIColor.init(hex: "#FFFFFF").cgColor

            self.playerLayer = AVPlayerLayer.init(player: self.player)

            self.playerLayer?.borderColor = UIColor.init(hex: "#FFFFFF").cgColor

            playerLayer?.shadowColor = UIColor.init(hex: "#FFFFFF").cgColor

            self.playerLayer?.videoGravity = .resizeAspect

            if zIsiPad {

                self.playerLayer?.frame = CGRect.init(x: 0, y: 0, width: 700, height: 900)

            } else {

                self.playerLayer?.frame = CGRect.init(x: 0, y: 0, width: 375, height: 500)

            }

            self.playerLayer?.shouldRasterize = true

            self.playerLayer?.rasterizationScale = UIScreen.main.scale

            self.bgView.layer.addSublayer(self.playerLayer!)

            //播放

            self.player?.play()

    相关文章

      网友评论

          本文标题:AVPlayer 去黑边

          本文链接:https://www.haomeiwen.com/subject/kjvrqdtx.html