title: How do I subclass AVPlayer?
body: <p>I'm working to subclass <code>AVPlayer</code> so that I can create a method that <code>skipsBackwards</code> in a queue of music. I want to build a fully functional music player that uses music from the users iPod. So that means <code>AVAudioPlayer</code> is out as well as <code>MPMusicPlayerController</code>. Also Core Audio scares me so I'm hoping to steer clear of that for now. </p>
  
  <p>I've considered using categories to extend the <code>AVPlayer</code> class but I need my subclass to have a class variable to store a <code>MPMediaItemCollection</code> so I figure it makes most sense to subclass rather that add a category.</p>
  
  <p>Here's my exception</p>
  
  <p>![enter image description here][1]</p>
  
  <p>Here's my appDelegate code where I setup the <code>AVPlayer</code> that is subclassed as <code>SWPlayer</code></p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &lt;MediaPlayer/MediaPlayer.h&gt;
  #import &lt;AVFoundation/AVFoundation.h&gt;
  #import &lt;AudioToolbox/AudioToolbox.h&gt;
  #import "SWPlayer.h"
  
  
  @interface AppDelegate : UIResponder &lt;UIApplicationDelegate&gt;
  
  @property (strong, nonatomic) UIWindow *window;   
  @property (nonatomic,retain)SWPlayer *bookPlayer;
  
  @end
  
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
  
      // Setup AudioSession
      NSError *sessionError = nil;
      [[AVAudioSession sharedInstance] setDelegate:self];
      [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&amp;sessionError];
  
      // Allow the audio to mix with other apps (necessary for background sound)
      UInt32 doChangeDefaultRoute = 1;
      AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doChangeDefaultRoute), &amp;doChangeDefaultRoute);
  
      //Grab some Songs to Test with
      MPMediaQuery *query = [MPMediaQuery songsQuery];
      NSArray *collection = [query items];
  
      //Setup bookPLayer to Test
      MPMediaItem *item = [collection objectAtIndex:5];
      NSLog(@"%@",[item valueForProperty:MPMediaItemPropertyTitle]);
      NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];
      self.bookPlayer = [[SWPlayer alloc]initWithURL:url];
      [bookPlayer play];
  
      [bookPlayer skipForwards];
  
      return YES;
  }
  </code></pre>
  
  <p>Here is my very basic subclass...</p>
  
  <pre><code>#import &lt;AVFoundation/AVFoundation.h&gt;
  #import &lt;MediaPlayer/MediaPlayer.h&gt;
  
  @interface SWPlayer : AVPlayer
  
  @property(nonatomic,retain)MPMediaItemCollection *mediaItemCollection;
  
  -(void)skipForwards;
  -(void)skipBackwards;
  
  @end
  
  #import "SWPlayer.h"
  
  @implementation SWPlayer
  
  @synthesize mediaItemCollection;
  
  -(void)skipForwards{
      NSLog(@"SWPlayer called skipForward method");
  }
  
  -(void)skipBackwards{
      NSLog(@"SWPlayer called skipBackward method");
  
  }
  
  @end
  </code></pre>
  
  <p>The music plays using my subclass of <code>AVPlayer</code>. The issue is that as soon as I call the <code>skipForward</code> method of <code>SWPlayer</code> I get an unrecognized selector error and the app crashes. What I am missing here? </p>