Having trouble figuring out error.

Discussion in 'iOS Programming' started by gizabo, Jun 11, 2009.

  1. gizabo macrumors regular

    Joined:
    Jul 20, 2008
    #1
    For some reason when I run my code, i get this error

    Code:
    [UIViewController playVideoWithControls]: unrecognized selector sent to instance 0x1028b1
    If you want, here is my .m:

    Code:
    #import "VideoView.h"
    #import <MediaPlayer/MediaPlayer.h>
    
    @implementation VideoView
    @synthesize player;
    
    - (void)playVideoWithURL:(NSURL *)url showControls:(BOOL)showControls {
        if (!player) {
            player = [[MPMoviePlayerController alloc] initWithContentURL:url];
    
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPlaying:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
    
            if (!showControls) {
                    player.scalingMode = MPMovieScalingModeAspectFill;
                    player.movieControlMode = MPMovieControlModeHidden;
            }
    
            [player play];
        }
    }
    
    - (IBAction)playVideoWithControls {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mov"];
        NSURL *url = [NSURL fileURLWithPath:path];
        [self playVideoWithURL:url showControls:YES];
    }
    
    
    - (void)didFinishPlaying:(NSNotification *)notification {
        if (player == [notification object]) {      
            [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
            [player release];
            player = nil;
        }
    }
    
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
        // Release anything that's not essential, such as cached data
    }
    
    
    - (void)dealloc {
        [super dealloc];
    }
    
    
    @end

    And my .h:
    Code:
    #import <UIKit/UIKit.h>
    #import <MediaPlayer/MediaPlayer.h>
    
    
    @interface VideoView : UIViewController {
        MPMoviePlayerController *player;
    
    }
    @property (nonatomic, retain) MPMoviePlayerController *player;
    - (IBAction)playVideoWithControls;
    
    
    @end
    Thanks. I just cant get what this error is...
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    What's the code look like that actually calls playVideoWithControls? Either you're using it improperly, or there's some leak going on is my guess.
     

Share This Page