Play the video at the beginning of the unity game, depending on your needs, and finally decide to use MPMoviePlayerController to achieve playback, as follows: by Tin
The size of the view needs to be modified under APPCONTROLLER.MM openeagl_unitycallback
UIView *mainview = [[UIView alloc] Initwithframe:[[uiscreen Mainscreen] applicationframe]]; // Mainview.backgroundcolor = [Uicolor graycolor]; = MainView; [Unitygetglviewcontroller (). View Addsubview: [Myviewcontroller Instance].view];
Need to receive unity commands in the game
//======================== Play start animation start ========================//By:xihao//2014-05-16voidPlaymovieinios (Char*path) {[[Myviewcontroller Instance] playvideo:[nsstring Stringwithutf8string:path]]; }voidExplayvideo (Char*URL) {[[Myviewcontroller Instance] playvideo:[nsstring stringwithutf8string:url];}voidExreleasevideo () {[[Myviewcontroller Instance] releasevideo];} Movieviewcontroller*MV;-(void) PlayVideo: (NSString *) path{if(MV! =Nil) {[MV Breakmovie]; [MV release]; MV=Nil; } MV=[[Movieviewcontroller alloc] init]; [Self.view AddSubview:mv.view]; [MV Playmovie:path];}-(void) releasevideo{if(MV! =Nil) {[MV Breakmovie]; [MV release]; MV=Nil; } unitysendmessage ("_iosdoor","Releasevideoover","");}//======================== play start animation end ========================
Next is to play the video
MPMoviePlayerController *movie;/** @method Play Movies*/-(void) Playmovie: (NSString *) filename{Nsurl*url =[Nsurl Fileurlwithpath:filename]; //Video Playback ObjectsMovie =[[MPMoviePlayerController alloc] initwithcontenturl:url]; Movie.controlstyle=Mpmoviecontrolstylenone; [Movie.view SetFrame:self.view.bounds]; Movie.initialplaybacktime= -1; [Self.view AddSubview:movie.view]; //register a notification to end a play[[Nsnotificationcenter defaultcenter] addobserver:self selector: @selec Tor (mymoviefinishedcallback:) name:mpmovieplayerplaybackdidfinishnotificat IonObject: movie]; [Movie Play];}#pragmaMark-------------------the end of the video playback delegate---------------------(void) breakmovie{if(Movie = =Nil) { return ; } //Destroying playback notifications[[Nsnotificationcenter Defaultcenter] removeobserver:self name: MpmovieplayerplaybackdidfinishnotificationObject: movie]; [Movie.view Removefromsuperview]; //releasing a video object[movie release]; Movie=Nil;}/*@method release objects when the video has finished playing*/-(void) Mymoviefinishedcallback: (nsnotification*) notify{NSNumber*reason =[Notify.userinfo Valueforkey:mpmovieplayerplaybackdidfinishreasonuserinfokey]; if(Reason! =Nil) {Nsinteger Reasonasinteger=[Reason IntegerValue]; Switch(Reasonasinteger) { Casempmoviefinishreasonplaybackended:{/*The movie ended normally*/ Break; } Casempmoviefinishreasonplaybackerror:{/*An error happened and the movie ended*/ Break; } Casempmoviefinishreasonuserexited:{/*The user exited the player*/ Break; }} NSLog (@"Finish Reason =%ld", (Long) Reasonasinteger); } /*cancels video auto-destruction performed by break MV//Video Playback object mpmovieplayercontroller* Themovie = [notify Object]; Destroy playback notifications [[Nsnotificationcenter Defaultcenter] removeobserver:self n Ame:mpmovieplayerplaybackdidfinishnotification Object:themovie]; [Themovie.view Removefromsuperview]; Release the video object [Themovie release]; Movie = nil; NSLog (@ "---------playvideoover 11"); */Unitysendmessage ("_iosdoor","Playvideoover",""); NSLog (@"---------Playvideoover");}