0

IB で作成された UIView で MPMoviePlayerController のインスタンスを再生しようとすると、過去数日間、エクササイズ アプリでクラッシュが発生しました。アプリの残りの部分は正常に実行されますが、MPMoviePlayer がインスタンス化されている場合、デバッガーは例外を発生させずにアプリを一時停止します。原因はこのコードだけではありません。他の投稿や書籍から moviePlayer をインスタンス化する他の方法でも同じ結果になります。

このコードを実行すると、メインにドロップアウトします。

NSURL *url = exercise.exerciseVideoURL;//path for vid

    self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];



    [self.moviePlayerController.view setFrame:self.movieHostingView.bounds];

    [self.moviePlayerController prepareToPlay];
    [self.moviePlayerController setControlStyle:MPMovieControlStyleNone];
    [self.movieHostingView addSubview:self.moviePlayerController.view];


    [[self.moviePlayerController view]
     setAutoresizingMask:(UIViewAutoresizingFlexibleWidth |
                          UIViewAutoresizingFlexibleHeight)];

    [[self.moviePlayerController view] setClipsToBounds:YES];
    [[self.moviePlayerController view] setFrame:[[self movieHostingView] bounds]];
    [self.movieHostingView addSubview:self.moviePlayerController.view];
    self.moviePlayerController.repeatMode = MPMovieRepeatModeOne;

他の投稿からMPMoviePlayerインスタンス化コードを使用して、モデルをビニングし、他の投稿のように直接パスでインスタンス化しようとしましたが、それでもmain()にドロップアウトします。

4

2 に答える 2

0

ビデオをディスク (メイン バンドル) から読み込んでいますか、それともインターネット経由で読み込んでいますか? まず、ファイルパスが正しいことを常に確認してください。

NSString *filepath = [url absoluteString];

if ([[NSFileManager defaultManager] fileExistsAtPath:filepath])
{
    NSLog(@"file exists so init player");
}
else
{
    NSLog(@"try again!");
}

私の場合、ロード後に常に MPMoviePlayerController を追加します。したがって、次のようなことができます。

NSString *filepath   =   [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"mp4"];

if ([[NSFileManager defaultManager] fileExistsAtPath:filepath])
{

    NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];
    _moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];

    [_moviePlayerController prepareToPlay];

    NSLog(@"frame = %@", NSStringFromCGRect(_moviePlayerController.backgroundView.frame));

    [_moviePlayerController.view setBackgroundColor:[UIColor yellowColor]];
    [_moviePlayerController.view setFrame:CGRectMake(0, 280, 320, 200)];


    // 

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(movieLoadStateDidChangeNotification:)
                                                 name:MPMoviePlayerLoadStateDidChangeNotification
                                               object:_moviePlayerController];   
}

そしてしばらくしてから:

- (void)movieLoadStateDidChangeNotification:(NSNotification *)notification
{
    [self.view addSubview:_moviePlayerController.view];
}
于 2013-05-20T19:29:29.727 に答える