11
votes

MpmoviePlayPontroller - détecter les boutons Suivant / prev

J'utilise mpmovieplayercontroller code> et je dois détecter appuyer sur les boutons Suivant / prev. J'ai essayé plusieurs choses, dont aucune ne semble fonctionner.

Voici ce que j'ai essayé: p>

  • Événements de télécommande LI> UL>
    -(void) viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
        [self becomeFirstResponder];
    }  
    -(void) viewWillDisappear:(BOOL)animated
    {
        [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
        [self resignFirstResponder];
        [super viewWillDisappear:animated];
    }  
    -(BOOL)canBecomeFirstResponder
    {
        return YES;
    }  
    -(void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent
    {
        // stuff
    }
    


6 commentaires

Stackoverflow.com/Questtions/3593683/...


Comme vous pouvez le voir dans mon post, c'est la première chose que j'ai essayée et ça ne marche pas


Serait-ce que lorsque MPMoviePlayController affiche, ViewWilldisappart est appelé et la télécommande de réception est donc terminée? S'il vous plaît essayez de commenter la viewwilldisappear et essayez à nouveau.


@John Merci pour la suggestion, je pensais la même chose, pas de bonne chance! :(


Avez-vous eu un coup d'œil à la mpmovieplayernowplayingMoviedidChangenotification? Il vous indique que la lecture de film actuelle change et si vous avez un dictionnaire ou une matrice avec les films, vous pouvez déterminer si le film qui est joué est le prochain ou le précédent. développeur.apple.com / Bibliothèque / iOS / Documentation / MediaPlayer / ...


@Emil Yep, essayé cela, la notification ne tire pas après avoir appuyé précédemment ou ensuite.


5 Réponses :


0
votes

Désolé, je ne comprends pas très bien votre problème, mais si vous souhaitez utiliser la commande de votre application dans le centre de contrôle, vous pouvez utiliser:

      // You need cath the singleton
MPRemoteCommandCenter *myRemote = [MPRemoteCommandCenter sharedCommandCenter];
//And add the selector you can fire depends on the button, a couple of examples:
[myRemote.playCommand addTarget:self action:@selector(myPlayMethods)];
[myRemote.nextTrackCommand addTarget:self action:@selector(myNextTrackMethods)];


0 commentaires

0
votes

Essayez d'vous inscrire à l'événement dans:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    // Turn on remote control event delivery
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

    // Set itself as the first responder
    [self becomeFirstResponder];
}


1 commentaires

Il existe également une solution qui dit à la sous-classe UIAPPLication et à l'impuissance - (vide) RemoteControlReceivedwithevent: (uievent *) RedeventEvent Vous avez essayé cela?



0
votes

Avez-vous essayé mpmovieplayernowplayingMoviedidChangenotification? Si cela ne fonctionne pas, je suggérerais de passer à une API de niveau inférieur I.e. Avplayer. Il fournit un contrôle grain fin sur toutes les actions lors de la lecture vidéo et autrement.


0 commentaires

0
votes

Vous devez vous inscrire pour gérer une notification pour MoviePlayerloadStatChaged. Lorsque vous appuyez sur les boutons NEXT / PREV, le MoviePlayerloadStatCHanged sera appelé et le LoardState sera MPMovieloadStaTaTatenknown

-(void)registerMyStuff {
    [[NSNotificationCenter defaultCenter] addObserver:self
                            selector:@selector(moviePlayerLoadStateChanged:)
                                    name:MPMoviePlayerLoadStateDidChangeNotification
                                           object:self.mpc];
}

- (void)moviePlayerLoadStateChanged:(NSNotification *)notification
{
    MPMoviePlayerController *moviePlayer = notification.object;
    MPMovieLoadState loadState = moviePlayer.loadState;

    if(loadState == MPMovieLoadStateUnknown)
    {
        // this is where the next/prev buttons notify
        // there is no video in this state so load one
        // just reload the default movie

        NSLog(@"MPMovieLoadStateUnknown");
        self.mpc.contentURL = self.fileURL;
        [self.mpc prepareToPlay];

        return;
    }
    else if(loadState & MPMovieLoadStatePlayable)
    {
        NSLog(@"MPMovieLoadStatePlayable");
    }
    else if(loadState & MPMovieLoadStatePlaythroughOK)
    {
        NSLog(@"MPMovieLoadStatePlaythroughOK");
    } else if(loadState & MPMovieLoadStateStalled)
    {
        NSLog(@"MPMovieLoadStateStalled");
    }
}


0 commentaires

0
votes

Vous modifiez mpmovieplayercontroller code> superposéview vue comme Changement uiImagePickerController code> superview pour implémenter la fonction dont vous avez besoin.

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]
    initWithContentURL:someUrl];

moviePlayer.movieControlMode = MPMovieControlModeHidden;
[moviePlayer play];

NSArray *windows = [[UIApplication sharedApplication] windows];

if ([windows count] > 1) {

     UIWindow *moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
     [moviePlayerWindow addSubview:yourCustomOverlayView];
}


0 commentaires