MPMoviePlayerController 从照片库加载视频,播放速度如此之快

Posted

技术标签:

【中文标题】MPMoviePlayerController 从照片库加载视频,播放速度如此之快【英文标题】:MPMoviePlayerController load video from Photo library,play so fast 【发布时间】:2013-07-31 12:43:40 【问题描述】:

// CameraViewController.h

@interface CameraViewController : UIViewController

UIImagePickerController *_picker;

@property (strong, nonatomic) IBOutlet UIImageView *imageView;

@property (nonatomic, 保留) MPMoviePlayerController *player;

(IBAction)loadImage:(UIButton *)sender;

// CameraViewController.m

@interface CameraViewController ()

@property(强,非原子) MPMoviePlayerController *playView;

@结束

@implementation CameraViewController

@synthesize imageView = _imageView;

@synthesize player = _player;

@synthesize playView = _playView;

(void)viewDidLoad

[super viewDidLoad];

_picker = [[UIImagePickerController alloc] init];

(void)didReceiveMemoryWarning

[super didReceiveMemoryWarning];

(IBAction)loadImage:(UIButton *)sender

_picker.delegate = self;

_picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

NSArray *mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie, nil];

_picker.mediaTypes = mediaTypes;

[self presentViewController:_picker animated:YES completion:NULL];

pragma mark -ImagePicker 委托

(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

UIImage *image = nil;

NSURL *imageURL = nil;

imageURL = [信息 valueForKey:UIImagePickerControllerMediaURL];

如果 (imageURL == nil)

image = [info valueForKey:UIImagePickerControllerEditedImage];

if (image == nil) 

    image = [info valueForKey:UIImagePickerControllerOriginalImage];

    _imageView.image = image;



else 


否则

self.player = [[MPMoviePlayerController alloc] initWithContentURL:imageURL];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.player];

    self.player.view.frame = CGRectMake(10.0, 10.0, 200.0, 200.0);

    self.player.view.backgroundColor = [UIColor clearColor];

    self.player.movieSourceType = MPMovieSourceTypeFile;

    [self.player prepareToPlay];

    [self.view addSubview:self.player.view];

    [self.player play];

[pickerdismissViewControllerAnimated:YES 完成:NULL];

(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

[pickerdismissViewControllerAnimated:YES 完成:NULL];

pragma mark - 用户定义

(void)movieFinishedCallback:(NSNotification *)通知

MPMoviePlayerViewController *player = [通知对象];

[[NSNotificationCenter defaultCenter] removeObserver:self 名称:MPMoviePlayerPlaybackDidFinishNotification 对象:播放器];

[player.view removeFromSuperview];

movieFinishedCallback:方法会被立即调用,所以视频不能完全播放。

如何解决?

【问题讨论】:

嗯,你能帮帮我吗? 【参考方案1】:

苹果建议:

使用 AVPlayer 播放来自 iPod 库、相机胶卷或通过 iTunes 文件共享的视频。

【讨论】:

以上是关于MPMoviePlayerController 从照片库加载视频,播放速度如此之快的主要内容,如果未能解决你的问题,请参考以下文章

当应用程序从后台进入前台时,MPMoviePlayerController 黑屏

MPMoviePlayerController:无法从全屏切换到嵌入式

MPMoviePlayerController 从流式视频中获取缩略图?

从 MPMoviePlayerController 标准控件中删除/隐藏全屏按钮

使用 MPMoviePlayerController 从 session.outputURL 播放视频

iOS- MPMoviePlayerController 无法从远程 URL 播放视频