我正在为iPhone开发一款应用,我正在UIwebView
上运行Youtube视频。
在那里,我想要检索有关视频的所有信息(视频开始时以及完成视频所花费的时间)。我试图每2秒获取一次这个信息。
我无法获得这样的通知。我也试过用JavaScript做这件事,但我在某处读到它需要Flash Player并且iPhone不支持它。所以JavaScript不是一个选择。
有谁能建议我怎样才能从这里前进?感谢。
我的代码:
//
// YouTubeEmbedViewController.m
// YouTubeEmbed
//
// Created by Movik Networks on 11/04/12.
// Copyright 2012 __MyCompanyName__. All rights reserved.
//
#import "YouTubeEmbedViewController.h"
@implementation YouTubeEmbedViewController
@synthesize thumbnailView;
- (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.
}
#pragma mark - View lifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
// webView is a UIWebView, either initialized programmatically or loaded as part of a xib.
NSString *htmlString = @"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 300\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"300\" height=\"300\"><param name=\"movie\" value=\"http://www.youtube.com/watch?v=oSOooSv1RH0\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/watch?v=oSOooSv1RH0\"type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"300\" height=\"300\"></embed></object></div></body></html>";
[thumbnailView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.google.com"]];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
答案 0 :(得分:0)
您可以使用Youtube API with the client library
然后您可以播放MPMoviePlayerViewController
中的文件并使用它的委托功能。