我正在开发视频共享 iOS 应用程序并Firebase5用作后端。它允许用户可以选择视频并将其发送到存储。当我尝试时,视频无法推送到database服务器。下面是我的代码:
static func uploadVideoToFirebaseStorage(videoUrl: URL, onSuccess: @escaping (_ videoUrl: String) -> Void) {
let videoIdString = NSUUID().uuidString
//Config.STORAGE_ROOT_REF is var STORAGE_ROOT_REF = "gs://****-cdc3c.appspot.com"
let storageRef = Storage.storage().reference(forURL: Config.STORAGE_ROOT_REF).child("posts").child(videoIdString)
storageRef.putFile(from: videoUrl, metadata: nil) { (metadata, error) in
if error != nil {
ProgressHUD.showError(error!.localizedDescription)
return
}
}
storageRef.downloadURL(completion: { (url, error) in
if let error = error {
return
}else {
let videoUrl = url!.absoluteString
onSuccess(videoUrl)
}
})
}
Run Code Online (Sandbox Code Playgroud) 我正在使用AVQueuePlayer播放远程音频文件列表。我想默认实现重复所有。
我的方法是,我正在观察AVPlayerItemDidPlayToEndTime通知,并在播放完毕后将 playerItem 添加到队列的后面。
在nextAudio(notification: Notification)不运行在所有。需要这方面的帮助,或者更好的方式来实现无限游戏。
func playAudio(_ items: [AVPlayerItem]) {
let avPlayerVC = AVPlayerViewController()
let player = AVQueuePlayer(items: items)
player.actionAtItemEnd = .pause
avPlayerVC.player = player
for item in items {
NotificationCenter.default.addObserver(self,
selector: #selector(FilesViewController.nextAudio(notification:)),
name: .AVPlayerItemDidPlayToEndTime, object: item)
}
present(avPlayerVC, animated: true) {
self.player.play()
}
}
@objc func nextAudio(notification: Notification) {
debugPrint("nextAudio was called")
guard player != nil else { return }
debugPrint("AVPlayerItemDidPlayToEndTime notif info \(notification.userInfo)")
if let currentItem = notification.userInfo!["object"] as? AVPlayerItem { …Run Code Online (Sandbox Code Playgroud)