【问题标题】:Detecting Click of Close button of AVPlayerViewController [duplicate]检测 AVPlayerViewController 的关闭按钮的点击 [重复]
【发布时间】:2018-08-09 07:11:43
【问题描述】:

视频播放有一个功能,就像linkedIn视频播放一样。 我正在使用 AVPlayerViewController 播放 video.in 我面临的问题是当 AVPlayerviewController 关闭时我无法检测到关闭按钮事件。 是否有任何观察者或方法会在 AVPlayerController 关闭时调用?

【问题讨论】:

标签: ios swift media-player avplayerviewcontroller


【解决方案1】:

Swift 3.2

import UIKit
import AVKit
import AVFoundation

class PlayResourcesVC: UIViewController {

    //MARK:- Variable Declarations
    var video_Url:String = String()
    let playerController = AVPlayerViewController()


    //MARK:- ViewDidload
    override func viewDidLoad() {
        super.viewDidLoad()

        let player = AVPlayer(url: URL(string: video_Url)!)
        playerController.player = player
        self.present(playerController, animated: false) {
            player.play()
            self.playerController.addObserver(self, forKeyPath: #keyPath(UIViewController.view.frame), options: [.old, .new], context: nil)
        }
    }

    override func viewDidDisappear(_ animated: Bool) {
        NotificationCenter.default.removeObserver(NSNotification.Name.AVPlayerItemDidPlayToEndTime)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }


    //MARK:- All Method
    func playerDidFinishPlaying(note: NSNotification) {
        self.navigationController?.popViewController(animated: false)
    }

    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        self.playerController.removeObserver(self, forKeyPath: #keyPath(UIViewController.view.frame))
        self.navigationController?.popViewController(animated: false)
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    • 2012-10-16
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多