ios6 - MPMoviePlayerController load video from Photo library,play so fast -
// cameraviewcontroller.h
@interface cameraviewcontroller : uiviewcontroller{
uiimagepickercontroller *_picker;
}
@property (strong, nonatomic) iboutlet uiimageview *imageview;
@property (nonatomic, retain) mpmovieplayercontroller *player;
- (ibaction)loadimage:(uibutton *)sender;
// cameraviewcontroller.m
@interface cameraviewcontroller ()
@property (strong, nonatomic) mpmovieplayercontroller *playview;
@end
@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 delegate
(void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info {
uiimage *image = nil;
nsurl *imageurl = nil;
imageurl = [info valueforkey:uiimagepickercontrollermediaurl];
if (imageurl == nil) {
image = [info valueforkey:uiimagepickercontrollereditedimage]; if (image == nil) { image = [info valueforkey:uiimagepickercontrolleroriginalimage]; _imageview.image = image; } else { }
}
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];
}
[picker dismissviewcontrolleranimated:yes completion:null];
}
(void)imagepickercontrollerdidcancel:(uiimagepickercontroller *)picker {
[picker dismissviewcontrolleranimated:yes completion:null];
}
pragma mark - user define
(void)moviefinishedcallback:(nsnotification *)notification {
mpmovieplayerviewcontroller *player = [notification object];
[[nsnotificationcenter defaultcenter] removeobserver:self name:mpmovieplayerplaybackdidfinishnotification object:player];
[player.view removefromsuperview];
}
the moviefinishedcallback:method called immediately,so video can not play completely.
how resolve it?
apple suggests:
uses avplayer play videos ipod library, camera roll, or via itunes file sharing.
Comments
Post a Comment