我正在尝试将音频播放器中的 url 转换为 AVAsset,以便我能够根据自己的喜好操纵音轨。(我只想能够修剪文件)。不幸的是,我遇到了资产未正确转换的问题。当我在转换之前打印音频 url 的持续时间时,它会正确打印出持续时间。不幸的是,当我将其转换为 AVAsset 时,它说持续时间为 0。这是怎么回事?任何指导将不胜感激!
func trimmingFunc() {
try? audioPlayer = AVAudioPlayer(contentsOf: audioURL!)
passingTime = audioPlayer.duration
audioPlayer.delegate = self
let currentDuration = audioPlayer.duration
print(currentDuration) //correctly prints duration
let filePath = URL(fileURLWithPath: (("\(String(describing: audioPlayer.url!))")))
print(filePath) //correctly prints filePath
let currentAsset = AVAsset(url: filePath)
print(CMTimeGetSeconds(currentAsset.duration) //This is printing 0
}
Run Code Online (Sandbox Code Playgroud) 所以我通过自定义 UICollectionView 访问用户的视频和照片,我的问题是,当我尝试通过手机上传视频到 firebase 时,我收到此错误:
\n\n2017-09-03 13:09:20.884509-0400 Project[5797:2021536] Cannot get file size: Error Domain=NSCocoaErrorDomain Code=257 "The file \xe2\x80\x9cIMG_3476.MP4\xe2\x80\x9d couldn\xe2\x80\x99t be opened because you don\xe2\x80\x99t have permission to view it." UserInfo={NSURL=file:///var/mobile/Media/DCIM/103APPLE/IMG_3476.MP4, NSFilePath=/var/mobile/Media/DCIM/103APPLE/IMG_3476.MP4, NSUnderlyingError=0x17064f450 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}\n /var/mobile/Media/DCIM/103APPLE/IMG_3476.MP4\n2017-09-03 13:09:21.261767-0400 Project[5797:2021536] Body file is unreachable: /var/mobile/Media/DCIM/103APPLE/IMG_3476.MP4\n Error Domain=NSCocoaErrorDomain Code=257 "The file \xe2\x80\x9cIMG_3476.MP4\xe2\x80\x9d couldn\xe2\x80\x99t be opened because you don\xe2\x80\x99t have permission to view it." UserInfo={NSURL=file:///var/mobile/Media/DCIM/103APPLE/IMG_3476.MP4, NSFilePath=/var/mobile/Media/DCIM/103APPLE/IMG_3476.MP4, NSUnderlyingError=0x170651b20 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}\nRun Code Online (Sandbox Code Playgroud)\n\n这是我加载文件的地方
\n\nstruct Media {\n var …Run Code Online (Sandbox Code Playgroud)