Search code examples
iphonexcodeipadmedia-player

Playing video in iPad application from server


I want to play a video which is uploaded to the server from an iPad application, but when the screen loads it gives an error:

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

I am using the following code:

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

    }

Solution

  • http://celeritas.com.pk/emrapp/test.mp4 the URL seems to be wrong...

    The requested URL /emrapp/test.mp4 was not found on this server.

    Any way this will work

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