摘自:http://blog.csdn.net/sjzsp/article/details/6319927
Iphone中已经自定义好了视频播放类MPMoviePlayerController,我们只需调用既可,下面详细介绍一下调用手机播放器的例子:
首先创建一个视图工程PlayMoveViewDemo,然后声明其类型:
#import <UIKit/UIKit.h>
@interface PlayMoveViewDemoViewController : UIViewController {
IBOutlet UIButton *button;
}
@property (nonatomic,retain)UIButton *button;
-(IBAction) pressedbutton:(id)sender;
@end
然后利用Interface builder创建一个按钮,并且把相应的声明和按钮相链接。
接下来需要引入相应的播放器实现,引入方法:
双击红色边框:
添加相应的类:
点击完成即可。
添加播放代码:
#import “PlayMoveViewDemoViewController.h”
#import “MediaPlayer/MediaPlayer.h”
@implementation PlayMoveViewDemoViewController
@synthesize button;
-(IBAction) pressedbutton:(id)sender
{
NSLog(@”按到我了“);
[self playVideo];
}
- (void)playVideo
{
MPMoviePlayerController *moviePlayer;
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURLURLWithString:@"http://dev.mopietek.net:8080/mp4/320480flv.3gp"]];
moviePlayer.movieControlMode = MPMovieControlModeDefault;
[moviePlayer play];
//[path release];
NSLog(@”play~”);
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn’t have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren’t in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[button release];
[super dealloc];
}
@end
编辑运行既可:
点击play:
播放器就完成了。