2011-08-31 9 views
8

私は、再生が終了したらコントロールを表示するMPMoviePlayerControllerサブクラスを持っています。私はMPMoviePlayerPlaybackDidFinishNotification通知に応答を添付し、次のようにコントロールのスタイルを設定しようとしている:これは動作しないプログラムでMPMoviePlayerControllerのコントロールを表示する

[self setControlStyle:MPMovieControlStyleEmbedded]; 

。本質的に、ビデオの終わりに、私はコントロールすることを望みます。 コントロールをプログラムで表示するにはどうすればよいですか?

注:コントローラはフルスクリーンモードではありません。

+0

MPMoviePlayerPlaybackDidFinishNotificationが通知を受けていますか?ブレークポイントまたはNSLogメッセージを設定して、確実に確認することができます。 –

+0

あなたはこのロバートの解決策を見つけましたか? – ToddH

+0

私は覚えておくのはずっと前だと思っていますが、最終的には別のプレイヤーを使用するように変更したと思いますか? –

答えて

0

親切にこのことについて私の完全なコードを見つけ、それは.hのクラスは、この

@property(strong,nonatomic) MPMoviePlayerViewController * moviePlayer; 

.Mクラスに追加し、このコードを追加します追加私

で働いて

-(void) playMovie:(NSString *)filePath 
{ 
    NSURL *theOutputURL = [NSURL fileURLWithPath:filePath]; 
    if(_moviePlayer) 
     [_moviePlayer.moviePlayer setContentURL:theOutputURL]; 
    else 
     _moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:theOutputURL]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(myMovieFinishedCallback:) 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:_moviePlayer.moviePlayer]; 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:_moviePlayer.moviePlayer]; 

    if (![_moviePlayer.moviePlayer isPreparedToPlay]) 
     [_moviePlayer.moviePlayer prepareToPlay]; 

    _moviePlayer.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 
    [_moviePlayer.moviePlayer setFullscreen:YES]; 
    _moviePlayer.moviePlayer.controlStyle=MPMovieControlStyleEmbedded; 
    [_moviePlayer.moviePlayer setContentURL:theOutputURL]; 
    _moviePlayer.view.frame = CGRectMake(0, 0, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height); 
    [_moviePlayer shouldAutorotateToInterfaceOrientation: AVCaptureVideoOrientationLandscapeRight]; 
    [self.view addSubview:_moviePlayer.view]; 
} 


- (void) moviePlayerPlaybackStateDidChange: (NSNotification *) notification { 
    if (_moviePlayer.moviePlayer.playbackState == MPMoviePlaybackStateStopped) { 
     [_moviePlayer.moviePlayer setContentURL:[_moviePlayer.moviePlayer contentURL]]; 
     [_moviePlayer.moviePlayer play]; 
    } 
} 

-(void)myMovieFinishedCallback:(NSNotification*)aNotification 
{ 
    // to add your code after playback is finished 

} 
「映画のURLを渡します」
関連する問題