Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
552 views
in Technique[技术] by (71.8m points)

objective c - How to play a video with MPMoviePlayerController

I'm using this code to play a video streaming from the apple site

- (IBAction)playMovie:(UIButton *)sender {
    NSLog(@"start playing");
    //NSURL *url = [NSURL URLWithString:@"http://spatie.be/test.mov"];
    NSURL *url = [NSURL URLWithString:@"http://stream.qtv.apple.com/events/mar/123pibhargjknawdconwecown/12oihbqeorvfhbpiubqnfv3_650_ref.mov"];
    moviePlayer =  [[MPMoviePlayerController alloc]
                    initWithContentURL:url];


    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayer];

    moviePlayer.controlStyle = MPMovieControlStyleDefault;
    moviePlayer.shouldAutoplay = YES;
    moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    [self.view addSubview:moviePlayer.view];
    [moviePlayer setFullscreen:YES animated:YES];    
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {

    NSError *error = [[notification userInfo] objectForKey:@"error"];
    if (error) {
        NSLog(@"Did finish with error: %@", error);
    }    

    MPMoviePlayerController *player = [notification object];
    [[NSNotificationCenter defaultCenter] 
     removeObserver:self
     name:MPMoviePlayerPlaybackDidFinishNotification
     object:player];

    if ([player
         respondsToSelector:@selector(setFullscreen:animated:)])
    {
        [player.view removeFromSuperview];
    }

}

When playMovie is invoked, moviePlayBackDidFinish is immediatelty called and the error message is logged:

Did finish with error: Error Domain=MediaPlayerErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x78d25d0 {NSLocalizedDescription=The operation could not be completed}

How can I solve this error?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You didn't tag this as iOS, but MPMoviePlayer is iOS only. This should work just fine with a video that will play on iOS. Unfortunately the video you are trying to play is not iOS compatible. Try this URL:

http://stream.qtv.apple.com/events/mar/123pibhargjknawdconwecown/12oihbqeorvfhbpiubqnfv3_ipad_vod_ref.mov

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...