一个AVPlayerItem不能AVPlayer的”多个实例相关联(An AVPlayerItem

2019-07-31 02:29发布

-(IBAction)play:(id)sender
{

    thumbImageView.alpha=0.0;

    NSString *stringvideo=[NSString stringWithFormat:@"http://streaming-service",[[NSUserDefaults standardUserDefaults]valueForKey:@"VideoIdselected"]];

    NSString *videoURLString = stringvideo;

       NSURL *url = nil;

  url = [NSURL URLWithString:videoURLString];





    self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];




    if (self.moviePlayerController)
    {
        /* Save the movie object. */
          [self setMoviePlayerController:self.moviePlayerController];


        [self installMovieNotificationObservers];

        /* Specify the URL that points to the movie file. */
        [self.moviePlayerController setContentURL:url];


        [self.moviePlayerController setMovieSourceType:MPMovieSourceTypeStreaming]; // for streaming



        self.moviePlayerController.controlStyle = MPMovieControlStyleEmbedded;

        // [self.videoPlayer setMovieSourceType:MPMovieSourceTypeStreaming];

      // self.moviePlayerController.shouldAutoplay = YES;

        [self.moviePlayerController.view setFrame: CGRectMake(0, 0, 320,160)];



        [self.moviePlayerController setFullscreen:NO animated:YES];

        [self.moviePlayerController view].backgroundColor = [UIColor lightGrayColor];

        [self.view addSubview:self.moviePlayerController.view];

        [self.view bringSubviewToFront:self.moviePlayerController.view];
        [self.moviePlayerController prepareToPlay];
        //self.moviePlayerController.useApplicationAudioSession = NO;

        [self.moviePlayerController play];





    }

}

你好我想在我的iPhone应用程序流的视频。 该代码可播放本地文件但有错误崩溃“终止应用程序由于未捕获的异常‘NSInvalidArgumentException’,理由是:‘一个AVPlayerItem不能AVPlayer的多个实例相关联的’”用于从服务器流式播放视频的时候。 另外,链接流的视频在浏览器中的精绝,但不过我不能够在应用程序中播放视频。 请帮忙 。 谢谢

Answer 1:

有同样的问题,请尝试设置sourceType像下面后设置的contentURL,

moviePlayerController_ = [[MPMoviePlayerViewController alloc] init];
moviePlayerController_.movieSourceType = MPMovieSourceTypeStreaming;
[moviePlayerController_.moviePlayer setContentURL:url];

来源: devforums.apple.com/message/467199



Answer 2:

这可能是一个问题MovieSourceType ; 您正在播放本地文件,但使用MPMovieSourceTypeStreaming ; 刚刚修改的类型,然后再试一次



Answer 3:

我已经使用moviePlayerController.movi​​eSourceType = MPMovieSourceTypeUnknown其作品对我..试试吧..



Answer 4:

首先,你必须通知到玩家源类型ofter您设置视频文件的内容; 像这样

下面是两种类型的网址; 如果URL是这样你写此功能

 NSString *aStr=@"http://www.my url like this.com/video/videos/review/Michale JACKSON  AUDIENCE Comment.mp4";   

aStr = [aStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

或(第二个)

NSString *aStr=@"http://www.normal url.com/video.mp4"

// after add your url string to this url

NSURL *url=[NSURL URLWithString:aStr];
MPMoviePlayerViewController *MPlayer = [[MPMoviePlayerViewController alloc]init];
MPlayer.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[MPlayer.moviePlayer setContentURL:url];
[self presentMoviePlayerViewControllerAnimated:MPlayer];


Answer 5:

如果你不尝试更新的contentURL,呼吁停止后出现此错误()直接回答这个问题,但在此之前解决问题。

moviePlayerController.stop()
moviePlayerController.movieSourceType = .File
moviePlayerController.contentURL = newURL


文章来源: An AVPlayerItem cannot be associated with more than one instance of AVPlayer'