0

我想播放从 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];

    }
4

4 回答 4

1

http://celeritas.com.pk/emrapp/test.mp4这个网址好像是错的……

在此服务器上未找到请求的 URL /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];
于 2012-08-16T08:11:01.153 回答
1

网址可能是错误的,请仔细检查视频网址链接是否可访问,其次请查看您的网络防火墙,这也可能会导致问题。

您可以更改的一项调整是:

mp.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;

采用:

mp.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;
于 2013-03-07T12:57:15.537 回答
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];
于 2012-08-16T07:42:35.573 回答
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];  
}  
于 2012-08-16T07:51:15.817 回答