2012-09-23 75 views
0

我有一個小問題 - 當我嘗試從我的本地主機播放音頻時,它崩潰。
這是代碼,它不斷崩潰。AVAudioPlayer不能播放從url

stuff是網址

stuff = [json objectAtIndex:indexPath.row]; 

songlink = [NSURL URLWithString:[stuff objectForKey:@"Link"]]; 
    NSData *songdata = [NSData dataWithContentsOfURL:[NSURL URLWithString:[stuff objectForKey:@"Link"]]]; 
    jam = [[AVAudioPlayer alloc] initWithData:songdata error:nil]; 
    jam.delegate = self; 
    [jam play]; 
+0

1.這是**與Xcode無關**。 2. http://emclstcd.tk – 2012-09-23 08:46:49

回答

0

您必須使用 「valueForKey」,而不是objectForKey的字典/可變數組。

其他事情要考慮。

確保您的網址具有以http開頭的全限定網址,而且您不能將本地主機用作主機名。

你總是應該使用像URL:

http://10.10.10.10/mysong.mp3 

如果您的網址中包含像「我的Song.mp3的」,這也是容易解決的命名空間:

NSString *stringUrl = [stuff valueForKey:@"Link"]; 
NSString *newUrl = [stringUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
...[NSURL URLWithString:newUrl]