0
我正在嘗試在我的應用中整合一個YouTube視頻。但是當視頻結束時,我希望它恢復到調用viewController。我幾乎成功地實現了這一點,但以我的方式,用戶必須先按完成按鈕,然後才能返回到原始ViewController。在應用程序中查看YouTube視頻,並返回到先前的ViewControlloer
這是我使用的代碼,請幫忙,我更喜歡參考完整的代碼或代碼示例。
YouTubeView.h:
#import <UIKit/UIKit.h>
@interface YouTubeView : UIWebView
{
}
- (YouTubeView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame mimeSubType:(NSString *)mimeType;
@end
YouTubeView.m:
#import "YouTubeView.h"
@interface YouTubeView()
@end
@implementation YouTubeView
- (YouTubeView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame mimeSubType:(NSString *)mimeType
{
NSString *strMimeType;
if([mimeType length]>0)
{
strMimeType = mimeType;
}
else
{
strMimeType [email protected]"x-shockwave-flash"; //@"x-shockwave-mp4";
}
if (self = [super init])
{
// Create webview with requested frame size
self = [[UIWebView alloc] initWithFrame:frame];
// HTML to embed YouTube video
NSString *videoHTML = [NSString stringWithFormat:@"\
<html>\
<head>\
<style type=\"text/css\">\
iframe {position:absolute; top:50%%; margin-top:-130px;}\
body {background-color:#000; margin:0;}\
</style>\
</head>\
<body>\
<iframe width=\"100%%\" height=\"240px\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe>\
</body>\
</html>", urlString];
[self loadHTMLString:videoHTML baseURL:nil];
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
@end
而且指向*對主視圖控制器按鈕: - (IBAction爲)runTestVideo:(ID)發送{
NSString *strNormalVdoURL = [NSString stringWithFormat:@"http://www.youtube.com/embed/TgLqH9n57B0"];
YouTubeView *videoVw = [[YouTubeView alloc] initWithStringAsURL:[NSString stringWithFormat:@"%@",strNormalVdoURL] frame:CGRectMake(0,0,315,420) mimeSubType:@"x-shockwave-flash"];
[self.view addSubview:videoVw];
[videoVw release];
videoVw = nil;
}
請幫忙。
你能做些什麼讓用戶不必按下完成按鈕嗎?電影完成時的含義就像完成按鈕。 – Idan 2012-07-19 09:19:35