1. Introduction of the system framework
2. Create a URL for your video
3. Create a playback item
4. Initialize the player
5. Set the playback page
Introducing System files #import <AVFoundation/AVFoundation.h> #import <AVKit/AVKit.h> @interface viewcontroller ()/** * Controls for video playback */@property (weak, nonatomic) Iboutlet uislider *progressslider;/** * Declare control properties that play video [can play video or play Audio] */@property (Nonatomic,strong) Avplayer *player;/** * Total duration of playback */@property (nonatomic,assign) cgfloat sumplayoperation; @end @implementation viewcontroller-(void) viewdidload {[Super viewdidload]; Additional setup after loading the view, typically from a nib. Set the playback URL nsstring *playstring = @ "Http://static.tripbe.com/videofiles/20121214/9533522808.f4v.mp4"; Nsurl *url = [Nsurl urlwithstring:playstring]; Set the item to play Avplayeritem *item = [[Avplayeritem alloc] initwithurl:url]; Initialize the Player object self.player = [[Avplayer alloc] initwithplayeritem:item]; Set Playback page Avplayerlayer *layer = [Avplayerlayer Playerlayerwithplayer:_player]; Set the size of the playback page layer.frame = CGRectMake (0, 0, [UIScreen mainscreen].bounds.size.width, 300); Layer.bAckgroundcolor = [Uicolor Cyancolor]. Cgcolor; Sets the ratio between the playback window and the current view display content layer.videogravity = Avlayervideogravityresizeaspect; Add playback view to Self.view [Self.view.layer Addsublayer:layer]; Set the default value for playback progress self.progressSlider.value = 0; Sets the default volume value for playback self.player.volume = 1.0f; } #pragma mark-Start button Response Method-(Ibaction) Startplayer: (ID) Sender {[Self.player play];} #pragma mark-Pause button Response Method-(Ibaction) Stopplayer: (ID) Sender {[Self.player pause];} #pragma mark-Change Progress-(Ibaction) Changeprogress: (ID) Sender {self.sumplayoperation = Self.player.currentItem.duration.va Lue/self.player.currentitem.duration.timescale; Cmtimemake (A, B) a represents the current time, and the number of frames per second [Self.player seektotime:cmtimemakewithseconds (self.progressslider.value* Self.sumplayoperation, Self.player.currentItem.duration.timescale) completionhandler:^ (BOOL finished) {[Self.playe R Play]; }]; }
Simple application of iOS Avplayer