How to play video with AVPlayerViewController (AVKit) in Swift
By : Sazzad Hossain
Date : March 29 2020, 07:55 AM
it should still fix some issue How do you play a video with AV Kit Player View Controller in Swift? , Swift 3.x - 5.x Necessary: import AVKit, import AVFoundation code :
let videoURL = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
let player = AVPlayer(url: videoURL!)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
playerViewController.player!.play()
}
let videoURL = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
let player = AVPlayer(url: videoURL!)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.view.bounds
self.view.layer.addSublayer(playerLayer)
player.play()
NSURL *videoURL = [NSURL URLWithString:@"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
[self presentViewController:playerViewController animated:YES completion:^{
[playerViewController.player play];
}];
NSURL *videoURL = [NSURL URLWithString:@"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = self.view.bounds;
[self.view.layer addSublayer:playerLayer];
[player play];
|
Pre-Roll Video Ad with AVPlayerViewController
By : cordovacoder
Date : March 29 2020, 07:55 AM
it should still fix some issue You need to call preparePrerollAds in your viewDidLoad to download the advertisement before attempting to present it. code :
[AVPlayerViewController preparePrerollAds];
|
Play a video from Youtube in a AVPlayerViewController in Swift
By : gaurav
Date : March 29 2020, 07:55 AM
Hope that helps AVPlayer only plays movie files, and YouTube videos aren't directly exposed as movie files at their URL. It looks like the preferred way to handle YouTube videos is to embed a web view into your app. See this page for information from Google on how to do that.
|
In swift, how to detect touch while playing video in AVPlayerViewController
By : Mohammed Salahudeen
Date : March 29 2020, 07:55 AM
it fixes the issue The solution is to create a Base class of AVPlayerViewController and override touchesBegan(_:with:) method: Swift 2: code :
class CustomAVPlayerViewController: AVPlayerViewController {
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
print("touchesBegan")
}
}
let videoURL = NSURL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
let player = AVPlayer(URL: videoURL!)
let playerViewController = CustomAVPlayerViewController()
playerViewController.player = player
self.presentViewController(playerViewController, animated: true) {
playerViewController.player!.play()
}
class CustomAVPlayerViewController: AVPlayerViewController {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
print("touchesBegan")
}
}
let videoURL = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
let player = AVPlayer(url: videoURL!)
let playerViewController = CustomAVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
playerViewController.player!.play()
}
|
AVPlayerViewController video with swift 2.0 xcode 7 beta 3
By : Bgs
Date : March 29 2020, 07:55 AM
will be helpful for those in need "SampleVideo_1080x720_1mb.mp4", ofType:"mp4" Shouldn't this be ""SampleVideo_1080x720_1mb", ofType:"mp4"
|