2

ドキュメント フォルダ内のファイルを表示するアプリケーションを 1 つ作成します。ドキュメントフォルダーから表示したい.mov形式のファイルが1つありますが、アプリを実行して再生ボタンをクリックすると、このムービーが表示されず、次の画像が表示されます。ここに画像の説明を入力

これは私のコードです:(私を導き、私の間違いを教えてください)

- (IBAction)Play:(id)sender
{
    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES)objectAtIndex:0];
    NSString *file = [documentPath stringByAppendingPathComponent:@"xcode4-outlet.mov"];
    NSURL *url = [NSURL fileURLWithPath:file];
    _moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
    [self.view addSubview:_moviePlayer.view];
    _moviePlayer.fullscreen = YES;
    _moviePlayer.shouldAutoplay = YES;
    _moviePlayer.allowsAirPlay = YES;
    [_moviePlayer play];
}

また、コンパイラは私にこのメッセージを受け取ります:

movie player[9489:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
movie player[9489:c07] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
movie player[9489:c07] [MPAVController] Autoplay: Enabling autoplay
movie player[9489:c07] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
movie player[9489:c07] [MPAVController] Autoplay: Enabling autoplay
4

3 に答える 3

5

ムービープレーヤーを追加する前に、ファイルが存在するかどうかを確認する必要があります。デフォルトを追加することもできます

-(IBAction)Play:(id)sender
{

    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES)objectAtIndex:0];
    NSString *file = [documentPath stringByAppendingPathComponent:@"xcode4-outlet.mov"];
    NSURL *url = [NSURL fileURLWithPath:file];

    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:file];
    if(fileExists)
    {
        _moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePreloadDidFinish:) name:MPMoviePlayerLoadStateDidChangeNotification
                                                   object:_moviePlayer];
        _moviePlayer.shouldAutoplay=NO;
        [_moviePlayer prepareToPlay];
    }

}

ムービーが完全にロードされた後にムービーを追加します

-(void)moviePreloadDidFinish:(NSNotification*)notification
{

   _moviePlayer.controlStyle=MPMovieControlStyleDefault;
   [self.view addSubview:_moviePlayer.view];
   [_moviePlayer play];
   [_moviePlayer setFullscreen:YES animated:YES];

}
于 2013-05-15T05:21:48.843 に答える