AVPlayer not playing streaming radio with dynamic URL

烈酒焚心 提交于 2019-12-11 14:36:29

问题


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]

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]

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


回答1:


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

or url encoding

-(NSString *)urlencode:(NSString *)str
{
    NSString *encodeString=(NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)str, NULL, (CFStringRef)@"", kCFStringEncodingUTF8));
    return encodeString;
}

and your code

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

[player play];


来源:https://stackoverflow.com/questions/23908870/avplayer-not-playing-streaming-radio-with-dynamic-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!