2012-04-17 19 views
2

私はビデオを見ることができるiPhoneアプリを作っています... 私は自分のコントロールを作っていますので、次のバックボタンを実装したいので、テーマをUIに表示できます問題は、別のコンテンツでMoviePlayerを再起動することです... 任意のアイデア???同じMPMoviePlayerControllerで別のビデオを再生するには?

ビデオは別のものを再生を開始するために遊んで終了した場合は再生が、私は意味...仕上げをしたとき、私は同じ設定を使用することができ

... 私はcontentUrlを設定しようとしたが、それは例外をtrows:

2012-04-17 11:37:41.198 NexTest2[8218:11f03] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 11.5]' 

私がコントロールのように、これらの二つのビュー使用しています原因viewController.m

- (void)viewDidLoad{ 
[super viewDidLoad];  
fileURL = [NSURL URLWithString:urlString]; 
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 
moviePlayerController.controlStyle = MPMovieControlStyleNone; 
[moviePlayerController setShouldAutoplay:YES]; 
[self addObservers]; 

/* Inset the movie frame in the parent view frame. */ 
CGRect viewInsetRect = CGRectInset ([self.view bounds],0.0, 0.0); 
[[moviePlayerController view] setFrame: viewInsetRect ]; 
[self.view addSubview:moviePlayerController.view]; 
[self resizeControlViews]; 
} 

が、その後resizeControlViewsで、私は、これを持っている:

ここではすべて正常に動作していますが、これらのビューの1つにはシークを制御するスライダがあり、もう1つには再生、次と戻るボタンがあります。プレイヤーがプレイしているとき、私が使用

//Add the observers to the player 
-(void)addObservers{ 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackStarted:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setDurationLabel:) name:MPMovieDurationAvailableNotification object:nil]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyWindowChanged:) name:UIWindowDidBecomeKeyNotification object:nil]; 

} 

ので、処理するために: 私は再生を制御するためにこれらのオブザーバーを追加しました

...多分問題は、これらのビューのUIコンポーネントを聖霊降臨祭だと思いますこのセレクタでMPMoviePlayerPlaybackStateDidChangeNotification:

-(void)timerRunning{ 
self.currentTime.text = [self floatToStringTime:(moviePlayerController.currentPlaybackTime)]; 
self.timeBar.value = moviePlayerController.currentPlaybackTime/moviePlayerController.duration; 

if (moviePlayerController.playbackState == MPMoviePlaybackStatePlaying) { 
    [self performSelector:@selector(timerRunning) withObject:nil afterDelay:0.5]; 
}   
} 
01:
//called when the playback state changes of state 
- (void)playbackStarted:(NSNotification*)notification { 
MPMoviePlayerController *player = notification.object; 
if (player.playbackState == MPMoviePlaybackStatePlaying) { 
    [self timerRunning]; 
} 
} 

とプレイヤーが、私はこの方法でそれを監視する「演奏」されている場合

私はラインで監視していながら

ので、多分ここに問題がある...しかし、それは完璧に動作単一のビデオと...

私はミスが...ある4をしましたが設定することです私はそれが他のビデオやストップビデオがまだ実行されているので、プレイヤーがこの例外を発生させない持続時間または現在の再生時間を持たない場合に発生すると思うのですが...どうすれば解決できるのでしょうか?それ...ここ

self.timeBar.value = moviePlayerController.currentPlaybackTime/moviePlayerController.duration; 
+1

ありがとうございます。一般的にムービープレイヤーを再び使用するには、そのプレーヤーをリリースして新しいコンテンツを追加する必要があります。 – DivineDesert

+0

@DimplePanchalプレーヤーを再利用するためには、プレイヤーを解放する必要はありません。 contentUrlを設定するだけで十分です。 – Till

+0

@ Till Ya、私もそれを見つけましたが、映画プレーヤーのcontentUrlを設定するだけで、一般的にiphone sdkでuncatchableクラッシュが作成されます。私はそれの背後にある理由を知らないが、これは私が観察したものである。 – DivineDesert

答えて

1

はあなたのUI関連のコードをチェックしてください...多分別の部分にこのコードを移動...間違いです。あなたは、コンテンツ関連のプロパティを取得して使用する前に、プレーヤーのステータスを適切にチェックしていない可能性が非常に高いです。

+0

それは問題ですね...しかし、[player stop];それは同じ例外を示しています...どんな考えですか? –

1

最終的にはうまくいきます... setCurrentContentUrlはうまくいきました。問題は私のコードだったので解決しました...私はその持続時間が0と異なることを検証しました... 今、私は完全なカスタムコントロールは:)クール:)

-(void)timerRunning{ 
    if (moviePlayerController.playbackState == MPMoviePlaybackStatePlaying) {  
     self.currentTime.text = [self floatToStringTime:(moviePlayerController.currentPlaybackTime)]; 
     if (moviePlayerController.duration != 0) { 
      self.timeBar.value = moviePlayerController.currentPlaybackTime/moviePlayerController.duration; 
     } 

    [self performSelector:@selector(timerRunning) withObject:nil afterDelay:0.5]; 
    }   
} 

はあなたのコードを追加してくださいすることができとにかく

+0

保存してくれた日、ありがとう。 – limon

関連する問題