1. 如何播放本地文件:
仿效:
- (id)initPlayerWithURL:(NSURL *)url delegate:(id<AudioPlayerDelegate>) aDelegate { self = [super init]; delegate = aDelegate; queue = [[AudioQueue alloc] initQueueWithDelegate:self]; fileStream = [[AudioFileStream alloc] initFileStreamWithDelegate:self]; [fileStream open]; request = [[AudioRequest alloc] initRequestWithURL:url delegate:self]; return self; }
添加:
- (id)initPlayerWithFile:(NSString *)url delegate:(id<AudioPlayerDelegate>) aDelegate { self = [super init]; delegate = aDelegate; queue = [[AudioQueue alloc] initQueueWithDelegate:self]; fileStream = [[AudioFileStream alloc] initFileStreamWithDelegate:self]; [fileStream open]; NSData *data = [[NSData alloc] initWithContentsOfFile:url]; if ([fileStream parseBytes:data] != noErr) { NSLog(@"***********error**********"); } return self; }
2. 无法都去部分audio的filetype的错误:
如果不指定audio的filetype,让coreaudio自己判断:
// We pass 0 as a fileTypeHint because CoreAudio is pretty good at // determining the fileType for us (and may ignore our hint anyway.) return AudioFileStreamOpen(self, propertyCallback, packetCallback, 0, &streamID);
对于部分audio会有如下错误:
error number: 1954115647 error code: typ?
解决方法是指定audio的类型
// We pass 0 as a fileTypeHint because CoreAudio is pretty good at // determining the fileType for us (and may ignore our hint anyway.) return AudioFileStreamOpen(self, propertyCallback, packetCallback, kAudioFileMP3Type, &streamID);