同一个文件路径,不同初始化方法,存在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)"
音频文件参数
| 通过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音频文件遇到的问题
- 检查发现,code= 2003334207的可能原因是:跟文件的检测有关、在下载文件时不完整,所以创建失败了!
- 可能不是没有本地化完成的问题,直接播放即可
NSError *error;
self.audioPlayer = [[AVAudioPlayer alloc] initWithData:vData fileTypeHint:AVFileTypeWAVE error:&error];//AVFileTypeWAVE 为音频格式
//替换
NSError *error;
self.audioPlayer = [[AVAudioPlayer alloc] initWithData:vData error:&error];