0

私は新しい開発者なので、まだ学んでいて、間違ったことをしていることを知っています。ユーザーがセグメントの1つを押すと、ビデオが再生されるセグメント化されたコントロールオブジェクトがあります。セグメントを押す場所にセットアップしてから、再生ボタンを押してビデオを再生する必要があります。再生ボタンを切り取って自動再生させたい。これは私が問題を抱えているところです。shouldAutoplay オプションを見つけましたが、それを使用してボタンを切り取ると、ビデオにまったく移動しません。shouldAutoplay オプションを正しく使用していないと確信しています。何らかの助け、または少なくとも正しい方向へのポイントを望んでいました。

- (IBAction)playMovie:(id)sender;

{
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"mytestimony" ofType:@"m4v"];
    NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    theMovie.shouldAutoplay = YES;
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    [theMovie autorelease];
    MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
    [self presentMoviePlayerViewControllerAnimated:moviePlayer];
}
4

2 に答える 2

2

ビデオを再生しないでください。ビデオプレーヤーで自動的に再生したくないので、再生する準備をしてshouldAutoPlayasを付けてください。NO

-(void) SetVideoFile:(NSString *)fileName {

    videoFileName=fileName;
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:fileName]];

    moviePlayer.initialPlaybackTime = 0;
    moviePlayer.view.frame = self.view.frame ;
    [orientationHandler VideoStart];
    [self.view addSubview:moviePlayer.view] ;
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayer];
    moviePlayer.shouldAutoplay = NO;
    [moviePlayer prepareToPlay];
}

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

    // your custom code which you want to play after the player did finish playing
}
于 2013-04-27T06:21:30.087 に答える
2

試しました[theMovie play];か?

更新:shouldAutoplayに設定されていることに気付きましtheMovieたが、提示したのは の別のインスタンスMPMoviePlayerViewController、つまり ですmoviePlayer。そのため、ムービーが自動再生されませんでした。代わりに次のものが必要です。

[self presentMoviePlayerViewControllerAnimated:theMovie];
于 2012-09-02T09:05:06.243 に答える