视频播放笔记

本文详细介绍了MPMoviePlayerViewController和MPMoviePlayerController的区别及在不同iOS版本中的使用方法,并提供了实例代码进行演示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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];  



















                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值