Create empty application and add homeviewcontroller
Homeviewcontroller. H code
# Import <uikit/uikit. h> # import <mediaplayer/mediaplayer. h> @ interface homeviewcontroller: uiviewcontroller {mpmovieplayerviewcontroller * playerviewcontroller;}-(ibaction) buttonclicked :( ID) sender;
@ End
Homeviewcontroller. m code
# Import "homeviewcontroller. H "@ interface homeviewcontroller () @ end @ implementation homeviewcontroller // call the movieplayerdidfinish method when the video is played or you click the done button during video playback, an object of the mpmovieplayercontroller type is passed. It is an attribute of the mpmovieplayerviewcontroller class. mpmovieplayercontroller is automatically created to accept commands but cannot be modified, you can use it to manage and configure video playback. // Obtain the mpmovieplayercontroller object in the movieplayerdidfinish method, then move the Message notification from nsicationicationcenter, stop playing the video, remove the video playback view, and release the mpmovieplayerviewcontroller object. -(Void) movieplayerdidfinish :( nsnotification *) Anote {mpmovieplayercontroller * player = [Anote object]; [[nsicationicationcenter defacenter center] removeobserver: Self name: mpmovieplayerplaybackdidfinishnotification object: Player] [PLAYER stop]; [self dismissmovieplayerviewcontrolleranimated]; [playerviewcontroller release];}-(ibaction) buttonclicked :( ID) sender {/* nsstring * filepath = [[nsbundle mainbundle] resourcepath] stringbyappendingpathcomponent: @ "movie. mov "]; nsurl * movieurl = [nsurl fileurlwithpath: filepath]; * // play the video file nsurl * movieurl = [nsurl urlwithstring: @" http://www.5i-dream.cn/mkovie.mov "] through HTTP; playerviewcontroller = [[mpmovieplayerviewcontroller alloc] handler: movieurl]; [nsicationicationcenter defaultcenter] addobserver: Self selector: @ selector (handler :) name: jsonobject: [playerviewcontroller movieplayer]; [self presentmovieplayerviewcontrolleranimated: playerviewcontroller]; // display the video playback view} @ end