MediaPlayer/MediaPlayer 视频播放

今天做了个MediaPlayer/MediaPlayer 小DEMO,具体要求是通过XML传过来的变量点击按钮一一对应播放相应的MP4.


1、添加MediaPlayer.framework


2、H文件


#import <UIKit/UIKit.h>


@interface news_show : UIViewController

{

IBOutlet UIButton *button;

}

@property (nonatomic,retain)UIButton *button;

-(IBAction) pressedbutton:(id)sender;

ottom:0px; font-size:11px; font-family:Menlo; color:rgb(187,strong) Nsstring *URL;//视频地址,只能用NsstRING不能用UILABEL



3、M文件

#import "news_show.h"

#import "MediaPlayer/MediaPlayer.h"

@implementation news_show{

Nsstring *telNumber;

}

@synthesize imageView;

@synthesize dealTitle;

@synthesize deal;

@synthesize dealDesc;

@synthesize button;

@synthesize URL;//视频地址



。。。。。。。。。。。。。。。。。


URL = [deal valueForKey:@"link"];

}

-(IBAction) pressedbutton:(id)sender

{

NSLog(@"按到我了");

[self playVideo];

}

- (void)playVideo

{

//NSURL *movieUrl = [NSURL URLWithString:@"http://www.apple.com/ios/xzqcf/video/01.mp4"];//这是绝对路径

NSURL *movieUrl = [NSURL URLWithString:URL];//这个是由XML提供的变量,不同介面有不同的相应连接

MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:movieUrl];

[self presentMoviePlayerViewControllerAnimated:player];

//[path release];

NSLog(@"play~");

}


- (void)dealloc {

[button release];

[super dealloc];

}

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念