Created
January 30, 2018 18:36
-
-
Save meyusufdemirci/378cc7de3fa3f41c97f4d51660b665d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import AVKit | |
class ViewController: UIViewController { | |
let playerController = AVPlayerViewController() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// if you have a url of video | |
// let player = AVPlayer(url: URL(string: "video url")!) | |
let path = Bundle.main.path(forResource: "Mahmut Orhan - Game Of Thrones", ofType: "mp4") | |
// if you have a path of local video | |
let player = AVPlayer(url: URL(fileURLWithPath: path!)) | |
playerController.player = player | |
playerController.view.frame = CGRect(x: 0, y: 200, width: UIScreen.main.bounds.width, height: 250) | |
self.view.addSubview(playerController.view) | |
playerController.player?.play() | |
NotificationCenter.default.addObserver(self, selector: #selector(onRotated), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil) | |
} | |
@objc func onRotated() { | |
// portrait | |
if UIDeviceOrientationIsPortrait(UIDevice.current.orientation) { | |
playerController.view.frame = CGRect(x: 0, y: 200, width: UIScreen.main.bounds.width, height: 250) | |
} | |
// landscape | |
else if UIDeviceOrientationIsLandscape(UIDevice.current.orientation) { | |
playerController.view.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment