AVPlayer不使用dynamicURL播放stream媒体广播
在这种情况下,iOS上的AVPlayer完美播放广播
AVPlayer *player; player =[[AVPlayer alloc] initWithURL:[NSURL URLWithString:@"http://kantipur-stream.softnep.com:7248"]]; [player play]
但是当我使用NSStringvariableslink来保存不同收音机的urlstring时,它不会播放任何广播
AVPlayer *player; player =[[AVPlayer alloc] initWithURL:[NSURL URLWithString:link]]; [player play]
链接从XML文档中获取并parsing。 我不明白是什么问题。
试试这个代码….它对我有好处…
NSString *string=@"http://kantipur-stream.softnep.com:7248"; moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:string]]; [moviePlayer.moviePlayer prepareToPlay]; moviePlayer.view.hidden = YES; [moviePlayer.moviePlayer play]; [self.view addSubview:moviePlayer.view];
不要忘了添加一个媒体播放器框架
或url编码
-(NSString *)urlencode:(NSString *)str { NSString *encodeString=(NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)str, NULL, (CFStringRef)@"", kCFStringEncodingUTF8)); return encodeString; }
和你的代码
NSString *string=@"http://kantipur-stream.softnep.com:7248"; player =[[AVPlayer alloc] initWithURL:[NSURL URLWithString:[self urlencode:string]]]; [player play];