IOS movie player-mpmovieplayercontroller

Source: Internet
Author: User
Tags notification center

Http://blog.csdn.net/iukey/article/details/7311126

Pmovieplayercontroller is a bit similar to avaudioplayer. The former plays the video and the latter plays the audio, but it is also very different. mpmovieplayercontroller can be initialized directly through a remote URL, but avaudioplayer cannot. But in general, it feels similar. Let's talk about the experience.
Supported formats: mov, MP4, m4v, and 3GP. Multiple audio formats are also supported.
First, you need to introduce mediaplayer. Framework. Then, import the corresponding header file in the file using mpmovieplayercontroller.
I. Create
The mpmovieplayercontroller class is initialized through an nsurl, which can be local or remote. Initialization must be implemented through the initwithcontenturl method:

[HTML]
View plaincopyprint?
    1. Mpmovieplayercontroller *Movieplayer= [[Mpmovieplayercontroller alloc] initwithcontenturl: [nsurl urlwithstring: @ "http: //"]; // remote

Or[HTML]
View plaincopyprint?

    1. Nsstring *Path= [Nsstring stringwithformat: @ "% @/documents/video.3gp", nshomedirectory ()]; // local path
    2. Mpmovieplayercontroller *Movieplayer= [[Mpmovieplayercontroller alloc] initwithcontenturl: [nsurl fileurlwithpath: path]; // local

Ii. attribute settings
1. Controller Style[HTML]
View plaincopyprint?

    1. Movieplayer. moviewcontrolmode=Mpmoviecontrolmodedefault;

You can use the following styles:
Mpmoviecontrolmodedefault: Display playing/pause, volume and time control
Mpmoviecontrolmodevolumeonly only displays volume control
Mpmoviecontrolmodehidden no Controller
2. Screen width/height ratio[HTML]
View plaincopyprint?

    1. Movieplayer. scallingmode=Mpmoviescallingmodeaspectfit;

You can use the following width/height ratio:
Mpmoviescallingmodenone does not scale
Mpmoviescallingmodeaspectfit adapts to the screen size and maintains the aspect ratio.
Mpmoviescallingmodeaspectfill adapts to the screen size, maintains the aspect ratio, and supports cropping.
Mpmoviescallingmodefill fills the screen and does not maintain the aspect ratio.
3. Background Color
The background color is used when the player is transferred in and out. When the screen cannot be filled, it is also used to fill the blank area. The Default background color is black, but you can use the uicolor object to set the backgroundcolor attribute to change the background color:[HTML]
View plaincopyprint?

    1. Movieplayer. backgroundcolor= [Uicolor redcolor];

3. Play and stop movies
To play a movie, call the play method. The movie playback controller automatically switches the view to the movie player and starts playing the video:[HTML]
View plaincopyprint?

    1. [Movieplayer play];

When you click the done button or the stop method is called[HTML]
View plaincopyprint?

    1. [Movieplayer stop];

When a movie stops playing, it is automatically switched back to the application before playing.ProgramView.
Iv. Notifications
Your program can configure when the movie player sends notifications, including ending loading content, technical playback, and changing the aspect ratio. The movie player sends events to the cocoa notification center. You can configure these events to forward them to an object in your application. To receive these notifications, you must use the nsicationcenter center class to add an observer (observer) to the movie player ):[HTML]
View plaincopyprint?

    1. Nsnotificationcenter *Icationicationcenter= [Nsicationicationcenter defacenter center];
    2. [Icationicationcenter addobserver: Self selector: @ selector (movieplayerpreloadfinish :) name: mpmovieplayercontentpreloaddidfinishnotification object: movieplayer];

The notification will be sent to the specified delegate class and target method. The notification parameters let you know which event triggers the delegate method:[HTML]
View plaincopyprint?

    1. -(Void) movieplayerpreloaddidfinish :( nsnotification *) Notification {
    2. // Add your processingCode
    3. }

you will see the following notifications:
mpmovieplayercontentpreloaddidfinishnotification
the notification is sent when the movie player stops pre-loading the content. Because the content can be played only when a part of the content is loaded, this notification may be sent only after it has been played.
mpmovieplayerscallingmodedidchangednotification
when the user changes the scaling mode of the movie, it is triggered. You can click the zoom icon to switch between full-screen playback and window playback.
mpmovieplayerplaybackdidfinishnotification
the notification is sent when the video is played or the user presses the done button.

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.