iOS video playback

Source: Internet
Author: User

#import "ViewController.h"
@import MediaPlayer;





@interface Viewcontroller ()
{
MPMoviePlayerController *_mov;
}
@property (Weak, nonatomic) Iboutlet Uiimageview *xianshi;

@end

@implementation Viewcontroller
-(Ibaction) Didclickdo: (ID) Sender {


MPMoviePlayerController *play = [[MPMoviePlayerController alloc] initwithcontenturl:@ "/users/apple/desktop/ Hdmv.mp4 "];
[Self presentmovieplayerviewcontrolleranimated:play];
The way it's been obsolete
UIImage *image = [_mov thumbnailimageattime:100 timeoption:mpmovietimeoptionnearestkeyframe];
_xianshi.image = image;

Now the
[_mov requestthumbnailimagesattimes:@[@1.0,@10.0,@30.0] timeoption:mpmovietimeoptionnearestkeyframe];//on effective virginity

}
-(void) Didthumb: (nsnotification *) notification
{
NSLog (@ "%@", notification.userinfo);//The specific time
UIImage *image = Notification.userinfo[mpmovieplayerthumbnailimagekey];
if (image) {
_xianshi.image = image;//Capture Successful display
}
}

-(void) Viewdidload {
[Super Viewdidload];
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (didplaybacknotif:) Name: Mpmovieplayerplaybackstatedidchangenotification Object:nil];
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (didthumb:) Name: Mpmovieplayerthumbnailimagerequestdidfinishnotification Object:nil];


Nsurl *url = [Nsurl fileurlwithpath:@ "/users/apple/desktop/hdmv.mp4"];//Path
_mov = [[MPMoviePlayerController Alloc]initwithcontenturl:url];
_mov.view.frame = CGRectMake (100, 100, 200, 100);//Playback position

_mov.controlstyle = Mpmoviecontrolstylenone;
_mov.shouldautoplay = NO;
[_mov preparetoplay];//start playing
[_mov play];
[Self.view Addsubview:_mov.view];


}

iOS video playback

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.