Ios 在webview中播放视频时出现问题
我在服务器上有视频,我正在使用webview播放视频,但每次我单击“完成”(在webview中)时,它都会上升,但第二次运行正常。请建议我如何解决此问题Ios 在webview中播放视频时出现问题,ios,objective-c,cocoa,webview,Ios,Objective C,Cocoa,Webview,我在服务器上有视频,我正在使用webview播放视频,但每次我单击“完成”(在webview中)时,它都会上升,但第二次运行正常。请建议我如何解决此问题 -(void)showPopViewWithUrl:(NSString*)url { self.navigationController.navigationBar.hidden = YES; float diff = [UIScreen mainScreen].bounds.size.height - self.view.fr
-(void)showPopViewWithUrl:(NSString*)url {
self.navigationController.navigationBar.hidden = YES;
float diff = [UIScreen mainScreen].bounds.size.height - self.view.frame.size.height;
UIView* popView = [[UIView alloc] init];
popView.frame = CGRectMake(0, -diff, self.view.frame.size.width, self.view.frame.size.height+diff);
[popView setBackgroundColor:[UIColor yellowColor]];
UIWebView* webview = [[UIWebView alloc] init];
webview.backgroundColor = [UIColor clearColor];
[webview setFrame:CGRectMake(0, 0, 300, 250)];
UIButton* crossBtn = [UIButton buttonWithType:UIButtonTypeCustom];
crossBtn.backgroundColor = [UIColor clearColor];
[crossBtn addTarget:self action:@selector(crossBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[crossBtn setImage:[UIImage imageNamed:@"close_pop.png"] forState:UIControlStateNormal];
[crossBtn setFrame:CGRectMake(popView.frame.size.width-30, popView.frame.size.height-40, 30, 30)];
[popView addSubview:webview];
[webview addSubview:crossBtn];
[self.view addSubview:popView];
[self playVideo:url webview:webview];
}
- (void)playVideo:(NSString *)urlString webview:(UIWebView*)videoView {
NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
<script>\
function load(){document.getElementById(\"yt\").play();}\
</script>\
</head><body onload=\"load()\"style=\"margin:0\">\
<video id=\"yt\" src=\"%@\" \
width=\"%0.0f\" height=\"%0.0f\" autoplay controls></video>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString,videoView.frame.size.width, videoView.frame.size.height];
[videoView loadHTMLString:html baseURL:nil];
// [self.view addSubview:videoView];
NSLog(@"%@",html);
}
-(void)showPopViewWithUrl:(NSString*)url{
self.navigationController.navigationBar.hidden=是;
float diff=[UIScreen mainScreen].bounds.size.height-self.view.frame.size.height;
UIView*popView=[[UIView alloc]init];
popView.frame=CGRectMake(0,-diff,self.view.frame.size.width,self.view.frame.size.height+diff);
[popView setBackgroundColor:[UIColor yellowColor];
UIWebView*webview=[[UIWebView alloc]init];
webview.backgroundColor=[UIColor clearColor];
[webview设置框架:CGRectMake(0,0,300,250)];
UIButton*Crosstn=[UIButton Button类型:UIButtonTypeCustom];
Crosstn.backgroundColor=[UIColor clearColor];
[crosstn addTarget:self action:@selector(crosstnclicked:)forControlEvents:UIControlEventTouchUpInside];
[crosstn setImage:[UIImage ImageName:@“close_pop.png”]用于状态:UIControlStateNormal];
[crosstn setFrame:CGRectMake(popView.frame.size.width-30,popView.frame.size.height-40,30,30)];
[popView addSubview:webview];
[webview添加子视图:crosstn];
[self.view addSubview:popView];
[自行播放视频:url网络视图:网络视图];
}
-(void)播放视频:(NSString*)urlString网络视图:(UIWebView*)视频视图{
NSString*embedHTML=@”\
\
\
身体{\
背景色:透明\
颜色:白色\
}\
\
\
函数load(){document.getElementById(\“yt\”).play();}\
\
\
\
";
NSString*html=[NSString stringWithFormat:embedHTML、urlString、videoView.frame.size.width、videoView.frame.size.height];
[videoView loadHTMLString:html baseURL:nil];
//[self.view addSubview:videoView];
NSLog(@“%@”,html);
}
-(void)showPopViewWithUrl:(NSString*)url{
self.navigationController.navigationBar.hidden=是;
float diff=[UIScreen mainScreen].bounds.size.height-self.view.frame.size.height;
UIView*popView=[[UIView alloc]init];
popView.frame=CGRectMake(0,-diff,self.view.frame.size.width,self.view.frame.size.height+diff);
[popView setBackgroundColor:[UIColor yellowColor]
UIWebView* webview = [[UIWebView alloc] init];
webview.backgroundColor = [UIColor clearColor];
[webview setFrame:CGRectMake(0, 0, 300, 250)];
UIButton* crossBtn = [UIButton buttonWithType:UIButtonTypeCustom];
crossBtn.backgroundColor = [UIColor clearColor];
[crossBtn addTarget:self action:@selector(crossBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[crossBtn setImage:[UIImage imageNamed:@"close_pop.png"] forState:UIControlStateNormal];
[crossBtn setFrame:CGRectMake(popView.frame.size.width-30, popView.frame.size.height-40, 30, 30)];
[popView addSubview:webview];
[webview addSubview:crossBtn];
[self.view addSubview:popView];
NSString *html=[self playVideoFromUrl:url]
[webview loadHTMLString:html baseURL:nil];
}
-(NSString*)播放视频源URL:(NSString*)strUrl{
浮动宽度=200.0f;
浮子高度=200.0f;
NSMutableString*html=[[NSMutableString alloc]initWithCapacity:1];
[html附录字符串:@”“;
[html附录字符串:@”“;
[html appendString:@“body{”];
[html appendString:@“背景色:透明;”;
[html附录字符串:@“颜色:白色;”;
[html appendString:@“}”];
[html附录字符串:@”“;
[html附录字符串:@”“;
[html格式:@“”,宽度,高度];
[html附录字符串:@”“;
返回html;
}
float width = 200.0f;
float height = 200.0f;
NSMutableString *html = [[NSMutableString alloc] initWithCapacity:1];
[html appendString:@"<html><head>"];
[html appendString:@"<style type=\"text/css\">"];
[html appendString:@"body {"];
[html appendString:@"background-color: transparent;"];
[html appendString:@"color: white;"];
[html appendString:@"}"];
[html appendString:@"</style>"];
[html appendString:@"</head><body style=\"margin:0\">"];
[html appendFormat:@"<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\"", strUrl];
[html appendFormat:@"width=\"%0.0f\" height=\"%0.0f\"></embed>", width, height];
[html appendString:@"</body></html>"];
return html;