利用MPMoviePlayerViewController实现简单的mp4播放_C/C++_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > C/C++ > 利用MPMoviePlayerViewController实现简单的mp4播放

利用MPMoviePlayerViewController实现简单的mp4播放

 2012/6/11 0:14:21  re_reference  程序员俱乐部  我要评论(0)
  • 摘要:1、要使用MPMoviePlayerViewController首先要加入MediaPlayer.framework.2、加入如下代码://ImplementviewDidLoadtodoadditionalsetupafterloadingtheview,typicallyfromanib.-(void)viewDidLoad{[superviewDidLoad];NSString*url=[[NSBundlemainBundle]pathForResource:@"TaylorSwift
  • 标签:实现 view 利用
1、要使用MPMoviePlayerViewController首先要加入MediaPlayer.framework.
2、加入如下代码:
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	NSString *url = [[NSBundle mainBundle] pathForResource:@"TaylorSwift-LoveStory" ofType:@"mp4"];
	
    MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:)
												 name:MPMoviePlayerPlaybackDidFinishNotification
											   object:[playerViewController moviePlayer]];
	//-- add to view---
    [self.view addSubview:playerViewController.view];
	
    //---play movie---
    MPMoviePlayerController *player = [playerViewController moviePlayer];
    [player play];
	
}

- (void) movieFinishedCallback:(NSNotification*) aNotification {
	MPMoviePlayerController *player = [aNotification object];
	[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
	[player stop];
	[self.view removeFromSuperView];
	[player autorelease];
}

3、支持横屏修改shouldAutorotateToInterfaceOrientation:interfaceOrientation方法使其返回YES。
发表评论
用户名: 匿名