AVPlayer没有使用动态URL播放流媒体广播

时间:2014-05-28 10:17:31

标签: ios objective-c avplayer

iOS上的AVPlayer在执行此操作时非常适合播放

AVPlayer *player;
player =[[AVPlayer alloc] initWithURL:[NSURL URLWithString:@"http://kantipur-stream.softnep.com:7248"]];

[player play]

但是当我使用名为link的NSString变量来保存不同无线电的url字符串时,它不会播放任何无线电,如

AVPlayer *player;
player =[[AVPlayer alloc] initWithURL:[NSURL URLWithString:link]];

[player play]

从XML文档中提取和解析链接。 我无法理解这个问题是什么。

1 个答案:

答案 0 :(得分:1)

试试这个代码....它对我有用......

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];

并且不要忘记添加媒体播放器框架

或 网址编码

-(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];