同一個(gè)文件路徑恢口,不同初始化方法,存在audioPlayer初始化失敗的情況
NSURL *contentURL = [NSURL fileURLWithPath:_fileUrl];
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:contentURL error:&error];
NSData *data = [NSData dataWithContentsOfURL:contentURL];
self.audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:&error];
// initWithContentsOfURL:初始化失敗
Error Domain=NSOSStatusErrorDomain Code=1685348671 "(null)"
音頻文件參數(shù)
通過URL初始化 | 通過data初始化 |
---|---|
Name: xxx.mp3 | Name: 222.mp3 |
Format: MPEG Audio | Format : Wave |
Size: 4.23M | Size: 358 KiB |
Duration: 4 min 37 s | Duration: 11 s 470 ms |
Overal bit rate mode: Variable | Overal bit rate mode: Constant |
Overal bit rate: 128 kb/s | Overal bit rate: 256 kb/s |
Writing library: Lavf57.83.100 | IsTruncated: YES |
FileExtension_Invalid: act at9 wav | |
- | - |
Format: MPEG Audio | Format : PCM |
Bit rate mode: Variable | Bit rate mode: Constant |
Format version: Version 1 | --- |
Format profile: Layer 3 | --- |
Format settings: Joint stereo | Format settings: Little / Signed |
Channel(s): 2 channels | Channel(s): 1 channel |
Sampling rate: 44.1 kHz | Sampling rate: 16.0 kHz |
Format rate: 38.281 FPS (1152 SPF) | --- |
Compression mode: Lossy | --- |
--- | Codec ID: 1 |
--- | Bit depth: 16 bits |
2021.03.09更新
iOS使用AVAudioPlayer播放data音頻文件遇到的問題
- 檢查發(fā)現(xiàn),code= 2003334207的可能原因是:跟文件的檢測有關(guān)浪南、在下載文件時(shí)不完整父款,所以創(chuàng)建失敗了!
- 可能不是沒有本地化完成的問題斩松,直接播放即可
NSError *error;
self.audioPlayer = [[AVAudioPlayer alloc] initWithData:vData fileTypeHint:AVFileTypeWAVE error:&error];//AVFileTypeWAVE 為音頻格式
//替換
NSError *error;
self.audioPlayer = [[AVAudioPlayer alloc] initWithData:vData error:&error];