如何从我的应用程序启动QuickTime?

时间:2010-06-10 21:40:00

标签: iphone objective-c cocoa-touch video mpmovieplayercontroller

我正在尝试从网络加载视频,但我无法将其显示在QuickTime中。我只能听到音频。我希望它能够启动QuickTime。

- (void)loadView {
    NSURL *movieURL = [NSURL URLWithString:@"http://movies.apple.com/media/us/mac/getamac/2009/apple-mvp-biohazard_suit-us-20090419_480x272.mov"];


    if (movieURL != nil) {
        moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

        moviePlayer.initialPlaybackTime = -1.0;

        // Register to receive a notification when the movie has finished playing. 
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(moviePlayBackDidFinish:) 
                                                     name:MPMoviePlayerScalingModeDidChangeNotification 
                                                   object:moviePlayer];

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

        moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 
        moviePlayer.movieControlMode = MPMovieControlModeDefault;
        moviePlayer.backgroundColor = [UIColor blackColor];

        [moviePlayer play];
    }
}

3 个答案:

答案 0 :(得分:1)

我使用了视图控制器:

moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:mySTVideo.video_url]];

[self presentModalViewController:moviePlayerViewController animated:YES];

[moviePlayerViewController release];

答案 1 :(得分:0)

你在设备上试过吗?我听说模拟器有时会遇到这个问题。

答案 2 :(得分:0)

让它出现在QuickTime中的另一个解决方案是:

NSString * urlStr = @"http://movies.apple.com/media/us/mac/getamac/2009/apple-mvp-biohazard_suit-us-20090419_480x272.mov";
NSString * htmlStr = [[@"<html><body><video preload=\"auto\" autoplay=\"true\"><source src=\"" stringByAppendingString:urlStr] stringByAppendingString:@"\"></video></body></html>"];
UIWebView * wv = [[UIWebView alloc] init];
wv.frame = self.view.frame;
[self.view addSubview:wv];
wv.hidden = true;
wv.mediaPlaybackRequiresUserAction = false;
[wv loadHTMLString:htmlStr baseURL:nil];

但是当关闭quicktime播放器时,您必须手动从superview中删除webview。