【问题标题】:Video won't play in iPad simulator视频无法在 iPad 模拟器中播放
【发布时间】:2010-07-01 07:01:05
【问题描述】:

我正在尝试在应用程序启动之前加载一个短片文件 (.m4v) 但是,当我使用 ipad 模拟器时,只播放声音。没有视频正在运行。 如果我把模拟器换成iphone模拟器,视频播放就好了。

我使用 MPMoviePlayerController 播放电影文件

我什至从 Apple 下载了示例 mediaPlayer,结果是一样的。使用示例电影文件 (.m4v),iphone 模拟器可以播放电影,但 ipad 模拟器不能

请帮忙!

【问题讨论】:

    标签: ipad cocos2d-iphone mpmovieplayercontroller


    【解决方案1】:

    如果您需要,这是我的解决方案: 该解决方案与cocos2d集成,但无论如何修改它应该相对容易。

    一般用法请参考以下网站:

    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
    

    使用 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];
    
    }
    

    【讨论】:

      【解决方案2】:

      几乎可以肯定这是模拟器中的已知错误/限制。

      【讨论】:

      • 所以你的意思是电影应该在 iPad 设备上播放?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-23
      • 1970-01-01
      • 2019-11-21
      • 2012-06-07
      • 1970-01-01
      • 2015-07-08
      • 2012-01-30
      相关资源
      最近更新 更多