title: Why is my Video played in simulator but not on Device (iPad) using AVFoundation Videoplayer?
body: <p>I built my own custom video player (edit: <a href="https://dl.dropbox.com/u/2896178/AVFoundationVideoPLayer.zip" rel="nofollow">find example code here</a>) with</p>
  
  <p>AVMoviePlayerView.h</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &lt;AVFoundation/AVFoundation.h&gt;
  
  @class AVPlayer;
  
  @interface AVMoviePlayerView : UIView
  
  @property (nonatomic) AVPlayer *player;
  
  - (void)setPlayer:(AVPlayer*)player;
  - (void)setVideoFillMode:(NSString *)fillMode;
  
  @end
  </code></pre>
  
  <p>and</p>
  
  <p>AVMoviePlayerView.m</p>
  
  <pre><code>#import "AVMoviePlayerView.h"
  #import &lt;CoreMedia/CoreMedia.h&gt;
  
  @implementation AVMoviePlayerView
  
  
  + (Class)layerClass {
  
      return [AVPlayerLayer class];
  
  }
  
  - (AVPlayer*)player
  {
      return [(AVPlayerLayer*)[self layer] player];
  }
  
  - (void)setPlayer:(AVPlayer*)player
  {
      [(AVPlayerLayer*)[self layer] setPlayer:player];
  }
  
  - (void)setVideoFillMode:(NSString *)fillMode
  {
      AVPlayerLayer *playerLayer = (AVPlayerLayer*)[self layer];
      playerLayer.videoGravity = fillMode;
  }
  
  
  @end
  </code></pre>
  
  <p>calling it from inside my MainViewController.m within -(void)viewDidLoad</p>
  
  <pre><code>    NSURL* url = [[NSBundle mainBundle] URLForResource:@"myVideo.264" withExtension:@"mp4"]; 
      self.avPlayer = [AVPlayer playerWithURL:url];
      [avPlayer addObserver:self forKeyPath:@"status" options:0 context:AVMoviePlayerViewControllerStatusObservationContext];
      [[NSNotificationCenter defaultCenter]   addObserver:self
                                                 selector:@selector(playerItemDidReachEnd:)
                                                     name:AVPlayerItemDidPlayToEndTimeNotification
                                                   object:[self.avPlayer currentItem]];
  </code></pre>
  
  <p>with methods</p>
  
  <pre><code>- (void)observeValueForKeyPath:(NSString*) path ofObject:(id)object change:(NSDictionary*)change context:(void*)context
  {
      if (avPlayer.status == AVPlayerStatusReadyToPlay) {
          [self.VideoLoop setPlayer:self.avPlayer];
          [self.avPlayer play];
      }
  }
  - (void)playerItemDidReachEnd:(NSNotification *)notification {
      AVPlayerItem *p = [notification object];
      [p seekToTime:kCMTimeZero];
  }
  </code></pre>
  
  <p>and of course defined in MainViewController.h</p>
  
  <pre><code>...
  #import &lt;CoreGraphics/CoreGraphics.h&gt;
  #import "AVMoviePlayerView.h"
  @class AVMoviePlayerView;
  @class AVPlayer;
  ...
  IBOutlet AVMoviePlayerView *VideoLoop;
  AVPlayer* avPlayer;
  </code></pre>
  
  <p>It works fine in Simulator (except the loop, but thats a different problem) but on the device (iPad3) no video shows up.</p>
  
  <p>Did I miss anything?
  Thanx!!!</p>
  
  <p>EDIT: <a href="https://dl.dropbox.com/u/2896178/AVFoundationVideoPLayer.zip" rel="nofollow">TO make it easier toshow me how stupid I am please find here some esample code. this does work in the simulator but not on device.</a></p>