我想播放从iPad应用程序上传到服务器的视频,但是当屏幕加载时会出现错误:
AVPlayerItem不能与多个AVPlayer实例关联
我使用以下代码:
-(void)playVideo{
NSURL *url = [NSURL URLWithString:@"http://celeritas.com.pk/emrapp/test.mp4"];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mp];
mp.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:mp];
[mp release];
NSLog(@"Successfully playing thanks");
}
-(void)playbackFinishedCallback:(NSNotification *)notification{
MPMoviePlayerController *movie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:movie];
[movie release];
}
答案 0 :(得分:1)
http://celeritas.com.pk/emrapp/test.mp4网址似乎有误......
在此服务器上找不到请求的网址/emrapp/test.mp4。
任何方式都可行
·H
MPMoviePlayerViewController * plyr;
NSURL * url;
@property (nonatomic,retain) MPMoviePlayerViewController *plyr;
@property (nonatomic,retain) NSURL *url;
的.m
@synthesize plyr ;
@synthesize url;
url = [NSURL URLWithString:@"valid url"];
plyr = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
答案 1 :(得分:1)
Url可能是错误的双重检查视频网址链接是否可访问,其次看到您的网络防火墙这可能也会导致问题。
您可以更改一次调整,而不是:
mp.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
使用:
mp.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;
答案 2 :(得分:0)
试试这个
在.h中创建MPMoviePlayerViewController的对象,如 MPMoviePlayerViewController * mp;
#import<MediaPlayer/MediaPlayer.h>
mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]];
[[mp moviePlayer] prepareToPlay];
[[mp moviePlayer] setUseApplicationAudioSession:NO];
[[mp moviePlayer] setShouldAutoplay:YES];
[[mp moviePlayer] setControlStyle:2];
[[mp moviePlayer] setRepeatMode:MPMovieRepeatModeOne];
[self presentMoviePlayerViewControllerAnimated:mp];
答案 3 :(得分:0)
试试此代码
-(IBAction)playMovie:(id)sender
{
NSURL *fileURL = [NSURL URLWithString:@"http://www.youtube.com/watch?v=3Qjh56woQMw"];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotificationobject:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}