2012-12-02 148 views
2

我是Mac Dev的新手,我很苦惱音頻流媒體。我在Get an audio stream from URI and play it on iPhoneiPhone - 流媒體音頻

發現了一個很好的參考作者似乎很高興,我試圖重現該解決方案。流來自Dogglounge收音機。 URL是http://dl3.mixcache.com:8000(這是iTunes點擊Get Info時返回的內容)。

我所做的是創建一個iPhone應用程序,其中包含一個實際上沒有控件的單一視圖。我在viewDidLoad中添加了代碼以儘快啓動流。看來NSData * _objectData運行無止境。我使用iOS6模擬器。

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    NSString* resourcePath = @"http://dl3.mixcache.com:8000"; //your url 
    NSURL *url = [NSURL URLWithString:resourcePath]; 

    NSError *e = nil; 
    NSData *_objectData = [NSData dataWithContentsOfURL:url options:NSDataReadingMappedIfSafe error:&e]; 


    NSLog(@"%@", [e localizedDescription]); 

    NSError *error; 

    AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error]; 
    audioPlayer.numberOfLoops = 0; 
    audioPlayer.volume = 1.0f; 
    [audioPlayer prepareToPlay]; 

    if (audioPlayer == nil) 
     NSLog(@"%@", [error description]); 
    else 
     [audioPlayer play]; 


} 

回答