Sha*_*a G 2 iphone objective-c iphone-sdk-3.0
我在网址上有一个视频,点按一下我就要播放一个视频,为此我用UIWebView来播放这个视频,为此我使用了以下代码:
-(void)viewDidLoad
{
NSString *string = @"http://www.boxmusiq.com/ThiruvasakamVideo/VTS_01_2_converted.mp4";
youtubeview = [[YouTubeView alloc] initWithStringAsURL:string frame:CGRectMake(0, 0, 320, 480)];
NSLog(@"the url is: %@",string);
[self.view addSubview:youtubeview];
}
Run Code Online (Sandbox Code Playgroud)
在YouTubeView.m中,YouTubeView是UIWebView的子类;
- (YouTubeView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame;
{
if (self = [super init])
{
// Create webview with requested frame size
self = [[UIWebView alloc] initWithFrame:frame];
// HTML to embed YouTube video
NSString *youTubeVideoHTML = @"<html><head>\
<body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
// Populate HTML with the URL and requested frame size
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, urlString, frame.size.width, frame.size.height];
// Load the html into the webview
[self loadHTMLString:html baseURL:nil];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
只需尝试以下代码即可
MPMoviePlayerController *theMoviPlayer;
NSURL *urlString=[NSURL URLWithString:@"http://www.boxmusiq.com/ThiruvasakamVideo/VTS_01_2_converted.mp4"];
theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:urlString];
theMoviPlayer.scalingMode = MPMovieScalingModeFill;
theMoviPlayer.view.frame = CGRectMake(0, 60, 320, 350);
[self.view addSubview:theMoviPlayer.view];
[self.theMoviPlayer play];
Run Code Online (Sandbox Code Playgroud)
注意:添加Mediaplayer FrameKit并将其导入您的班级