When you click on a button to play the video, if the button triggers the function when the Alloc MPMoviePlayerController object, loading the resource file, because loading the resource file also takes time, there will be a short black splash screen, this experience is very bad, there is a good solution is, Pre-Alloc the MoviePlayer object in advance and call play directly when the button is clicked.
Pre-load related code:
Pre-load video to avoid black screen nsstring *videopath=[[nsbundle mainbundle]pathforresource:@ "Startvideo" oftype:@ "mp4"]; Self.moviecontroller=[[mpmovieplayercontroller alloc] Initwithcontenturl:[nsurl Fileurlwithpath:videopath]]; [[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector (moviefinish:) Name: Mpmovieplayerplaybackdidfinishnotification Object:self.movieController]; Self.moviecontroller.scalingmode=mpmoviescalingmodeaspectfill; [Self.view InsertSubview:movieController.view Belowsubview:bgimgview]; Self.moviecontroller.view.frame=cgrectmake (0,0, 1024x768, 768); [Self.moviecontroller Setcontrolstyle:mpmoviecontrolstylenone]; Remove the progress bar self.movieController.initialPlaybackTime = -1.0; [Self.moviecontroller Setshouldautoplay:no]; [Self.moviecontroller Preparetoplay];
Note in particular:
[self. Moviecontroller setshouldautoplay:NO];
[self. Moviecontrollerpreparetoplay];
Set AutoPlay to No, the default is yes, it will play automatically.
"iOS development" resolves "a black screen splash screen issue when clicking MPMoviePlayerController to play Video"