我正在使用以Swift
编写的视频播放器应用。
我的问题是我应该使AVPlayerViewController
的拐角曲线。但我只想使用AVPlayerViewController
而不使用其他任何类。
我现在做什么:
fileprivate func setupPlayer() {
let player = AVPlayer(url: videoURL)
let playerViewController = AVPlayerViewController()
playerViewController.view.frame = CGRect.init(x: xPosition,
y: yPosition,
width: 200,
height: 100)
playerViewController.player = player
self.addChild(playerViewController)
self.view.addSubview(playerViewController.view)
playerViewController.didMove(toParent: self)
playerViewController.videoGravity = AVLayerVideoGravity.init(rawValue: "")
playerViewController.view.backgroundColor = UIColor(displayP3Red: 0/255, green: 0/255, blue: 0/255, alpha: 0)
playerViewController.view.layer.cornerRadius = 20
playerViewController.contentOverlayView?.isHidden = true
playerViewController.contentOverlayView?.alpha = 0
}
但是我想在Appstore中拥有类似的曲线:
答案 0 :(得分:4)
AVPlayerViewController
向您的视图添加一个子层。设置playerViewController.view.layer.cornerRadius
属性时,它只会影响它,而不会影响它的孩子。
要修复此问题,必须使用masksToBounds
图层属性裁剪子视图(或此处的子图层)。
playerViewController.view.layer.masksToBounds = true
答案 1 :(得分:-1)
尝试一下。
import UIKit
import AVKit
class ViewController: UIViewController {
var videoController:AVPlayerViewController!
var player:AVPlayer!
var url:URL!
override func viewDidLoad() {
super.viewDidLoad()
let path:String=Bundle.main.path(forResource: "PinkLake", ofType: "mp4")!
url=URL(fileURLWithPath: path)
player=AVPlayer(url: url)
videoController=AVPlayerViewController()
videoController.player=player;
let viewVideo=UIView()
viewVideo.frame.origin.x=0;
viewVideo.frame.origin.y=50;
viewVideo.frame.size.width=200;
viewVideo.frame.size.height=200;
videoController.view.frame=viewVideo.frame
//declare tempView
var tempView = UIView(frame: videoController.view.frame)
tempView=videoController.view;
tempView.layer.cornerRadius=50;
videoController.view=tempView;
self.view.addSubview(viewVideo)
viewVideo.addSubview(videoController.view)
self.view.backgroundColor=UIColor.yellow
player.play()
}
}
答案 2 :(得分:-1)
AVPlayerLayer正常。
let available;
// send a GET to Machine1
require('request')('http://192.168.1.35:3000', (err, res, body) => {
available = JSON.parse(body);
});
// select desired file
let wantedMovie = available.movies[0];
// send a POST to Machine1 saying what I want.
require('request')('http://192.168.1.35:3000', {
method: 'POST',
body: JSON.stringify(wantedMovie)
}, (err, res, body) => {
let url = JSON.parse(body).url;
// => playback the file from Machine1 via the URL.
});