Reputation: 1832
I am trying this code to achieve online streaming/buffering with the help of amazing audio engine, but it throws me following error:
AEAudioFilePlayer.m:148: AudioFileOpenURL: 'wht?' (2003334207)
Here is the code:
- (void)viewDidLoad {
[super viewDidLoad];
self.audioController = [[AEAudioController alloc] initWithAudioDescription:[AEAudioController nonInterleaved16BitStereoAudioDescription] inputEnabled:YES];
_audioController.preferredBufferDuration = 0.005;
[_audioController start:NULL];
[self initWithAudioController:self.audioController];
AEAudioFilePlayer *oneshot = [AEAudioFilePlayer audioFilePlayerWithURL:[NSURL URLWithString:self.urlOfSong] error:NULL];
_oneshot.removeUponFinish = YES;
[_audioController addChannels:[NSArray arrayWithObject:oneshot]];
}
- (id)initWithAudioController:(AEAudioController*)audioController {
self.audioController = audioController;
NSError *error = NULL;
BOOL result = [self.audioController start:&error];
if ( !result ) {
// Report error
NSLog(@"The Amazing Audio Engine didn't start!");
} else {
NSLog(@"The Amazing Audio Engine started perfectly!");
}
return self;
}
Upvotes: 2
Views: 311
Reputation: 1832
in .h file
@property (nonatomic, strong) AEAudioFilePlayer *player;
@property (nonatomic, strong) AEAudioController *audioController;
in .m file
-(void)playAudio
{
self.audioController = [[AEAudioController alloc] initWithAudioDescription:[AEAudioController nonInterleaved16BitStereoAudioDescription] inputEnabled:YES];
_audioController.preferredBufferDuration = 0.005;
[_audioController start:NULL];
[self initWithAudioController:self.audioController];
if ( _player ) {
[_audioController removeChannels:@[_player]];
self.player = nil;
} else {
NSArray *documentsFolders = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [documentsFolders[0] stringByAppendingPathComponent:kFileName];
if ( ![[NSFileManager defaultManager] fileExistsAtPath:path] ) return;
NSError *error = nil;
self.player = [AEAudioFilePlayer audioFilePlayerWithURL:[NSURL fileURLWithPath:path] error:&error];
if ( !_player ) {
[[[UIAlertView alloc] initWithTitle:@"Error"
message:[NSString stringWithFormat:@"Couldn't start playback: %@", [error localizedDescription]]
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil] show];
return;
}
[self startTimer];
_player.removeUponFinish = YES;
_player.completionBlock = ^{
_audioController = nil;
[ _audioController removeChannels:@[_player]];
[self remveTimer];
self.player = nil;
};
[_audioController addChannels:@[_player]];
}
}
- (id)initWithAudioController:(AEAudioController*)audioController {
self.audioController = audioController;
NSError *error = NULL;
BOOL result = [self.audioController start:&error];
if ( !result ) {
// Report error
NSLog(@"The Amazing Audio Engine didn't start!");
} else {
NSLog(@"The Amazing Audio Engine started perfectly!");
}
return self;
}
Upvotes: 0