I am new to ios programming, actually I need to stream video URL but i am unable to stream video URL using avplayer, but using avplayer downloaded file i am able to play.Actual problem is my file format is different
for example my file name is like this song.apa but it is song.mp4
code:
let avplayerController = AVPlayerViewController()
var avPlayer:AVPlayer?
override func viewDidLoad()
{
super.viewDidLoad()
let movieUrl = URL.init(string: "http://techslides.com/demos/sample-videos/small.3gp")
self.avPlayer = AVPlayer.init(url: movieUrl!)
self.avplayerController.player = self.avPlayer
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func playVideo(_ sender: Any)
{
self.present(self.avplayerController, animated: true) {
self.avplayerController.player?.play()
}
}
In Swift 3
import Foundation
import AVFoundation
import MediaPlayer
import AVKit
func play()
{
let player = AVPlayer(url: "Your Url")
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true)
{
playerViewController.player!.play()
}
}
You cant play this particular link (http://techslides.com/demos/sample-videos/small.3gp) using AVPlayer or AVPlayerViewController because that file is in AMR (Adaptive Multi-Rate, a format for speech) - which is not supported since iOS 4.3
Some of 3gp files can be played but only ones that have video and audio streams supported by Apple.
In Swift 3, try this code for playing video in project
import UIKit
import AVKit
import AVFoundation
import MediaPlayer
import MobileCoreServices
class VideoPlayerViewController: UIViewController,AVPlayerViewControllerDelegate {
//MARK: - Outlet -
#IBOutlet weak var viewVidioPlayer: UIView!
//MARK: - Variable
//MARK: - View Life Cycle -
override func viewDidLoad() {
super.viewDidLoad()
}
//MARK: - Action -
//for Playing Video
#IBAction func btnvideoPlayClicked(_ sender: UIButton) {
self.videoPlay()
}
func videoPlay()
{
let playerController = AVPlayerViewController()
playerController.delegate = self
let bundle = Bundle.main
let moviePath: String? = "http://techslides.com/demos/sample-videos/small.3gp"
let movieURL = URL(fileURLWithPath: moviePath!)
let player = AVPlayer(url: movieURL)
playerController.player = player
self.addChildViewController(playerController)
self.view.addSubview(playerController.view)
playerController.view.frame = self.view.frame
player.play()
}
//MARK: - other Function -
func playerViewControllerWillStartPictureInPicture(_ playerViewController: AVPlayerViewController){
print("playerViewControllerWillStartPictureInPicture")
}
func playerViewControllerDidStartPictureInPicture(_ playerViewController: AVPlayerViewController)
{
print("playerViewControllerDidStartPictureInPicture")
}
func playerViewController(_ playerViewController: AVPlayerViewController, failedToStartPictureInPictureWithError error: Error)
{
print("failedToStartPictureInPictureWithError")
}
func playerViewControllerWillStopPictureInPicture(_ playerViewController: AVPlayerViewController)
{
print("playerViewControllerWillStopPictureInPicture")
}
func playerViewControllerDidStopPictureInPicture(_ playerViewController: AVPlayerViewController)
{
print("playerViewControllerDidStopPictureInPicture")
}
func playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart(_ playerViewController: AVPlayerViewController) -> Bool
{
print("playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart")
return true
}
}
I hope it's work for you,
thank you
heres an example of streaming video..
override func viewDidLoad() {
super.viewDidLoad()
let player = AVPlayer(url: URL(string: "http://techslides.com/demos/sample-videos/small.mp4")!)
let controller = AVPlayerViewController()
present(controller, animated: true) { _ in }
controller.player = player
addChildViewController(controller)
view.addSubview(controller.view)
controller.view.frame = CGRect(x: 50, y: 50, width: 300, height: 300)
controller.player = player
controller.showsPlaybackControls = true
player.isClosedCaptionDisplayEnabled = false
player.play()
}
you can use YoutubePlayerView for playing youtube videos, and for else formats you can use UIWebView. For doing so, simply use if-else block,
if movieUrl.contains("youtube.com/") {
var videoId: String = extractYoutubeId(fromLink: movieUrl)
youtubePlayerView.load(withVideoId: videoId)
} else {
webView = UIWebView(frame: CGRect(x: 0, y: 0, width: 288, height: 277))
webView.delegate = self
webView.backgroundColor = UIColor.black
webView?.loadRequest(movieUrl)
}
For Swift 3 play video from URL
//AVPlayerViewControllerDelegate // example : class TestAudioVideoVC: UIViewController,AVPlayerViewControllerDelegate
func videoPlay()
{
let playerController = AVPlayerViewController()
playerController.delegate = self
let videoURL = NSURL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
let player = AVPlayer(url: videoURL! as URL)
playerController.player = player
self.addChildViewController(playerController)
self.view.addSubview(playerController.view)
playerController.view.frame = CGRect(x: 0, y: 64, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height - 64)
playerController.showsPlaybackControls = true
player.play()
}
//MARK: - AVPlayerViewController Delegate -
func playerViewControllerWillStartPictureInPicture(_ playerViewController: AVPlayerViewController){
print("playerViewControllerWillStartPictureInPicture")
}
func playerViewControllerDidStartPictureInPicture(_ playerViewController: AVPlayerViewController)
{
print("playerViewControllerDidStartPictureInPicture")
}
func playerViewController(_ playerViewController: AVPlayerViewController, failedToStartPictureInPictureWithError error: Error)
{
print("failedToStartPictureInPictureWithError")
}
func playerViewControllerWillStopPictureInPicture(_ playerViewController: AVPlayerViewController)
{
print("playerViewControllerWillStopPictureInPicture")
}
func playerViewControllerDidStopPictureInPicture(_ playerViewController: AVPlayerViewController)
{
print("playerViewControllerDidStopPictureInPicture")
}
func playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart(_ playerViewController: AVPlayerViewController) -> Bool
{
print("playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart")
return true
}
Play video in swift 5
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func playVideoUsingURL(_ sender: Any) {
playGlobalVideo()
}
#IBAction func playVideoFromLocalDrive(_ sender: Any) {
playLocalVideo()
}
func playGlobalVideo() {
guard let videoURL = URL(string: "http://static.videokart.ir/clip/100/480.mp4") else {
return
}
let player = AVPlayer(url: videoURL)
let vc = AVPlayerViewController()
vc.player = player
present(vc, animated: true) {
player.play()
}
}
func playLocalVideo() {
guard let videoPath = Bundle.main.path(forResource: "movie", ofType: "mov") else {
return
}
let player = AVPlayer(url: URL.init(fileURLWithPath: videoPath))
let playCtr = AVPlayerViewController()
playCtr.player = player
present(playCtr, animated: true) {
player.play()
}
}
}
Related
I have splash screen as a short mov video for my application and I use AVPlayer (code below) for that. It stopped working with the IOS 14 physical device, while on the simulator it works fine. Could you help with that?
import UIKit
import AVKit
import AVFoundation
class PlayerVC: UIViewController, AVAudioPlayerDelegate {
lazy var player: AVPlayer = {
let fileName = "test"
let path = Bundle.main.path(forResource: fileName, ofType: "mov")!
let videoURL = URL(fileURLWithPath: path)
let player = AVPlayer(url: videoURL)
return player
}()
override func viewDidLoad() {
super.viewDidLoad()
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(viewTapped)))
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.shouldRasterize = true
playerLayer.frame = self.view.bounds
self.view.layer.addSublayer(playerLayer)
player.play()
NotificationCenter.default.addObserver(self, selector: #selector(self.playerDidFinishPlaying(sender:)), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)
}
#objc func playerDidFinishPlaying(sender: NSNotification) {
loadRootVC()
}
private func loadRootVC() {
dismiss(animated: false, completion: nil)
self.onVideoFinished();
}
#objc func viewTapped() {
loadRootVC()
}
deinit {
NotificationCenter.default.removeObserver(self)
}
}
So I am creating a simple radio station app. I have coded the following and got the play / pause button switching text. I just can't work out how to access the player in the button when the func is inside ViewDidLoad. I am sure I need to set global variables?
override func viewDidAppear(_ animated: Bool) {
guard let url = URL(string: "http://stream.radiomedia.com.au:8003/stream") else {
return
}
// Create a new AVPlayer and associate it with the player view
let player = AVPlayer(url: url)
player.allowsExternalPlayback = true
player.usesExternalPlaybackWhileExternalScreenIsActive = true
// Create a new AVPlayerViewController and pass it a reference to the player.
let playerViewController = AVPlayerViewController()
playerViewController.contentOverlayView?.backgroundColor = UIColor.white
playerViewController.view.frame = CGRect (x:100, y:100, width:200, height:200)
playerViewController.player = player
self.addChild(playerViewController)
self.view.addSubview(playerViewController.view)
playerViewController.didMove(toParent: self)
playerViewController.player = player
player.play()
}
#IBAction func playVideo(_ sender: Any) {
if(playButton == false){
playButton = true;
(sender as! UIButton).setTitle("Pause", for: [])
player.pause() // does not work
}else
{
playButton = false;
(sender as! UIButton).setTitle("Play", for: [])
player.play() // does not work
}
}
class YourVC: UIViewController {
var player = AVPlayer()
}
just declare the player inside your class so that other functions can access it.
and in your viewDidApper(), change:
let player = AVPlayer(url: url)
to
self.player = AVPlayer(url: url)
then you can call player.pause() and player.play() from anywhere inside your Class.
import UIKit
import AVFoundation
class AudioPlayerVC: UIViewController {
var audioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
var alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("wakeUp", ofType: ".mp3"))
var error:NSError?
audioPlayer = AVAudioPlayer(contentsOfURL: alertSound, error: &error)
audioPlayer.prepareToPlay()
audioPlayer.play()
}
#IBAction func onPressPlayPaush(_ sender: UIButton) {
if(sender == false){
sender = true
audioPlayer.pause()
}else
{
sender = false
audioPlayer.play()
}
}
I have got four video clips and I want to play them endlessly. But my AVQueuePlayer() loops all the videos just 2 times and then stops.
How to make them play endlessly?
Here's my code:
import UIKit
import AVKit
class ViewController: UIViewController {
private let player = AVQueuePlayer()
let clips = ["001", "002", "003", "004"]
private var token: NSKeyValueObservation?
var avPlayerView = AVPlayerViewController()
override func viewDidLoad() {
super.viewDidLoad()
self.addAllVideosToPlayer()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
self.addAllVideosToPlayer()
}
func addAllVideosToPlayer() {
avPlayerView.player = player
for clip in clips {
let urlPath = Bundle.main.path(forResource: clip, ofType: "m4v")!
let url = URL(fileURLWithPath: urlPath)
let playerItem = AVPlayerItem(url: url)
player.insert(playerItem, after: player.items().last)
token = player.observe(\.currentItem) { [weak self] player, _ in
if self!.player.items().count == 1 { self?.addAllVideosToPlayer() }
}
avPlayerView.showsPlaybackControls = false
player.volume = 0.0
}
present(avPlayerView, animated: true, completion: { self.player.play() })
}
}
I solved my problem. I deleted viewDidLoad() method and placed present() function into viewDidAppear().
Here's how it looks like:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
self.addAllVideosToPlayer()
present(avPlayerView, animated: true, completion: { self.player.play() })
}
I'm currently looping my mp4 video with no playback controls, kind of like a gif but with sound. But I do not know why when I segue to the next view controller, the video is still playing. Does anybody know the simplest method to resolve this issue?
ViewController
import UIKit
import AVKit
import AVFoundation
fileprivate var playerObserver: Any?
class ScoreController: UIViewController {
#IBOutlet var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let returnValue: Int = UserDefaults.standard.integer(forKey: "userScore")
label.text = "Your Score: \(returnValue)/30"
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
let path = Bundle.main.path(forResource: "Innie-Kiss", ofType:"mp4")
let player = AVPlayer(url: URL(fileURLWithPath: path!))
let resetPlayer = {
player.seek(to: kCMTimeZero)
player.play()
}
playerObserver = NotificationCenter.default.addObserver(forName: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem, queue: nil) { notification in resetPlayer() }
let controller = AVPlayerViewController()
controller.player = player
controller.showsPlaybackControls = false
self.addChildViewController(controller)
let screenSize = UIScreen.main.bounds.size
let videoFrame = CGRect(x: 0, y: 130, width: screenSize.width, height: (screenSize.height - 130) / 2)
controller.view.frame = videoFrame
self.view.addSubview(controller.view)
player.play()
} catch {
}
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
}
fileprivate var player: AVPlayer? {
didSet { player?.play() }
}
deinit {
guard let observer = playerObserver else { return }
NotificationCenter.default.removeObserver(observer)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
#IBAction func doneButton(_ sender: Any) {
self.performSegue(withIdentifier: "done", sender: self)
}
}
In viewWillDisapper() or button action for segue do this :
NotificationCenter.default.removeObserver(self)
Also move this from viewDidLoad() to some function like :
var player: AVPlayer?
func audioPlayer(){
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
let path = Bundle.main.path(forResource: "Innie-Kiss", ofType:"mp4")
player = AVPlayer(url: URL(fileURLWithPath: path!))
let resetPlayer = {
self.player?.seek(to: kCMTimeZero)
self.player?.play()
}
playerObserver = NotificationCenter.default.addObserver(forName: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player?.currentItem, queue: nil) { notification in resetPlayer() }
let controller = AVPlayerViewController()
controller.player = player
controller.showsPlaybackControls = false
self.addChildViewController(controller)
let screenSize = UIScreen.main.bounds.size
let videoFrame = CGRect(x: 0, y: 130, width: screenSize.width, height: (screenSize.height - 130) / 2)
controller.view.frame = videoFrame
self.view.addSubview(controller.view)
player?.play()
} catch {
}
}
and make player object a global variable. var player = AVPlayer? and in viewWillDisappear make it nil.
So your viewWillDisappear should look like this :
override func viewWillDisappear(_ animated: Bool) {
NotificationCenter.default.removeObserver(self)
if player != nil{
player?.replaceCurrentItem(with: nil)
player = nil
}
}
override func viewWillDisappear(_ animated: Bool) {
}
This may be helpful to you if you are switching windows; as you perform a segue, you will execute the function included in curly brackets automatically. I'm rubbish with AV, but some of the other's code suggested to turn off the function may work here if it isn't working in the IBAction.
I'm not great with Xcode though, so mileage will probably vary.
I had this issue and fixed it by adding this line before setting player to nil:
[self.player pause];
here is my viewWillDisapear:
- (void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:AVPlayerItemDidPlayToEndTimeNotification
object:self.player];
[self.player removeObserver:self forKeyPath:#"rate"];
[self.player removeTimeObserver:self.playerObserver];
self.playerObserver = nil;
[self.player pause];
self.player = nil;
[[UIDevice currentDevice] setValue:#(UIInterfaceOrientationPortrait) forKey:#"orientation"];
[UINavigationController attemptRotationToDeviceOrientation];
[StayfilmApp restrictOrientation:YES];
}
class ScoreController: UIViewController {
#IBOutlet var label: UILabel!
var player: AVPlayer?
override func viewDidLoad() {
super.viewDidLoad()
let returnValue: Int = UserDefaults.standard.integer(forKey: "userScore")
label.text = "Your Score: \(returnValue)/30"
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
let path = Bundle.main.path(forResource: "Innie-Kiss", ofType:"mp4")
player = AVPlayer(url: URL(fileURLWithPath: path!))
let resetPlayer = {
player.seek(to: kCMTimeZero)
player.play()
}
playerObserver = NotificationCenter.default.addObserver(forName: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem, queue: nil) { notification in resetPlayer() }
let controller = AVPlayerViewController()
controller.player = player
controller.showsPlaybackControls = false
self.addChildViewController(controller)
let screenSize = UIScreen.main.bounds.size
let videoFrame = CGRect(x: 0, y: 130, width: screenSize.width, height: (screenSize.height - 130) / 2)
controller.view.frame = videoFrame
self.view.addSubview(controller.view)
player.play()
} catch {
}
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
player.pause()
}
fileprivate var player: AVPlayer? {
didSet { player?.play() }
}
deinit {
guard let observer = playerObserver else { return }
NotificationCenter.default.removeObserver(observer)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
#IBAction func doneButton(_ sender: Any) {
self.performSegue(withIdentifier: "done", sender: self)
}
}
notable changes:
var player: AVPlayer?
and also
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
NotificationCenter.default.removeObserver(self)
player?.pause()
}
I have the same problem when I used segue to go to the next ViewController, then I used present code with swift by using this code
#IBAction func next(_ sender: Any) {
let vc = self .storyboard?.instantiateViewController(withIdentifier:"ViewControllerAA") as! ViewControllerAA
self.present(vc,animated: true,completion: nil)
}
but the problem didn't solve , then I used this code to go to the next VC and my problem solved and the background sound of the video stoped, and the code is this below
#IBAction func next(_ sender: Any) {
if let vc = self.storyboard?.instantiateViewController(withIdentifier: "ViewControllerAA") as? ViewControllerAA {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = vc
}
}
How would i go about making a local .mp4 file with no sound play on a loop, so it would only take up part of the screen and have no user controls. Just a looping video, sort of like a gif. I am using xcode, swift2.
class ViewController: UIViewController {
var playerViewController = AVPlayerViewController()
var playerView = AVPlayer()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewDidAppear(animated: Bool) {
var fileURL = NSURL(fileURLWithPath: "/Users/Mantas/Desktop/123/123/video-1453562323.mp4.mp4")
playerView = AVPlayer(URL: fileURL)
playerViewController.player = playerView
self.presentViewController(playerViewController, animated: true){
self.playerViewController.player?.play()
}
}
}
I have made this, it plays the video, but in full screen, i dont know how to make it only take up part of the screen and how to make it loop
Alternate version in Swift 3.0:
Add these properties:
fileprivate var player: AVPlayer? {
didSet { player?.play() }
}
fileprivate var playerObserver: Any?
Add this to your deinit:
deinit {
guard let observer = playerObserver else { return }
NotificationCenter.default.removeObserver(observer)
}
Add this function:
func videoPlayerLayer() -> AVPlayerLayer {
let fileURL = URL(fileURLWithPath: mediaPath)
let player = AVPlayer(url: fileURL)
let resetPlayer = {
player.seek(to: kCMTimeZero)
player.play()
}
playerObserver = NotificationCenter.default.addObserver(forName: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem, queue: nil) { notification in
resetPlayer()
}
self.player = player
return AVPlayerLayer(player: player)
}
Then add to your layer wherever you feel like (viewDidLoad, viewDidAppear, viewDidFinishLayingOutSubviews):
let playerLayer = videoPlayerLayer()
playerLayer.frame = view.bounds
view.layer.insertSublayer(playerLayer, at: 0)
Adding observer when video going to finish you can make replay the video
override func viewDidAppear(animated: Bool) {
super.viewDidAppear()
var fileURL = NSURL(fileURLWithPath: "/Users/Mantas/Desktop/123/123/video-1453562323.mp4.mp4")
playerView = AVPlayer(URL: fileURL)
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "playerItemDidReachEnd:",
name: AVPlayerItemDidPlayToEndTimeNotification,
object: self.playerView.currentItem) // Add observer
playerViewController.player = playerView
//amend the frame of the view
self.playerViewController.player.frame = CGRectMake(0, 0, 200, 200)
//reset the layer's frame, and re-add it to the view
var playerLayer: AVPlayerLayer = AVPlayerLayer.playerLayerWithPlayer(self.playerView)
playerLayer.frame = videoHolderView.bounds
videoHolderView.layer.addSublayer(playerLayer)
/* Full Screen
self.presentViewController(playerViewController, animated: true){
self.playerViewController.player?.play()
} */
}
func playerItemDidReachEnd(notification: NSNotification) {
self.playerView.seekToTime(kCMTimeZero)
self.playerView.play()
}
For a seemless repeating video without a black flash. Use the AVPlayerLooper like so:
private var player: AVQueuePlayer!
private var playerLayer: AVPlayerLayer!
private var playerItem: AVPlayerItem!
private var playerLooper: AVPlayerLooper!
override func viewDidLoad(){
super.viewDidLoad()
let path = Bundle.main.path(forResource: "background_cloudy", ofType: "mov")
let pathURL = URL(fileURLWithPath: path!)
let duration = Int64( ( (Float64(CMTimeGetSeconds(AVAsset(url: pathURL).duration)) * 10.0) - 1) / 10.0 )
player = AVQueuePlayer()
playerLayer = AVPlayerLayer(player: player)
playerItem = AVPlayerItem(url: pathURL)
playerLooper = AVPlayerLooper(player: player, templateItem: playerItem,
timeRange: CMTimeRange(start: kCMTimeZero, end: CMTimeMake(duration, 1)) )
playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
playerLayer.frame = view.layer.bounds
view.layer.insertSublayer(playerLayer, at: 1)
}
This is tested with Swift 5, I found in https://gist.github.com/lanserxt/33fd8c479185cba181497315299e0e31
import UIKit
import AVFoundation
class LoopedVideoPlayerView: UIView {
fileprivate var videoURL: URL?
fileprivate var queuePlayer: AVQueuePlayer?
fileprivate var playerLayer: AVPlayerLayer?
fileprivate var playbackLooper: AVPlayerLooper?
func prepareVideo(_ videoURL: URL) {
let playerItem = AVPlayerItem(url: videoURL)
self.queuePlayer = AVQueuePlayer(playerItem: playerItem)
self.playerLayer = AVPlayerLayer(player: self.queuePlayer)
guard let playerLayer = self.playerLayer else {return}
guard let queuePlayer = self.queuePlayer else {return}
self.playbackLooper = AVPlayerLooper.init(player: queuePlayer, templateItem: playerItem)
playerLayer.videoGravity = .resizeAspectFill
playerLayer.frame = self.frame
self.layer.addSublayer(playerLayer)
}
func play() {
self.queuePlayer?.play()
}
func pause() {
self.queuePlayer?.pause()
}
func stop() {
self.queuePlayer?.pause()
self.queuePlayer?.seek(to: CMTime.init(seconds: 0, preferredTimescale: 1))
}
func unload() {
self.playerLayer?.removeFromSuperlayer()
self.playerLayer = nil
self.queuePlayer = nil
self.playbackLooper = nil
}
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func layoutSubviews() {
self.playerLayer?.frame = self.bounds
}
}