Не могу воспроизвести звук по онлайн-ссылке, используя Amazing Audio Engine
Я пытаюсь этот код для достижения потоковой передачи / буферизации онлайн с помощью удивительного звукового движка, но он выдает мне следующую ошибку:
AEAudioFilePlayer.m: 148: AudioFileOpenURL: 'wht?' (2003334207)
Вот код:
- (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;
}
1 ответ
В.h файле
@property (nonatomic, strong) AEAudioFilePlayer *player;
@property (nonatomic, strong) AEAudioController *audioController;
в.m файле
-(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;
}