AVPlayer无法播放带有动态URL的流式广播 [英] AVPlayer not playing streaming radio with dynamic URL

查看:172
本文介绍了AVPlayer无法播放带有动态URL的流式广播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行此操作时,iOS上的AVPlayer可以完美播放广播

AVPlayer on iOS is perfectly playing radio when doing this

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

[player play]

但是当我使用名为link的NSString变量来保存不同收音机之类的网址字符串时,它不会播放任何收音机

But it doesn't play any radio when I use NSString variable called link to hold url string of different radios like

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

[player play]

链接是从X​​ML文档中提取并解析的. 我不明白是什么问题.

link is fetched and parsed from an XML document. I can't understand whats the problem.

推荐答案

尝试此代码....它对我有好处...

try this code....its working good for me...

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

别忘了添加媒体播放器框架

and don't forget to add a media playerFramework

或 网址编码

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

这篇关于AVPlayer无法播放带有动态URL的流式广播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆