出现和关闭 AVPlayer 控制器的问题
Issue with presenting and dismissing of AVPlayer Controller
所以我有一个应用程序可以拍摄和录制要发送到服务器并稍后查看的视频。
来龙去脉如下
1. 视频录制
2.添加过滤器或文本
3.发送到服务器
4.关闭avplayer并返回相机
一切正常,但在第四步,avplayer 从未完全关闭,我只看到了这个。
这是 avplayer 控制器上所有 UI 组件减去实际视频的图像。
我确保我调用了 present 和 dismiss,所以不存在我使用错误的视图控制器呈现和解散方法组合的问题。当我到达此屏幕时,我必须再次按 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)
}
}
}
这是处理添加到服务器的函数。有一些异步任务正在进行,但那些不应该篡改可以在底部看到的控制器的解雇。有谁知道为什么视图控制器仍然存在?
下面是呈现上述视图控制器的代码片段。
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)
}
}
}
所以我有一个应用程序可以拍摄和录制要发送到服务器并稍后查看的视频。
来龙去脉如下 1. 视频录制 2.添加过滤器或文本 3.发送到服务器 4.关闭avplayer并返回相机
一切正常,但在第四步,avplayer 从未完全关闭,我只看到了这个。
这是 avplayer 控制器上所有 UI 组件减去实际视频的图像。
我确保我调用了 present 和 dismiss,所以不存在我使用错误的视图控制器呈现和解散方法组合的问题。当我到达此屏幕时,我必须再次按 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)
}
}
}
这是处理添加到服务器的函数。有一些异步任务正在进行,但那些不应该篡改可以在底部看到的控制器的解雇。有谁知道为什么视图控制器仍然存在?
下面是呈现上述视图控制器的代码片段。
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)
}
}
}