Получение метки времени с локальным AVPlayer Swift - PullRequest
0 голосов
/ 27 июня 2019

У меня проблемы с созданием метки времени, когда видео приостановлено. Я хочу, чтобы в моем всплывающем окне создания заметок было приостановлено воспроизведение видео, чтобы пользователь знал, когда он сделал заметку. У меня есть время печати видео в консоли через .addPeriodicTimeObserver.

Я использовал player.addPeriodicTimeObserver, чтобы напечатать время, когда видео находится в консоли, и попробовал множество подходов, чтобы поместить его в cell.detailTextLabel.text. Любая помощь будет принята с благодарностью!

func playVideo(_ sender: Any) {


    guard let path = Bundle.main.path(forResource: "Hot Work Scene 1 Graphics Test 2 JR", ofType:"mp4") else {
        debugPrint("Video.mp4 not found")
        return
    }

    let player = AVPlayer(url: URL(fileURLWithPath: path))
    playerController.player = player

    self.addChild(playerController)
    self.view.addSubview(playerController.view)

    player.play()
    player.pause()
    let time_interval = CMTime(value: 1, timescale: 2)

    player.addPeriodicTimeObserver(forInterval: time_interval, queue: DispatchQueue.main, using: { (progressTime) in
        let current_time = String.duration(from: progressTime)
        print(current_time)

    })
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
    if cell == nil {
        cell = UITableViewCell(style: .default, reuseIdentifier: "Cell")
    }
        cell?.textLabel?.text = noteData[indexPath.row]

        cell?.detailTextLabel?.text = String.duration(from: CMTime(value: 1, timescale: 2))


    return cell!
}

extension String {

    static func duration(from time: CMTime) -> String {
        let totalSeconds = CMTimeGetSeconds(time)
        let secondsText = String(format: "%02d", Int(totalSeconds) % 60)
        let minutesText = String(format: "%02d", Int(totalSeconds) / 60)
        return  "\(minutesText):\(secondsText)"


    }

}

Раздел подробностей ячейки просто производит 00:00, поскольку расширение предоставляет, но я хотел бы, чтобы фактическое время, когда видео приостановилось, чтобы быть в этой позиции.

...