嗨,在我的应用程序中,我想播放实时流视频,我具有实时流视频URL。现在尝试正常使用URl
播放视频,但不起作用。其显示错误之类的。
An AVPlayerItem cannot be associated with more than one instance of AVPlayer
我的视频播放代码。
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString: @"url"];
MPMoviePlayerController *mov = [[MPMoviePlayerController alloc]initWithContentURL: url];
self.movieplayer = mov;
[self.movieplayer.view setFrame:CGRectMake(10,20, 100, 100)];
self.movieplayer.movieSourceType = MPMovieSourceTypeFile;
[self.view addSubview:self.movieplayer.view];
[self.movieplayer prepareToPlay];
[self.movieplayer pause];
self.movieplayer.shouldAutoplay = NO;
}
我已经使用上面的代码播放了实时流视频,但无法正常工作。我想在不使用
UIWebView
的情况下播放实时流视频,请告诉我是否可以使用UIWebView
进行实时流的播放,或者我需要隐藏成其他格式才能播放。请告诉我如何解决此问题,但我没有找到合适的解决方案。谢谢。
最佳答案
试试这个代码...
NSString * url = @“您的网址”;
movieURL = [NSURL URLWithString:[self urlencode:url]];
moviePlayerTemp=[[MPMoviePlayerController alloc]initWithContentURL:movieURL];
[moviePlayerTemp.view setFrame:CGRectMake(0, 0, 300, 400)];
[moviePlayerTemp prepareToPlay];
[moviePlayerTemp setShouldAutoplay:YES];
[self.view addSubview:moviePlayerTemp.view];
-(NSString *)urlencode:(NSString *)str
{
NSString *encodeString=(NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)str, NULL, (CFStringRef)@"", kCFStringEncodingUTF8));
return encodeString;
}