- 巨坑: 被URLAssetWithURL整的獲取的duration一直為0, why,郁悶不已
各種百度\google搜索 URLAssetWithURL用法, 實(shí)在難找
- 錯(cuò)誤代碼
//只有這個(gè)方法獲取時(shí)間是準(zhǔn)確的 audioPlayer.duration獲得的時(shí)間不準(zhǔn)
AVURLAsset* audioAsset1 =[AVURLAsset URLAssetWithURL:[NSURL URLWithString:mp3FilePath] options:nil];
CMTime audioDuration1 = audioAsset1.duration;
float audioDurationSeconds1 =CMTimeGetSeconds(audioDuration1);
還好終于stackOverflow找到答案, 必須在此福利大伙一下,怪自己被坑的太慘
- 正確代碼
//只有這個(gè)方法獲取時(shí)間是準(zhǔn)確的 audioPlayer.duration獲得的時(shí)間不準(zhǔn)
AVURLAsset* audioAsset =[AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:mp3FilePath] options:nil];
CMTime audioDuration = audioAsset.duration;
float audioDurationSeconds =CMTimeGetSeconds(audioDuration);
- 關(guān)鍵代碼
[NSURL fileURLWithPath:mp3FilePath]
// 存到沙河的 mp3FilePath 路徑
感謝StackOverFlow的解答者
https://stackoverflow.com/questions/4101380/avurlasset-refuses-to-load-video?rq=1