【问题标题】:Video player: Play,Pause, forward and backward methods IOS Swift 3视频播放器:播放、暂停、前进和后退方法 IOS Swift 3
【发布时间】:2018-07-04 07:29:56
【问题描述】:

如何通过时差获取此按钮事件/委托(播放、暂停、前进和后退)。

这里我把代码放在下面。请建议我们可以使用其他玩家参加此活动

player = AVPlayer(url:URL(fileURLWithPath: objpdfURL));
NotificationCenter.default.addObserver(self, selector: #selector(VedioPlayVC.didfinishplaying(note:)),name:NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)

NotificationCenter.default.addObserver(self, selector:#selector(VedioPlayVC.Stop(note:)), name: .kAVPlayerViewControllerDismissingNotification, object: nil);

NotificationCenter.default.addObserver(self, selector: #selector(VedioPlayVC.Jump(note:)),name:NSNotification.Name.AVPlayerItemTimeJumped, object: nil)

playerController.player = player
playerController.allowsPictureInPicturePlayback = true
playerController.delegate = self
playerController.player?.play()
self.present(playerController,animated:true,completion:nil)

【问题讨论】:

    标签: ios swift3 avplayer avplayerviewcontroller video-player


    【解决方案1】:

    希望这会有所帮助

    @IBAction func btnPlayAction(_ sender: UIButton) {
        if isVideoPlaying{
            player.pause()
            sender.setTitle("Play", for: .normal)
        }else{
            player.play()
            sender.setTitle("Pause", for: .normal)
        }
        isVideoPlaying = !isVideoPlaying
    }
    
    @IBAction func btnForwardAction(_ sender: UIButton) {
        guard let duration = player.currentItem?.duration else { return }
        let currentTime = CMTimeGetSeconds(player.currentTime())
        let newTime = currentTime + 5.0
        if newTime < (CMTimeGetSeconds(duration) - 5.0){
            let time: CMTime = CMTimeMake(value: Int64(newTime*1000), timescale: 1000)
            player.seek(to: time)
        }
    }
    @IBAction func btnBackwardAction(_ sender: UIButton) {
    
        let currentTime = CMTimeGetSeconds(player.currentTime())
        var newTime = currentTime - 5.0
    
        if newTime < 0{
            newTime = 0
        }
        let time: CMTime = CMTimeMake(value: Int64(newTime*1000), timescale: 1000)
        player.seek(to: time)
    
    }
    

    【讨论】:

    • 你能用视图详细说明这个方法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-06
    • 2017-09-25
    相关资源
    最近更新 更多