Play videos on iOS

Source: Internet
Author: User

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.