为什么我的视频在模拟器中播放但在使用AVFoundation Videoplayer的设备(iPad)上播放?

hea*_*kit 1 objective-c avfoundation ipad ios-simulator ios5

我建立了自己的自定义视频播放器(编辑:在这里找到示例代码)

AVMoviePlayerView.h

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@class AVPlayer;

@interface AVMoviePlayerView : UIView

@property (nonatomic) AVPlayer *player;

- (void)setPlayer:(AVPlayer*)player;
- (void)setVideoFillMode:(NSString *)fillMode;

@end
Run Code Online (Sandbox Code Playgroud)

AVMoviePlayerView.m

#import "AVMoviePlayerView.h"
#import <CoreMedia/CoreMedia.h>

@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
Run Code Online (Sandbox Code Playgroud)

在我的MainViewController.m中调用它 - (void)viewDidLoad

    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]];
Run Code Online (Sandbox Code Playgroud)

用方法

- (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];
}
Run Code Online (Sandbox Code Playgroud)

当然也在MainViewController.h中定义

...
#import <CoreGraphics/CoreGraphics.h>
#import "AVMoviePlayerView.h"
@class AVMoviePlayerView;
@class AVPlayer;
...
IBOutlet AVMoviePlayerView *VideoLoop;
AVPlayer* avPlayer;
Run Code Online (Sandbox Code Playgroud)

它在模拟器中工作正常(除了循环,但这是一个不同的问题),但在设备(iPad3)上没有显示视频.

我错过了什么吗?感谢名单!

编辑:为了让我更容易告诉我多么愚蠢我请在这里找到一些esample代码.这在模拟器中有效但在设备上无效.

hea*_*kit 12

发现原因 - 仅花费我50分...... iOS支持高达2.5 Mbps的MPEG-4视频和H.264 1080p.我的视频帧尺寸太大了!