#import "ViewController.h" #import <AVFoundation/AVFoundation.h> #import <AVKit/AVKit.h> #import < Mediaplayer/mediaplayer.h> @interface Viewcontroller () @property (nonatomic, strong) MPMoviePlayerController * Playercontroller; @end @implementation viewcontroller-(void) viewdidload {[Super viewdidload]; [Self test1]; }-(void) test {//ios 9.0 video playback//create video playback controller Avplayerviewcontroller * PLAYVC = [[Avplayerviewcontroller alloc]in It]; NSString * Path = [[NSBundle mainbundle]pathforresource:@] alizee_la_isla_bonita copy. mp4 "Oftype:nil"; Set Property Playvc.player = [Avplayer playerwithurl:[nsurl Fileurlwithpath:path]]; [Self PRESENTVIEWCONTROLLER:PLAYVC animated:yes completion:nil]; Sets the size of the view of the player controller playVc.view.frame = CGRectMake (0, 0, 300, 300); Play [Playvc.player play]; Add the viewer's view to the view [Self.view AddSubview:playVc.view]; }-(void) test1 {//ios 8.0 has interface//get resource path nsurl * url = [[NSBundle mainbundle]urlforresource:@] alizee_la_isla_bonita copy. mp4 "Withextension:nil"; NSLog (@ "%@", url); Create player Controller Mpmovieplayerviewcontroller * Playercontroller = [[Mpmovieplayerviewcontroller alloc]initwithcontenturl: URL]; Play [self Presentviewcontroller:playercontroller animated:yes completion:nil]; }-(void) test2 {//IOS 8.0 No interface//Get resource path nsurl * url = [[NSBundle mainbundle]urlforresource:@] Alizee_la _isla_bonita copy. mp4 "Withextension:nil"; Create Video Player MPMoviePlayerController * Playercontroller = [[MPMoviePlayerController Alloc]initwithcontenturl:url]; Be sure to quote strongly, otherwise you won't be able to play the video self. Playercontroller = Playercontroller; Ready to play [Playercontroller Preparetoplay]; Set style Playercontroller.controlstyle = Mpmoviecontrolstylefullscreen; PlayerController.view.frame = CGRectMake (0, 0, 300, 300); PlayerController.view.frame = Self.view.bounds; [Self.view AddSUbview:PlayerController.view]; [Playercontroller play]; }
Video playback iOS8.0 with iOS 9.0