2009-10-10 12 views

Respuesta

17

MPMoviePlayerController es un singleton debajo del capó. Si no has lanzado correctamente (ObjC) o Dispose() 'd (MonoTouch) y creas una segunda instancia, no se reproducirá o solo se reproducirá audio.

Además si se suscribe a MPMoviePlayerScalingModeDidChangeNotification o MPMoviePlayerPlaybackDidFinishNotification o MPMoviePlayerContentPreloadDidFinishNotification, se advirtió que la NSNotification publicado toma una referencia a la MPMoviePlayerController, así que si lo mantiene en todo, tendrá una referencia al jugador.

Aunque el recolector de basura de Mono eventualmente se activará, este es un caso en el que se desea la terminación determinística (la referencia ya no está ahora, no se ha ido cuando el GC decide realizar una recopilación).

Es por eso que desea llamar al método Dispose() en el controlador y al método Dispose() en la notificación.

Por ejemplo:

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

Si estaba escuchando a las notificaciones, llamar a Dispose en su controlador de notificación al final, para liberar la referencia que mantiene a su MPMoviePlayerController por ejemplo:

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

El secreto está en el final. Juega con la configuración de: moviePlayer.initialPlaybackTime = -1; antes de liberarlo. Pruébelo: :)

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

no puede ver su código de Nir y no tengo privilegios de edición así que aquí está de nuevo:

El secreto radica en el juego axial con el ajuste de: moviePlayer.initialPlaybackTime = -1; antes de soltarlo Pruébelo: :)

-(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]; 
} 
Cuestiones relacionadas