2

我正在尝试使用此代码在惊人的音频引擎的帮助下实现在线流/缓冲,但它引发了以下错误:

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;
    }
4

1 回答 1

0

在 .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;
}
于 2016-02-05T13:43:11.117 回答