1

这是我的代码。我想播放一个存在于设备内存中的视频。视频格式为 .mov。但我只得到了黑屏。

NSString *documentdir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        NSString *tileDirectory = [documentdir stringByAppendingPathComponent:urlpath];
        self.videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:tileDirectory]];
        [self.videoPlayer.view setFrame:CGRectMake(0, 0, 320, 420)];

        [self.videoPlayer prepareToPlay];
        [self.view addSubview:self.videoPlayer.view];
        [self.videoPlayer play];
4

1 回答 1

0

我得到了我的输出。我参考这个链接:How to play video stream with MPMoviePlayerController in iOS来解决我的问题。

我在下面修改的代码..

self.videoPlayer = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:urlpath]];
    self.videoPlayer.movieSourceType = MPMovieSourceTypeStreaming;
    [self.videoPlayer.view setFrame:CGRectMake(0, 0, 320, 420)];
    [self.view addSubview: self.videoPlayer.view];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:nil];
    [self.videoPlayer.backgroundView setBackgroundColor:[UIColor blackColor]];
    [self.videoPlayer play];

这条线是关键..self.videoPlayer.movieSourceType = MPMovieSourceTypeStreaming;

于 2013-11-04T13:20:22.813 回答