2009-10-10 15 views

Odpowiedz

17

MPMoviePlayerController to singleton pod maską. Jeśli nie zostałeś prawidłowo zwolniony (ObjC) lub Wyrzuć() "d (MonoTouch) i utworzysz drugie wystąpienie, nie będzie on odtwarzał ani odtwarzał tylko audio.

Dodatkowo jeśli subskrybować MPMoviePlayerScalingModeDidChangeNotification lub MPMoviePlayerPlaybackDidFinishNotification lub MPMoviePlayerContentPreloadDidFinishNotification być ostrzeżony, że pisał NSNotification przyjmuje odniesienie do MPMoviePlayerController, tak więc jeśli trzymać go wokół, trzeba będzie odniesienie odtwarzacza.

Chociaż Mono Garbage Collector ostatecznie kick-w, jest to przypadek, w którym wypowiedzenie deterministyczny jest poszukiwany (chcesz odniesienie poszedł teraz, nie zniknął, gdy GC postanawia przeprowadzić kolekcji).

Dlatego należy wywołać metodę Dispose() na kontrolerze i metodę Dispose() w powiadomieniu.

Na przykład:

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

Jeśli słuchałeś powiadomień, zadzwoń utylizować w swojej obsługi powiadomień na końcu, aby zwolnić odniesienie że prowadzi do MPMoviePlayerController na przykład:

var center = NSNotificationCenter.DefaultCenter; 
center.AddObserver (
    "MPMoviePlayerPlaybackDidFinishNotification"), 
    (notify) => { Console.WriteLine ("Done!"); notify.Dispose(); }); 
0

Sekret leży na końcuOdtwórz z ustawieniem: moviePlayer.initialPlaybackTime = -1; przed zwolnieniem. Wypróbuj: :)

-(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

nie widzę kodu Nir i nie mam edycji przywileje tak tutaj jest ponownie:

Sekret leży w Luz osiowy z ustawieniem: moviePlayer.initialPlaybackTime = -1; przed zwolnieniem go. Wypróbuj: :)

-(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]; 
} 
Powiązane problemy