Movie Player

Discussion in 'iOS Programming' started by forrestgrant, Feb 11, 2009.

  1. forrestgrant macrumors member

    Joined:
    Jun 24, 2008
    #1
    I am trying to play videos. I have a table view, if you select the first row, video A plays, if you select the second row, video B plays. This works fine if I open the app, and select a row, however. When I am done with that video, if I then select the next video, nothing happens.

    Help?

    Code:
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    	
    	MPMoviePlayerController *player;
    	NSBundle *bundle = [NSBundle mainBundle];
    	NSString *moviePath;
    	
    	NSInteger row = [indexPath row];
    	if(row == 0) {
    		moviePath = [bundle pathForResource:@"video_a" ofType:@"m4v"];
    		player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
    	} else {
    		moviePath = [bundle pathForResource:@"video_b" ofType:@"m4v"];
    		player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
    	}
    	
    	[player play];
    }
    
     
  2. jnic macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #2
    You don't seem to be unloading the player between videos. Try adding a notification for when playback finishes and use it to unload your player:

    Code:
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(yourMethod:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    Code:
    - (void)yourMethod:(NSNotification*)notification {
    	[player release];
    }
     
  3. forrestgrant thread starter macrumors member

    Joined:
    Jun 24, 2008
    #3
    Worked. Thanks.
    I knew it must be something stupidly simple.
     

Share This Page