Ne peut pas rechercher avec MPMoviePlayerController
-
27-10-2019 - |
Question
Je vais chercher timeline sur MPMediaPlayerController.
J'ai essayé avec la méthode non documentée setCurrentTime de MPMediaPlayerController comme suit.
[player setCurrentTime:1.f];
Ensuite, la pomme Crashs avec follows ...
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MPMoviePlayerController setCurrentTime:]: unrecognized selector sent to instance 0x5619fe0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00f59be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x010ae5c2 objc_exception_throw + 47
2 CoreFoundation 0x00f5b6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00ecb366 ___forwarding___ + 966
4 CoreFoundation 0x00ecaf22 _CF_forwarding_prep_0 + 50
5 MPlayerExample 0x0000227d -[MPlayerExampleViewController PauseVideo] + 69
6 Foundation 0x000367f6 __NSFireDelayedPerform + 441
7 CoreFoundation 0x00f3afe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
8 CoreFoundation 0x00f3c594 __CFRunLoopDoTimer + 1220
9 CoreFoundation 0x00e98cc9 __CFRunLoopRun + 1817
10 CoreFoundation 0x00e98240 CFRunLoopRunSpecific + 208
11 CoreFoundation 0x00e98161 CFRunLoopRunInMode + 97
12 GraphicsServices 0x0188e268 GSEventRunModal + 217
13 GraphicsServices 0x0188e32d GSEventRun + 115
14 UIKit 0x002c642e UIApplicationMain + 1160
15 MPlayerExample 0x00001fe4 main + 102
16 MPlayerExample 0x00001f75 start + 53
)
terminate called after throwing an instance of 'NSException'
La solution
Vous pouvez chercher MPMoviePlayerController
en utilisant la propriété currentPlaybackTime
, qui est documenté dans le Protocole MPMediaPlayback Référence .
Alors votre code ressemblerait à ceci:
[player setCurrentPlaybackTime:1.0];
Autres conseils
Il est une API non documentée ... il est pas garanti. En fait, vous ne devriez pas vous attendre à. Il est tout à fait possible d'Apple il retiré d'une mise à jour du système d'exploitation, et maintenant la méthode n'existe pas.
S'il importe, vous passez un flotteur, et je pense qu'il attend un double. Cela pourrait être la raison pour laquelle vous avez des problèmes. Mais si vous écrivez une application pour la distribution sur l'App Store il n'y a pas de point d'instruction plus - votre application se rejetée. Apple analyse statique du code automatiquement lors de la soumission, toute utilisation des API non publiques entraînera votre application se rebondi directement à vous.
ici est un code qui fonctionnera pour la recherche d'une vidéo à l'aide MPMoviePlayer curseur sur commande
//create slider
slider1 = [[UISlider alloc] initWithFrame:CGRectMake(85, 435, 150,30)];
[slider1 addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[slider1 setBackgroundColor:[UIColor clearColor]];
slider1.minimumValue = 0;
slider1.continuous = YES;
[self.view addSubview:slider1];
// Set slider max value as moviePlayerController Total Duration and Current (Set Value ) as slider Value
-(void)sliderAction:(id)sender
{
UISlider *slider = (UISlider*)sender;
float value = slider.value;
slider.maximumValue = self.moviePlayerController.duration;
self.moviePlayerController.currentPlaybackTime = value;
}