Cocos2d and MPMoviePlayerViewController - NSNotificationCenter not working

Posted by digi_0315 on Stack Overflow See other posts from Stack Overflow or by digi_0315
Published on 2011-01-14T12:50:17Z Indexed on 2011/01/14 12:53 UTC
Read the original article Hit count: 228

I'm using cocos2d with MPMoviePlayerViewController class, but when I tryed to catch notification status when the movie is finished I got this error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString movieFinishedCallback]: unrecognized selector sent to instance 0x5d23730'

my playVideoController.m are:

@implementation PlayVideoViewController

+(id) scene{

    CCScene *scene = [CCScene node];
    CCLayer *layer = [credits node];
    [scene addChild: layer];
    return scene;
}
-(id)initWithPath:(NSString *)moviePath{

    if ((self = [super init])){
        movieURL = [NSURL fileURLWithPath:moviePath];   
        [movieURL retain];



        playerViewController = [[MPMoviePlayerViewController alloc]
                                initWithContentURL:movieURL];

        player = [playerViewController moviePlayer];

        [[NSNotificationCenter defaultCenter] 
         addObserver:self
         selector:@selector(movieFinishedCallback)
         name:MPMoviePlayerPlaybackDidFinishNotification
         object:player];

        [[[CCDirector sharedDirector] openGLView] addSubview:playerViewController.view];
  [player play];

    }
    return self;
}

-(void)movieFinishedCallback{
    CCLOG(@"video finished!!");
}

in .h:

#import <UIKit/UIKit.h>
#import "cocos2d.h"
#import <MediaPlayer/MediaPlayer.h>

@interface PlayVideoViewController : CCLayer {
    NSURL    *movieURL;
    MPMoviePlayerViewController *playerViewController;
    MPMoviePlayerController *player;
}
+(id) scene;

@end

and I call it in appDelegate.m:

- (void) applicationDidFinishLaunching:(UIApplication*)application
{

    CC_DIRECTOR_INIT();
    CCDirector *director = [CCDirector sharedDirector];

    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];

    EAGLView *glView = [director openGLView];
    [glView setMultipleTouchEnabled:YES];

    [CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];//kEAGLColorFormatRGBA8

    NSString *path = [[NSBundle mainBundle] pathForResource:@"intro" ofType:@"mov" inDirectory:nil];
    vi

ewController = [[[PlayVideoViewController alloc] initWithPath:path] autorelease]; }

what i'm doing wrong? anyone can help me please?? I'm try to solve it since a lot of hours ago but I can't!

© Stack Overflow or respective owner

Related posts about ipad

Related posts about video