2009-10-10 12 views

答えて

17

MPMoviePlayerControllerは、フードの下にあるシングルトンです。 d(ObjC)またはDispose()d(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; 
} 

、それは例えば、あなたのMPMoviePlayerControllerを保持していることの参照を解放するために、最後にあなたの通知ハンドラに廃棄を呼び出す:

var center = NSNotificationCenter.DefaultCenter; 
center.AddObserver (
    "MPMoviePlayerPlaybackDidFinishNotification"), 
    (notify) => { Console.WriteLine ("Done!"); notify.Dispose(); }); 
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]; 
} 
1

はあなたのコードニールを見ることができないと私はそれが再びあるので、ここで編集する権限がありません:秘密は設定とエンドプレイに産む

: 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]; 
} 
関連する問題