gpt4 book ai didi

ios - 出现和关闭 AVPlayer Controller 的问题

转载 作者:行者123 更新时间:2023-11-28 13:53:34 24 4
gpt4 key购买 nike

所以我有一个应用程序可以拍摄和录制要发送到服务器并稍后查看的视频。

事件的先后顺序如下1. 视频录制2.添加过滤器或文本3.发送到服务器4.关闭avplayer并返回相机

一切正常,但在第四步,avplayer 从未完全解雇,我所看到的就是这个。

enter image description here

这是 avplayer Controller 上所有 UI 组件减去实际视频的图像。

我确保我调用了 present 和 dismiss,所以不存在我使用错误的 View Controller 呈现和解散方法组合的问题。当我到达此屏幕时,我必须再次按 X 才能返回相机,但事实并非如此。

/// Add the story to firebase
func handleAddToStory() {
print("Attempting to add to story")
self.dismiss(animated: true, completion: nil)
// hide the color slider so we can return the image of the tapView that contains the text field if they added one
colorSlider.isHidden = true
colorSlider.isHidden = false





DispatchQueue.global(qos: .background).async {
print("This is run on the background queue")

let videoImage = self.imageWithView(inView: self.tapView)


// Export the video
self.video?.exportFilterVideo(videoComposition: self.avVideoComposition , completion: { (url) in

if let videoImage = videoImage {

let filterVideoAsset = AVAsset(url: url! as URL)

// Now merge the filtered video with tapView image which will contain the textfield if the user added one
Merge(config: .standard).overlayVideo(video: filterVideoAsset, overlayImage: videoImage, completion: { (finalVideoUrl) in

// Upload to firebase storage
let dateFormatter = ISO8601DateFormatter()
let timeStamp = dateFormatter.string(from: Date())
let uid = User.current.uid
let storageRef = Storage.storage().reference().child("event_stories").child(self.eventKey).child(uid).child(timeStamp + ".mp4")
StorageService.uploadVideo(finalVideoUrl! as URL, at: storageRef) { (downloadUrl) in
guard let downloadUrl = downloadUrl else {
return
}

let videoUrlString = downloadUrl.absoluteString
print(videoUrlString)
// Post to firebase
PostService.create(for: self.eventKey, for: videoUrlString)
}

}, progressHandler: { _ in })


} else {

let dateFormatter = ISO8601DateFormatter()
let timeStamp = dateFormatter.string(from: Date())
let uid = User.current.uid
let storageRef = Storage.storage().reference().child("event_stories").child(self.eventKey).child(uid).child(timeStamp + ".mp4")
StorageService.uploadVideo(url! as URL, at: storageRef) { (downloadUrl) in
guard let downloadUrl = downloadUrl else {
return
}

let videoUrlString = downloadUrl.absoluteString
print(videoUrlString)
PostService.create(for: self.eventKey, for: videoUrlString)
}
//svprogresshud insert here

}

})







DispatchQueue.main.async {
print("This is run on the main queue, after the previous code in outer block")
self.dismiss(animated: true, completion: nil)
self.videoPlayer?.replaceCurrentItem(with: nil)

}
}


}

这是处理添加到服务器的函数。有一些异步任务正在进行,但那些不应该篡改可以在底部看到的 Controller 的解雇。有谁知道为什么 View Controller 仍然存在?

下面是呈现上述 View Controller 的代码片段。

  if let event = self.event {
let video = AVURLAsset(url: videoURL)
let videoViewController = FilterVideoViewController(video: video)
videoViewController.event = event
SVProgressHUD.dismiss(completion: {
self.present(videoViewController, animated: false, completion: nil)
})

}

最佳答案

这些部分

video?.exportFilterVideo(videoComposition: avVideoComposition , completion: { (url) in 
Merge(config: .standard).overlayVideo(video: filterVideoAsset, overlayImage: videoImage, completion: { (finalVideoUrl) in

使主线程非常繁忙。所以你需要一个像

这样的后台队列
 func handleAddToStory() {
print("Attempting to add to story")

// hide the color slider so we can return the image of the tapView that contains the text field if they added one
colorSlider.isHidden = true
let videoImage = self.imageWithView(inView: self.tapView)
colorSlider.isHidden = false
self.dismiss(animated:false, completion: nil)
self.videoPlayer?.replaceCurrentItem(with: nil)


DispatchQueue.main.asyncAfter(deadline: .now() + 0.7 ) {

video?.exportFilterVideo(videoComposition: avVideoComposition , completion: { (url) in

if let videoImage = videoImage {

let filterVideoAsset = AVAsset(url: url! as URL)

// Now merge the filtered video with tapView image which will contain the textfield if the user added one
Merge(config: .standard).overlayVideo(video: filterVideoAsset, overlayImage: videoImage, completion: { (finalVideoUrl) in

upload(finalVideoUrl! as URL)

}, progressHandler: { _ in })


} else {

upload(url! as URL)

}

})

}


}

func upload(_ url:URL) {

DispatchQueue.global().async {

let dateFormatter = ISO8601DateFormatter()
let timeStamp = dateFormatter.string(from: Date())
let uid = User.current.uid
let storageRef = Storage.storage().reference().child("event_stories").child(self.eventKey).child(uid).child(timeStamp + ".mp4")
StorageService.uploadVideo(url, at: storageRef) { (downloadUrl) in
guard let downloadUrl = downloadUrl else {
return
}

let videoUrlString = downloadUrl.absoluteString
print(videoUrlString)
PostService.create(for: self.eventKey, for: videoUrlString)
}

}

}

关于ios - 出现和关闭 AVPlayer Controller 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54205810/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com