12

MonoTouch では、Movie Player サンプルでこの問題に遭遇しました。この問題は、ビデオを 1 回だけ再生し、2 回目は再生しないというものでした。

さまざまな人々に影響を与えているため、この質問に回答を投稿するよう求めています。

4

3 に答える 3

17

MPMoviePlayerController は、フードの下にあるシングルトンです。適切に release (ObjC) または Dispose() (MonoTouch) していない場合、2 番目のインスタンスを作成すると、再生されないか、オーディオのみが再生されます。

さらに、MPMoviePlayerScalingModeDidChangeNotification または MPMoviePlayerPlaybackDidFinishNotification または MPMoviePlayerContentPreloadDidFinishNotification をサブスクライブする場合は、投稿された NSNotification が MPMoviePlayerController への参照も取得することに注意してください。

Mono のガベージ コレクターは最終的に機能しますが、これは確定的な終了が必要な場合です ( GC がコレクションの実行を決定したときに参照を削除するのではなく参照を削除したい場合)。

これが、コントローラーで Dispose () メソッドを呼び出し、通知で Dispose() メソッドを呼び出す理由です。

例えば:

// Deterministic termination, do not wait for the GC
if (moviePlayer != null){
    moviePlayer.Dispose ()
    moviePlayer = null;
}

通知を聞いていた場合は、最後に通知ハンドラーで Dispose を呼び出して、保持している MPMoviePlayerController への参照を解放します。次に例を示します。

var center = NSNotificationCenter.DefaultCenter;
center.AddObserver (
    "MPMoviePlayerPlaybackDidFinishNotification"),
    (notify) => { Console.WriteLine ("Done!"); notify.Dispose (); });
于 2009-10-10T17:13:07.357 に答える
1

あなたのコードNirを見ることができず、私には編集権限がないので、ここにもう一度あります:

秘密は endPlay にあり、moviePlayer.initialPlaybackTime = -1; を設定します。解放する前に。やってみて : :)

-(void)playMovie:(NSString *)urlString{ movieURL = [NSURL URLWithString:urlString];          
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];    
moviePlayer.initialPlaybackTime = 0; 
//Register to receive a notification when the movie has finished playing. 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endPlay:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];

moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 
moviePlayer.movieControlMode = MPMovieControlModeDefault;
moviePlayer.backgroundColor = [UIColor blackColor];

[moviePlayer play];

}

-(void)endPlay: (NSNotification*)notification{
 [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; 
moviePlayer.initialPlaybackTime = -1; 
[moviePlayer stop]; 
[moviePlayer release]; 
} 
于 2010-02-09T19:35:56.357 に答える
0

秘密は endPlay にあり、moviePlayer.initialPlaybackTime = -1; を設定します。解放する前に。やってみて : :)

-(void)playMovie:(NSString *)urlString{
    movieURL = [NSURL URLWithString:urlString]; 
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    moviePlayer.initialPlaybackTime = 0;
    //Register to receive a notification when the movie has finished playing. 
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(endPlay:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:moviePlayer];

    moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 
    moviePlayer.movieControlMode = MPMovieControlModeDefault;
    moviePlayer.backgroundColor = [UIColor blackColor];

    [moviePlayer play];

}

-(void)endPlay: (NSNotification*)notification{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
    moviePlayer.initialPlaybackTime = -1;
    [moviePlayer stop];
    [moviePlayer release];
}
于 2010-02-04T12:35:45.500 に答える