您的位置:首页 > 其它

MediaPlayer/MediaPlayer 视频播放

2013-11-02 15:04 267 查看
今天做了个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;

@property (nonatomic,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];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: