iphone视频播放问题

官方例子参见 http://developer.apple.com/libra ... oc/uid/DTS40007798.
注意: SDK4.0之前, 直接用MPMoviePlayerController,然后传个视频路径就可以看到播放界面了. 
而SDK4.0之后, 如果你还是用MPMoviePlayerController, 需要自己在代码里把MPMoviePlayerController的view加到你的view上,否则虽然视频在播放,但你是看不到界面的. 当然, 如果你还是想直接就看到播放界面, 可以用新的MPMoviePlayerViewController这个controller(它就相当于4.0之前的 MPMoviePlayerController)
上面是摘自论坛:
新的播放方式,是竖屏,要横屏播放还要自己代码实现。为什么新版本不是更方便,反而 给程序员带来麻烦,很费解!
但我遇到一个奇怪的问题,我的iso4.1,找不到这个类MPMoviePlayerViewController,不晓得为什么?
我直接输入实现这个视频播放,却是可以正常运行!我的xcode 3.2.4版本
下面是我实现的视频播放代码,其中写了横屏播放代码,当点击完成时,返回到竖屏模式
代码如下:

-(IBAction)playMovie

{

    NSBundle *bundle = [NSBundle mainBundle];

    NSString *moviePath = [bundle pathForResource:@"Movie" ofType:@"mov"];

    NSURL *movieURL = [NSURL fileURLWithPath:moviePath];

    moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];

    //定义视频横屏播放

    [[moviePlayerViewController view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];

     [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

   [[NSNotificationCenter defaultCenter] addObserver:self 

selector:@selector(moviePlayBackDidFinish:) 

 name:@"MPMoviePlayerPlaybackDidFinishNotification"

   object:nil];

    //在当前view上添加视频的视图

    [[[UIApplication sharedApplication] keyWindow] addSubview:moviePlayerViewController.view];

}

//点击完成返回首页

- (void)moviePlayBackDidFinish:(NSNotification*)notification{

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];

    [moviePlayerViewController.moviePlayer stop];

    [moviePlayerViewController.view removeFromSuperview];

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值