Skip to content

Instantly share code, notes, and snippets.

@cherenkov
Created December 11, 2010 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cherenkov/737414 to your computer and use it in GitHub Desktop.
Save cherenkov/737414 to your computer and use it in GitHub Desktop.
空のプロジェクトを作ってこのファイルだけ編集。iPadプログラミングで、Youtubeを画面に表示し、UIWebViewで再生できますが、 Youtubeの動画を途中から再生することは可能でしょうか? コード例もあるとポイント高めです.. - 人力検索はてな http://q.hatena.ne.jp/1291294956
//
// iPad_youtubeViewController.m
// iPad-youtube
//
// Created by cherenkov on 10/12/02.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "iPad_youtubeViewController.h"
@implementation iPad_youtubeViewController
// Implement loadView to create a view hierarchy programmatically.
- (void)loadView {
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
webView = [[UIWebView alloc] initWithFrame:[self.view frame]];
[webView setDelegate:self];
[self.view addSubview: webView];
}
// Implement viewDidLoad to do additional setup after loading the view.
- (void)viewDidLoad {
[super viewDidLoad];
[webView loadRequest:[NSURLRequest requestWithURL:
[NSURL URLWithString:@"http://www.youtube.com/watch?v=fWrjUti71ps"]]];
}
//
//http://www.youtube.com/watch?v=xTuXZ9u_EcA
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIDeviceOrientationLandscapeRight);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)dealloc {
[super dealloc];
[webView release];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//youtubeを途中から再生したい。
//シミュレータでは画面が動かないがとりあえずスキップできた。
//再生してからcurrentTimeを変えるとスキップできるようだが、タイミング(イベント)がよくわからなかったのでsetTimeoutで代用。
[webView stringByEvaluatingJavaScriptFromString:@"var v=document.querySelector('video'); v.play(); setTimeout(function(){ v.currentTime = 60},5000);"];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment