1

MPMoviePlayerViewController でビデオを再生しようとしています。MPMoviePlayerViewController を提示しますが、1 秒後に彼は自分自身を閉じています。

これは私のコードです:

.h:

#import <MediaPlayer/MediaPlayer.h>

@property (strong, nonatomic) MPMoviePlayerViewController *moviePlayerViewController;

.m:

- (void)playmovie
{
    NSString *databaseName = @"NO.mp4";
    NSArray *documentPaths =
    NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentDir = [documentPaths objectAtIndex:0];
    NSString *databasePath = [documentDir stringByAppendingPathComponent:databaseName];

    NSURL *movieURL = [NSURL fileURLWithPath:databasePath];

    UIGraphicsBeginImageContext(CGSizeMake(1,1));
    self.moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
    [self presentMoviePlayerViewControllerAnimated:self.moviePlayerViewController];
    UIGraphicsEndImageContext();

    [self.moviePlayerViewController.moviePlayer prepareToPlay];
    [self.moviePlayerViewController.moviePlayer play];
}

私が何を間違えたのか教えてください。

前もって感謝します!

4

2 に答える 2

3

以下の回答を確認してください

https://stackoverflow.com/a/15586468/1713478

URLを以下のコードに変更します

NSString *path =[[NSBundle mainBundle] pathForResource:@"NO" ofType:@"mp4"]; 
NSURL *url = [NSURL fileURLWithPath:path];

これを試してみてください。成功します。

于 2013-03-29T10:02:21.517 に答える
0

これを試して..

NSString *databaseName = @"NO.mp4";
    NSArray *documentPaths =
    NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentDir = [documentPaths objectAtIndex:0];
    NSString *databasePath = [documentDir stringByAppendingPathComponent:databaseName];
    NSURL *url = [NSURL fileURLWithPath:databasePath];
    MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    moviePlayer.view.frame = CGRectMake(0, 0, 500, 500);
    moviePlayer.moviePlayer.shouldAutoplay=YES;
    moviePlayer.moviePlayer.controlStyle = MPMediaTypeMusicVideo;
    [moviePlayer.moviePlayer setFullscreen:YES animated:YES];
    [self.view addSubview:moviePlayer.view];
    [moviePlayer.moviePlayer play];
于 2013-04-10T05:48:45.363 に答える