Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

Swift. Play() and Pause() don't work on AVPlayer on the Youtube embed video (((

$
0
0

Please tell me why tap on the play and pause buttons do not work.

I have UIButton, under the video webview, and I try to press it to pause, it does not work.

Pressing is recognized! I checked through the print.

What could be the problem ?

Maybe the problem is in the layer?

My Control buttons are not on the video, there UNDER it, under webview.

upd: playerControl() I even put to viewDidLoad

webView

    var webView: WKWebView! = {    let configuration = WKWebViewConfiguration()    configuration.allowsInlineMediaPlayback = true    let webView = WKWebView(frame: .zero, configuration: configuration)    webView.translatesAutoresizingMaskIntoConstraints = false    return webView    }()

Button

    lazy var pauseButton: UIButton = {    let button = UIButton(type: .system)    let image = UIImage(named: "Pause")    button.setImage(image, for: .normal)    button.tintColor = .white    button.translatesAutoresizingMaskIntoConstraints = false    button.addTarget(self, action: #selector(tapPause), for: .touchUpInside)    return button}()@objc func tapPause() {    print("pause player")    player?.pause()}

playerControl

var player: AVPlayer?func playerControl() {    if let url = currentUrl {        player = AVPlayer(url: url)    let playerLayer = AVPlayerLayer(player: player)    self.webView.layer.addSublayer(playerLayer)    playerLayer.frame = self.webView.frame    player!.play()    player!.pause()    }}

Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>