tags:

views:

24

answers:

0

I am trying to play a series of videos.

In order to do this, I thought I would keep track of the sequence number for the next video to play.

The problem is that I can't seem to access the array names from inside the callback. It seems like it might be a memory issue because the same code put in loadView works fine.

Here is the code I am using. While this code works fine in loadView. I don't understand why it will not work in the MPMoviePlayer callback?

NSLog(@"Chosen record: %@", [arrayBrotherPirateEnglish objectAtIndex: 2] );

The array:

NSArray *arrayBrotherPirateEnglish;

The initializing of the array:

arrayBrotherPirateEnglish = [NSArray arrayWithObjects: @"OBTP English full with text", @"OBTP English p1", @"OBTP English p2",
                                 @"OBTP English p3", @"OBTP English p4", @"OBTP English p5", @"OBTP English p6",  
                                 @"OBTP English p7", @"OBTP English p8", @"OBTP English p9", @"OBTP English p10",  
                                 @"OBTP English p11",                                    
                                nil]; 

Code to play movie:

NSString *url = [[NSBundle mainBundle] 
                     pathForResource:strFileName 
                     ofType:@"mp4"];

    playerViewController = 
    [[MPMoviePlayerViewController alloc] 
     initWithContentURL:[NSURL fileURLWithPath:url]];

    //need this else, video shows half display
    playerViewController.view.frame = self.view.frame;

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



    [self.view addSubview:playerViewController.view];

    //---play movie---
    player = [playerViewController moviePlayer];
    [player play];

The callback:
- (void) movieFinishedCallback:(NSNotification*) aNotification {
    NSLog(@"MOVIE FINISHED.");

    player = [aNotification object];
    [[NSNotificationCenter defaultCenter] 
     removeObserver:self
     name:MPMoviePlayerPlaybackDidFinishNotification
     object:player];                

    //if continuous mode, nothing else left to play
    if([strPageMode compare:@"OFF"] == NSOrderedSame)
    {
        [player stop];          

        //[self.view removeFromSuperView];
        [player autorelease];   


        NSLog(@"STOPSTOPYSTPO");
    }
    //page mode, each page is played at a time
    else
    {

        NSLog(@"Chosen record: %@", [arrayBrotherPirateEnglish objectAtIndex: 2] );

    }
}       

The line of code above result in the following error. Any insight appreciated? 2010-07-26 14:43:45.275 BookReaderJuly23[52856:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSCFData objectAtIndex:]: unrecognized selector sent to instance 0x5556cc0'