iOS crazy detailed video playback Mpmovieplayerviewcontroller

Source: Internet
Author: User

Frames that need to be imported

#import <MediaPlayer/MediaPlayer.h>

Mediaplayer.framework


Mpmovieplayerviewcontroller:

Open Network Video:

-(void) Openmovie

{

mpmovieplayerviewcontroller *movie = [[mpmovieplayerviewcontrolleralloc] Initwithcontenturl : [nsurlurlwithstring:@ "video network Address"];

[Movie. MoviePlayer Preparetoplay];

[ self presentmovieplayerviewcontrolleranimated: movie];

[Movie. MoviePlayer setcontrolstyle:mpmoviecontrolstylefullscreen];

[Movie. View setbackgroundcolor: [uicolorclearcolor]];

[Movie. View setframe:self. View. bounds];

[[nsnotificationcenterdefaultcenter]addobserver: Self

selector:@selector(moviefinishedcallback:)

name:mpmovieplayerplaybackdidfinishnotification

object: Movie. MoviePlayer];


}

-(void) Moviefinishedcallback: (nsnotification*) notify{

//The video is finished or the Done button under presentmovieplayerviewcontrolleranimated is clicked to respond to the notification.

MPMoviePlayerController* Themovie = [notifyobject];

[[nsnotificationcenterdefaultcenter]removeobserver: Self

name:mpmovieplayerplaybackdidfinishnotification

object: Themovie];

[selfdismissmovieplayerviewcontrolleranimated];

}

To open a local video:

-(void) Openmovie

{

nsstring *url = [[nsbundlemainbundle]pathforresource: @ "img_0322"ofType:@ "mp4"];

    mpmovieplayerviewcontroller *playerviewcontroller  = [[ mpmovieplayerviewcontrolleralloc " initwithcontenturl :[ nsurlfileurlwithpath :url] ";

[[nsnotificationcenterdefaultcenter]addobserver:selfselector: @selector(moviefinishedcallback:)

name:mpmovieplayerplaybackdidfinishnotification

object: [PlayerviewcontrollerMoviePlayer]];


[Self. View addsubview:p layerviewcontroller. View];


MPMoviePlayerController *player = [Playerviewcontrollermovieplayer];

[Playerplay];

}

-(void) Moviefinishedcallback: (nsnotification*) anotification {

MPMoviePlayerController *player = [Anotificationobject];

[[nsnotificationcenterdefaultcenter]removeobserver:Self name:mpmovieplayerplaybackdidfinishnotificationobject:p layer];

[Playerstop];

[Player. View Removefromsuperview];

}


More iOS Madness: Http://blog.csdn.net/wanglongblog

iOS crazy detailed video playback Mpmovieplayerviewcontroller

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.