Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import AVFoundation
- import AVKit
- class ViewController: UIViewController {
- var player: AVPlayer!
- let videoURL = URL( string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" )
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- videoPlay()
- }
- func videoPlay(){
- player = AVPlayer(url: videoURL!)
- let playerController = AVPlayerViewController()
- playerController.player = player
- self.addChild(playerController)
- self.view.addSubview(playerController.view)
- playerController.view.frame = CGRect(x: 0, y: 20, width: 375, height: 207)
- player.play()
- if player.rate != 0 && player.error == nil {
- print("video player is playing.................")
- NotificationCenter.default.addObserver(self,selector: #selector(gettime(_:)),name: nil,object: nil)
- } else {
- print("video player is NOT playing.")
- }
- }
- @objc func gettime(_ notification: Notification){
- let currentTime = Float(player.currentTime().value)
- print(currentTime)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement