无法使用惊人的音频引擎播放来自在线链接的音频

Posted

技术标签:

【中文标题】无法使用惊人的音频引擎播放来自在线链接的音频【英文标题】:Can't play audio from an online link, using Amazing Audio Engine 【发布时间】:2016-01-27 10:04:39 【问题描述】:

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

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;
    

【问题讨论】:

它在 ios 9 上吗?你有那个done 吗? yes 允许任意加载,并且在 iOS 9 上确实有效 【参考方案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;

【讨论】:

以上是关于无法使用惊人的音频引擎播放来自在线链接的音频的主要内容,如果未能解决你的问题,请参考以下文章

利用MediaPlayer实现在线音频的播放(支持进度条拖动快进快退)

利用MediaPlayer实现在线音频的播放(支持进度条拖动快进快退)

解决ubuntu下的firefox无法在线播放音频和视频的问题

ios 如何播放在线的音频文件

AVFoundation 添加音频输入使音频播放静音

音频文件无法从服务器播放