播放视频向后
我想要什么,基本上扭转了AVAsset和输出的视频文件,我发现这个链接 - https://github.com/tempire/ReverseAVAsset/blob/master/AVAsset.swift播放视频向后
这是我做过什么:
import UIKit import AVFoundation
import AVKit
class ViewController: UIViewController {
var playerViewController = AVPlayerViewController()
var playerView = AVPlayer()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let path = Bundle.main.path(forResource: "video", ofType: "mov")
let outputUrl = URL(fileURLWithPath: "\(NSUUID().uuidString)video.mov")
let originalAsset = AVAsset(url: URL(fileURLWithPath: path!))
let reversedAsset = originalAsset.reversedAsset(outputUrl)
playerView = AVPlayer(playerItem: AVPlayerItem(asset: reversedAsset!))
playerViewController.player = playerView
present(playerViewController, animated: true) {
self.playerViewController.player?.play()
}
}
}
但其没有工作,这是我结束了:
我觉得我做的事情错outputURL,请帮助,如果你知道该怎么做
回答:
问题是与输出URL,这是做
import UIKit import AVFoundation
import AVKit
class ViewController: UIViewController {
var playerViewController = AVPlayerViewController()
var playerView = AVPlayer()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let path = Bundle.main.path(forResource: "video", ofType: "mov")
//Correct way
var outputURL: URL?
do {
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
outputURL = documentsURL.appendingPathComponent("\(NSUUID().uuidString)newvideo.mp4")
}
let originalAsset = AVAsset(url: URL(fileURLWithPath: path!))
let reversedAsset = originalAsset.reversedAsset(outputUrl)
playerView = AVPlayer(playerItem: AVPlayerItem(asset: reversedAsset!))
playerViewController.player = playerView
present(playerViewController, animated: true) {
self.playerViewController.player?.play()
}
}
}
以上是 播放视频向后 的全部内容, 来源链接: utcz.com/qa/260236.html