視頻播放筆記

來源:互聯網
上載者:User

MPMoviePlayerViewController和MPMoviePlayerController
使用場合不一樣

MPMoviePlayerViewController是在iOS3.2以後的平台上使用。MPMoviePlayerController在3.2之前使用,雖然在3.2之後也能使用,但是使用方法略有改變,建議3.2之後使用MPMoviePlayerViewController。

3.2之後,MPMoviePlayerController作為MPMoviePlayerViewController的一個屬性存在。

為了兼用以前版本 可以用如下方式使用(引用自一個網友的)

-(void) initAndPlay:(NSString *)videoURL{    if ([videoURL rangeOfString:@"http://"].location!=NSNotFound||[videoURL rangeOfString:@"https://"].location!=NSNotFound)     {        NSURL *URL = [[NSURL alloc] initWithString:videoURL];        if (URL) {            if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2)            {//3。2以後                MPMoviePlayerViewController* tmpMoviePlayViewController=[[MPMoviePlayerViewController alloc] initWithContentURL:URL];                if (tmpMoviePlayViewController)                {                    self._moviePlayViewController=tmpMoviePlayViewController;                                         [self presentMoviePlayerViewControllerAnimated:_moviePlayViewController];                    _moviePlayViewController.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;                    [_moviePlayViewController.moviePlayer play];                }                [tmpMoviePlayViewController release];                }            else if([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2)            {//3。2以前                MPMoviePlayerController* tmpMoviePlayController=[[MPMoviePlayerController alloc] initWithContentURL:URL];                if (tmpMoviePlayController)                                      {                    self._moviePlayerController=tmpMoviePlayController;                    [_moviePlayerController play];                }                [tmpMoviePlayController release];            }           [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidFinish) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];        }        [URL release];    }}


MPMoviePlayerViewController的使用:

MPMoviePlayerViewController的屬性moviePlayer提供了各種設定,展開、控制模式、迴圈模式、自動播放等等,最後一步就是別忘了播放。

  1. _moviePlayer.controlStyle = MPMovieControlStyleNone;    
  2. _moviePlayer.shouldAutoplay = YES;    
  3. _moviePlayer.repeatMode = MPMovieRepeatModeOne;  
  4. [_moviePlayer setFullscreen:YES animated:YES];    
  5. _moviePlayer.scalingMode = MPMovieScalingModeAspectFit;  
  6.  
  7. [_moviePlayer play];
     








聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.