MPMoviePlayerController

MPMoviePlayerController用於管理視頻的播放,視頻能夠來自於本地文件或者是網絡數據流。視頻能夠全屏或者內置在moviePlayer擁有的view中播放。你能夠在你的app中在一個view包含視頻播放的view,或者使用MPMoviePlayerViewController來管理。網絡

默認支持AirPlayapp

當咱們將MPMoviePlayerController加入到視圖中時,須要合理設置framedom

MPMoviePlayerController *player =
        [[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player prepareToPlay]
[player.view setFrame: myView.bounds];  // player's frame must match parent's
[myView addSubview: player.view];
// ...
[player play];

(1)添加自定義子視圖ide

將moviePlayer認爲是一個封閉的結構,你能夠在movie的Layer content上添加自定義的子試圖可是毫不要修改它已經存在的子試圖。 (view)性能

除了在movie上添加子視圖,能夠在backgroundView上添加子控件。在內置和全屏模式下,自定義的控件都被支持。可是必須調整兩種狀況下的位置。能夠使用通知來判斷和調整。(backgroundView)ui

Use the MPMoviePlayerWillEnterFullscreenNotification and MPMoviePlayerWillExitFullscreenNotification notifications to detect changes to and from fullscreen modethis

MPMoviePlayerController支持代碼控制,也提供了供用戶使用的按鈕。你能夠使用MPMoviePlayerController實現的協議spa

MPMediaPlayback 中的方法用代碼來控制視頻播放的大部分操做。該協議中的方法能讓你開始,中止,根據當前播放的內容向前或者向後,甚至改變播放的速率。controlStyle屬性可以展現一些系統提供的標準的控制按鈕來控制視頻的播放。同時你也能夠設置shouldAutoplay屬性來決定是否自動播放網絡視頻文件。代理

當你建立了一個MPMoviePlayerController的時候,你指定了要播放的視頻文件。可是,你能夠經過設置contentUrl屬性來改變正在播放的視頻。改變這個屬性使你從新利用了同一個movie Playercode

NOTE

Although you can create multiple MPMoviePlayerController objects and present their views in your interface, only one movie player at a time can play its movie.

爲長視頻建立video書籤和章節連接提供便利。MPMoviePlayerController提供了在特定時間生成縮略圖的方法。能夠使用

thumbnailImageAtTime:timeOption:方法來建立單張縮略圖或者用requestThumbnailImagesAtTimes:timeOption:

來建立多張縮略圖。


To play a network stream whose URL requires access credentials, first create an appropriate NSURLCredential object. Do this by calling, for example, the initWithUser:password:persistence: method, as shown here:


  • NSURLCredential *credential = [[NSURLCredential alloc]

  •                         initWithUser: @"userName"

  •                             password: @"password"

  •                         persistence: NSURLCredentialPersistenceForSession];

  •  

  • self.credential = credential;

  • [credential release];

In addition, create an appropriate NSURLProtectionSpace object, as shown here. Make appropriate modifications for the realm you are accessing:


  • NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]

  •                             initWithHost: "@streams.mydomain.com"

  •                                     port: 80

  •                                 protocol: @"http"

  •                                   realm: @"mydomain.com"

  •                     authenticationMethod: NSURLAuthenticationMethodDefault];

  •  

  • self.protectionSpace = protectionSpace;

  • [protectionSpace release];

Add the URL credential and the protection space to the Singleton NSURLCredentialStorage object. Do this by calling, for example, the setCredential:forProtectionSpace: method, as shown here:


  • [[NSURLCredentialStorage sharedCredentialStorage]

  •                     setDefaultCredential: credential

  •                       forProtectionSpace: protectionSpace];

With the credential and protection space information in place, you can then play the protected stream.



一 Movie Player Notifications

MPMoviePlayerController是經過通知而非咱們常見的代理來通知視頻播放的狀態的。如下狀況會發送通知

  1. 視頻開始播放,暫停,快進,快退(四個)

  2. AirPlay播放開始,結束(兩個)

  3. 視屏的scaling mode改變了

  4. 視頻進入全屏或者退出全屏

  5. 網絡視頻的load state改變了

  6. 網絡視頻的meta-information能夠得到了


二 支持的格式

.mov, .mp4, .mpv, and .3g

  • H.264 Baseline Profile Level 3.0 video, up to 640 x 480 at 30 fps. (The Baseline profile does not support B frames.) 

  • MPEG-4 Part 2 video (Simple Profile)

If you use this class to play audio files, it displays a white screen with a QuickTime logo while the audio plays. For audio files, this class supports AAC-LC audio at up to 48 kHz, and MP3 (MPEG-1 Audio Layer 3) up to 48 kHz, stereo audio.

相關文章
相關標籤/搜索