2010-07-01 6 views
0

J'essaie de charger un court fichier vidéo (.m4v) avant le démarrage de l'application Cependant, lorsque j'utilise le simulateur d'ipad, seul le son est lu. Il n'y a pas de vidéo en cours d'exécution. Si je change le simulateur en simulateur d'iphone, la vidéo joue très bien.La vidéo ne joue pas dans le simulateur d'iPad

J'utilise MPMoviePlayerController pour lire le fichier de film

J'ai même téléchargé l'échantillon MediaPlayer d'Apple, et le résultat est le même. Avec l'exemple de fichier vidéo (.m4v), le simulateur d'iphone peut lire le film, mais le simulateur d'ipad ne peut pas

S'il vous plaît, aidez!

Répondre

0

Il est presque certain qu'il s'agit d'un bug ou d'une limitation dans le simulateur.

+0

Alors que vous vouliez dire la film devrait jouer dans un appareil iPad? – Leo

+0

Oui, exactement. L'avez-vous essayé sur un appareil? – Dad

+0

Finalement, j'ai compris, ma mise en œuvre n'est pas bonne. – Leo

3

Voici ma solution si vous en avez besoin: La solution est intégrée à cocos2d, mais il devrait être relativement facile de la modifier malgré tout.

S'il vous plaît consulter le site Web suivant pour l'usage général:

Getting MPMoviePlayerController to Work with iOS4, 3.2 (iPad) and Earlier Versions of iPhone SDK

iPad iOS: 3.2.2

@implementation MovieLayer 

/* 
* name: movie file name 
* type: movie file type 
* target: target class to handle the selectors 
* finish: selector called when the movie is finished 
* load: selector called when the movie loading state is changed 
*/ 
+ (id)layerWithMovieName:(NSString*)name type:(NSString*)movieType target:(id)target 
    finish:(SEL)finishSelector load:(SEL)loadSelector 
{ 
return [[[self alloc] initWithMovieName:name type:movieType target:target 
      finish:finishSelector load:loadSelector] autorelease]; 
} 

- (id)initWithMovieName:(NSString*)name type:(NSString*)movieType target:(id)target 
    finish:(SEL)finishSelector load:(SEL)loadSelector 
{ 
if ((self = [super init]) != nil) 
{ 
    NSBundle *bundle = [NSBundle mainBundle]; 
    NSString *moviePath = [bundle pathForResource:name ofType:movieType]; 
    if (moviePath) 
    { 
    NSURL *moviePathURL = [NSURL fileURLWithPath:moviePath]; 
    [self loadMovieAtURL:moviePathURL]; 

    // Movie finish loading notification 
    [[NSNotificationCenter defaultCenter] 
    addObserver:target 
    selector:loadSelector 
    name:MPMoviePlayerLoadStateDidChangeNotification 
    object:nil]; 

    // Movie finish Notification 
    [[NSNotificationCenter defaultCenter] 
    addObserver:target 
    selector:finishSelector 
    name:MPMoviePlayerPlaybackDidFinishNotification 
    object:nil]; 
    } 
} 
return self; 
} 

- (void)dealloc 
{ 

[theMovie.view removeFromSuperview]; 
theMovie.initialPlaybackTime = -1; 
[theMovie stop]; 
[theMovie release]; 

[super dealloc]; 
} 

- (void)loadMovieAtURL:(NSURL*)theURL 
{ 
CGSize size = [[CCDirector sharedDirector] winSize]; 

theMovie = [[MPMoviePlayerController alloc] initWithContentURL:theURL]; 

[theMovie prepareToPlay]; 

// > 3.2 
[theMovie respondsToSelector:@selector(loadState)]; 

theMovie.scalingMode = MPMovieScalingModeAspectFill; 
[theMovie setFullscreen:TRUE animated:TRUE]; 
theMovie.controlStyle = MPMovieControlStyleNone; 

theMovie.view.frame = CGRectMake(0, 0, size.width, size.height); 
theMovie.view.backgroundColor = [UIColor clearColor]; 

// Transform 
theMovie.view.transform = CGAffineTransformMakeRotation(-270.0f * (M_PI/180.0f)); 
theMovie.view.center = [[CCDirector sharedDirector] openGLView].center; 

[[[CCDirector sharedDirector] openGLView] addSubview:theMovie.view]; 
} 

- (void)play 
{ 
[theMovie play]; 
} 

@end 

Utilisation de base en utilisant cocos2d

MovieLayer *player = [MovieLayer layerWithMovieName:LOGO_ANIMATION 
       type:LOGO_ANIMATION_FILE_EXT 
       target:self 
       finish:@selector(myMovieFinishedCallback:) 
       load:@selector(myMovieLoadCallback:)]; 
    [self addChild:player z: 0 tag:1]; 
} 
return self; 
} 

- (void)myMovieLoadCallback:(NSNotification*)notification 
{ 
MPMovieLoadState state = [(MPMoviePlayerController*)notification.object loadState]; 

// Remove observer 
[[NSNotificationCenter defaultCenter] 
    removeObserver:self 
    name:MPMoviePlayerLoadStateDidChangeNotification 
    object:nil]; 

if (state & MPMovieLoadStateUnknown) 
{ 
    [self myMovieFinishedCallback:nil]; 
} 
else if (state & MPMovieLoadStatePlayable) 
{ 
    [(MovieLayer*)[self getChildByTag:1] play]; 
} 
else if (state & MPMovieLoadStatePlaythroughOK) 
{ 
    [(MovieLayer*)[self getChildByTag:1] play]; 
} 
else if (state & MPMovieLoadStateStalled) 
{ 
    [self myMovieFinishedCallback:nil]; 
} 
} 

- (void)myMovieFinishedCallback:(NSNotification*)notification 
{ 
[[NSNotificationCenter defaultCenter] 
    removeObserver:self 
    name:MPMoviePlayerPlaybackDidFinishNotification 
    object:nil]; 

[self removeChildByTag:1 cleanup:YES]; 

} 
Questions connexes