(电影播放器)MPMoviePlayerController

示例名:MoviePlayer(电影播放器)
功能:播放本地或网络视频

框架:MediaPlayer.framework
源码解释:

1 -initAndPlayMovie创建一个电影播放控制器,指定播放内容的URL,并开始播放
2 -applicationDidFinishLaunching从主程序束中得到Movie.m4v的路径,并调用-initAndPlayMovie开始播放

核心源码:

 1 -(void)initAndPlayMovie:(NSURL *)movieURL
2 {
3 // Initialize a movie player object with the specified URL
4 MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
5
6 // save the movie player object
7 self.moviePlayer = mp;
8 [mp release];
9
10 // Play the movie!
11 [self.moviePlayer play];
12 }

 

 1 - (void)applicationDidFinishLaunching:(UIApplication *)application {    
2 // Override point for customization after application launch
3 NSURL *movieURL;
4
5 NSBundle *bundle = [NSBundle mainBundle];
6 NSString *moviePath = [bundle pathForResource:@"Movie" ofType:@"m4v"];
7 movieURL = [NSURL fileURLWithPath:moviePath];
8 [self initAndPlayMovie:movieURL];
9 [window makeKeyAndVisible];
10 }



网上有,拿来改改。挺好用的。比较简单。分享。
- (void) Playback : (id) sender
{
//指定播放的名字和地址
NSString *path = [[NSBundle mainBundle] pathForResource:@"ss" ofType:@"mov"];
// m4a格式也是允许的。
MPMoviePlayerController* theMovie=[[[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]] retain];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
[theMovie play];
}

- (void) setUpForPlay: (NSNotification *) notification
{
UIButton *button = (UIButton *)[self.view viewWithTag:BUTTON_TAG];
// Prepare button for re-starting
[button setTitle:@"Start" forState:UIControlStateNormal];
[button removeTarget:self action:@selector(stopPlayback:) forControlEvents:UIControlEventTouchUpInside];
[button addTarget:self action:@selector(startPlayback:) forControlEvents: UIControlEventTouchUpInside];
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值