Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An AVPlayerItem cannot be associated with more than one instance of AVPlayer'

-(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];





    }

}

Hi I am trying to stream a video on my iphone app. The code plays a local file but crashes with an error " Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An AVPlayerItem cannot be associated with more than one instance of AVPlayer'" when used to stream a video from a server. Also the link streams the video absolutely fine in a browser but however i am not able to play the video in the app. Please Help . Thanks

like image 975
Andy Khatter Avatar asked Aug 20 '12 16:08

Andy Khatter


4 Answers

Had same issue, try setting ContentURL after Setting the SourceType like below,

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

Source: devforums.apple.com/message/467199

like image 127
suresh Avatar answered Nov 17 '22 23:11

suresh


It might be a problem with MovieSourceType; you are playing a local file but using MPMovieSourceTypeStreaming; just modify the type and try again

like image 35
bluesky719 Avatar answered Nov 17 '22 23:11

bluesky719


i have used moviePlayerController.movieSourceType = MPMovieSourceTypeUnknown its works for me.. try it..

like image 1
Akshay Savaliya Avatar answered Nov 18 '22 00:11

Akshay Savaliya


First you have to inform to player the source type ofter you set that content of video file; like this

Here is two types of urls; if the url is like this you write this function

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

aStr = [aStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

or (second one)

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];
like image 1
ShigaSuresh Avatar answered Nov 18 '22 01:11

ShigaSuresh