MPMoviePlayerViewController播放视频横屏播放

实现播放视频的时候自动横屏必须重写MPMoviePlayerViewController,具体代码如下:

1.重写MPMoviePlayerViewController

Java代码   收藏代码
  1. //  
  2. //  DirectionMPMoviePlayerViewController.h  
  3. //  Direction  
  4. //  
  5. //  Created by apple on 12-4-10.  
  6. //  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.  
  7. //  
  8.   
  9. #import <MediaPlayer/MediaPlayer.h>  
  10.   
  11. @interface DirectionMPMoviePlayerViewController : MPMoviePlayerViewController  
  12.   
  13. @end  

 

Java代码   收藏代码
  1. //  
  2. //  DirectionMPMoviePlayerViewController.m  
  3. //  Direction  
  4. //  
  5. //  Created by apple on 12-4-10.  
  6. //  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.  
  7. //  
  8.   
  9. #import "DirectionMPMoviePlayerViewController.h"  
  10.   
  11. @implementation DirectionMPMoviePlayerViewController  
  12.   
  13. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation  
  14. {  
  15.     return UIDeviceOrientationIsLandscape(interfaceOrientation);  
  16. }  
  17.   
  18. @end  

 

2.初始化播放器,播放

Java代码   收藏代码
  1. - (void)viewDidLoad  
  2. {  
  3.     [super viewDidLoad];  
  4.     // Do any additional setup after loading the view from its nib.  
  5.     [self customTitleView];  
  6.     NSString *mystr = @"http://114.112.50.220:8080/res/20120331/2FFCE63A-C997-4D8C-4C4F-4127D78A958E.m3u8";  
  7.     NSURL *myURL = [[NSURL alloc] initWithString:mystr];  
  8.     [self playMovieAtURL:myURL];  
  9. }  
  10.   
  11. -(void)playMovieAtURL:(NSURL*)theURL  
  12. {  
  13.     playerView = [[DirectionMPMoviePlayerViewController alloc] initWithContentURL:theURL];  
  14.     playerView.view.frame = self.view.frame;//全屏播放(全屏播放不可缺)  
  15.     playerView.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;//全屏播放(全屏播放不可缺)  
  16.     [[NSNotificationCenter defaultCenter] addObserver:self  
  17.                                              selector:@selector(myMovieFinishedCallback:)  
  18.                                                  name:MPMoviePlayerPlaybackDidFinishNotification  
  19.                                                object:playerView];  
  20.     [playerView.moviePlayer play];  
  21.     [self presentMoviePlayerViewControllerAnimated:playerView];  
  22. }  
  23.   
  24. // When the movie is done, release the controller.  
  25. -(void)myMovieFinishedCallback:(NSNotification*)aNotification  
  26. {  
  27.     DirectionMPMoviePlayerViewController* theMovie = [aNotification object];  
  28.     [[NSNotificationCenter defaultCenter] removeObserver:self  
  29.                                                     name:MPMoviePlayerPlaybackDidFinishNotification  
  30.                                                   object:theMovie];  
  31.       
  32.     [theMovie release];  

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值