使用 URL - iOS 在 MPMoviePlayerController 中播放视频

To play video in MPMoviePlayerController using URL - iOS

我正在尝试使用 URL 在 iOS - MPMoviePlayerController 中播放视频。但它不允许我加载视频。我在 viewDidLoad 方法中使用以下代码:

NSURL *fileURL = [NSURL URLWithString:@"http://videos.testtube.com/revision3/web/discoverydinosaurs/0035/discoverydinosaurs--0035--male-dinosaurs-battle--large.h264.mp4"];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:self.view.bounds];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.movieSourceType = MPMovieSourceTypeStreaming;
moviePlayerController.fullscreen = YES;
moviePlayerController.shouldAutoplay = YES;
[moviePlayerController prepareToPlay];
[moviePlayerController play];

它给我以下错误日志:

<Info>: logging starts...
<Debug>: setMessageLoggingBlock: called
ERROR:     98: Error '!obj' trying to fetch default input device's sample rate
ERROR:     100: Error getting audio input device sample rate: '!obj'
WARNING:   230: The input device is 0x0; '(null)'
WARNING:   234: The output device is 0x26; 'AppleHDAEngineOutput:1B,0,1,2:0'
ERROR:     400: error '!obj'
ERROR:     400: error -66680
ERROR:     113: * * * NULL AQIONode object
ERROR:     400: error -66680
ERROR:     400: error -66680
ERROR:     703: Can't make UISound Renderer
ERROR:     400: error -66680
ERROR:     400: error -66680
ERROR:     400: error -66680
ERROR:     400: error -66680
ERROR:     400: error -66680

请帮我解决这个错误。

在MPMoviePlayerController中使用URL真的可以播放视频吗???

请帮忙。

感谢和问候。

它适用于您的 URL。我试过了...

-(void)Play
{
    NSURL *videoPath = [NSURL URLWithString:@"http://videos.testtube.com/revision3/web/discoverydinosaurs/0035/discoverydinosaurs--0035--male-dinosaurs-battle--large.h264.mp4"];

    MPMoviePlayerViewController *mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoPath];
    // Remove the movie player view controller from the "playback did finish" notification observers
    [[NSNotificationCenter defaultCenter] removeObserver:mpViewController
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:mpViewController.moviePlayer];

    // Register this class as an observer instead
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(movieFinishedCallback:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:mpViewController.moviePlayer];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(doneButtonClick:)
                                                 name:MPMoviePlayerWillExitFullscreenNotification
                                               object:nil];

    // Set the modal transition style of your choice
    mpViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

    // Present the movie player view controller
    [self presentViewController:mpViewController animated:YES completion:nil];


    // Start playback
    [mpViewController.moviePlayer prepareToPlay];
    [mpViewController.moviePlayer play];

}


- (void)movieFinishedCallback:(NSNotification*)aNotification
{
    // Obtain the reason why the movie playback finished
    NSNumber *finishReason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];

    // Dismiss the view controller ONLY when the reason is not "playback ended"
    if ([finishReason intValue] != MPMovieFinishReasonPlaybackEnded)
    {
        MPMoviePlayerController *moviePlayer = [aNotification object];

        // Remove this class from the observers
        [[NSNotificationCenter defaultCenter] removeObserver:self
                                                        name:MPMoviePlayerPlaybackDidFinishNotification
                                                      object:moviePlayer];

        // Dismiss the view controller
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}