12
votes

Pourquoi n'est-il pas possible d'utiliser le MPMoviePlayController plus d'une fois?

à MonoTouch, nous avons rencontré ce problème avec l'échantillon du joueur de film en ce sens qu'il ne jouerait qu'une fois la vidéo, mais ne le jouerait pas une seconde fois.

Je pose cette question à poster une réponse, car elle frappe diverses personnes.


0 commentaires

3 Réponses :


17
votes

mpmovieplayPontroller est un singleton sous la hotte. Si vous n'avez pas correctement libéré (objc) ou jetez () 'd (monoTouch) et que vous créez une seconde instance, il ne joue pas ou joue uniquement audio.

Si vous vous abonnez à MPMOVIEPLAYERSCALINGMODIDNOTIFICATION OU MPMOVIEPLYERPLABACKDIDIATIFICATION OU Mpmovieplayercontentpreloaddididfinishnotification, soyez averti que la NSNotification affichée prend également une référence au MPMOVIEPlayerController également, donc si vous le gardez autour, vous aurez une référence au joueur. P>

Bien que le collectionneur des ordures de Mono finisse par lancer, cette est un cas où la résiliation déterministe est souhaitée (vous voulez que la référence a disparu maintenant em>, n'est pas partie lorsque le GC décide d'effectuer une collection). P>

C'est pourquoi vous voulez appeler le Disposer () méthode sur le contrôleur et le dispositif d'élimination () sur la notification. P>

Par exemple: P>

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


0 commentaires

0
votes

Le secret repose dans la fin de la fin avec le réglage de: MoviePlayer.InitialplayBackTime = -1; avant de le libérer. Essaye le : :)

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


0 commentaires

1
votes

Vous ne pouvez pas voir votre code NIR et je n'ai pas de privilèges d'édition, donc ici, il est à nouveau:

Le secret repose dans la fin de la fin avec le paramètre: MoviePlayer.InitialplayBackTime = -1; avant de le libérer. Essayez-le: :) ​​ P>

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


0 commentaires