ios7 UIWebView Youtube视频 [英] ios7 UIWebView Youtube Video

查看:110
本文介绍了ios7 UIWebView Youtube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIWebView子类,我用它来播放youtube和本地视频。在iOS6下完美运行。升级到iOS7我遇到了一个问题,我真的不知道从哪里开始。虽然子类似乎仍能在iOS7模拟器上播放youtube和本地视频,但当我在设备上播放youtube时,我会记录以下消息:

I have a UIWebView subclass that I used to play both youtube and local videos. Worked perfectly under iOS6. In upgrading to iOS7 I've encountered a problem I don't really know where to start on. While the subclass seems to still work fine playing youtube and local video on the iOS7 simulator, when I play a youtube on the device I get the following messages logged:

Sep 26 10:17:27 JRR-IPad SVOx[558] <Error>: CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

Sep 26 10:17:27 JRR-IPad SVOx[558] <Error>: CGContextSetBlendMode: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

Sep 26 10:17:27 JRR-IPad SVOx[558] <Error>: CGContextSetAlpha: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

Sep 26 10:17:27 JRR-IPad SVOx[558] <Error>: CGContextTranslateCTM: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

Sep 26 10:17:27 JRR-IPad SVOx[558] <Error>: CGContextScaleCTM: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update. 

Sep 26 10:17:27 JRR-IPad SVOx[558] <Error>: CGContextGetCTM: invalid context 0x0.
This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

Sep 26 10:17:27 JRR-IPad SVOx[558] <Error>: CGContextDrawImage: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

Sep 26 10:17:27 JRR-IPad SVOx[558] <Error>: CGContextGetCTM: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

===

这只发生在设备上,而不是在模拟器上,并没有在iOS6下发生。我在这里看到一些帖子谈论了关于测试版的各种类的类似问题,但我没有看到关于iOS7发布版本的评论。

This happens only on the device, not on the simulator, and did not occur under iOS6. I've seen some posts here talking about similar problems with various classes on the beta, but I've not seen comments about the iOS7 release version.

我不使用我的代码中的任何这些方法,所以这些消息来自库。

I do not use any of these methods in my code, so these messages are originating within libraries.

任何人? TIA。

推荐答案

使用此功能,您可以在视图中运行YouTube视频..

Using this you can run youtube video in your view..

UIWebView * videoView = [[UIWebView alloc] initWithFrame:self.view.bounds];

UIWebView *videoView = [[UIWebView alloc] initWithFrame:self.view.bounds];

    NSString *strparse = [NSString stringWithFormat:@"http://www.youtube.com/watch?v=%@",youtubeVideoId];
    NSRange rng = [strparse rangeOfString: @"watch?v="];
    strparse = [strparse substringFromIndex:rng.location];
    rng = [strparse rangeOfString:@"&feature="];


    if (rng.length >0)
    {
        strparse = [strparse substringToIndex:rng.location];
    }
    strparse = [strparse stringByReplacingOccurrencesOfString:@"watch?v=" withString:@""];
    //http://www.youtube.com/embed/FJkiwbqlSy0
    NSString *youTubeVideoHTML =[NSString stringWithFormat:@"<!DOCTYPE html><html><head><style>body{margin:0px 0px 0px 0px; background:#1111}</style></head> <body> <div id=\"player\"></div> <script> var tag = document.createElement('script'); tag.src = \"http://www.youtube.com/player_api\"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player', { width:'%0.0f', height:'%0.0f', videoId:'%@', events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange } });} function onPlayerReady(event) { event.target.playVideo(); } function onPlayerStateChange(event) {if(event.data === 0) {   event.target.destroy(); }}  </script> </body> </html>",0.0, 0.0,youtubeVideoId];


    videoView.scalesPageToFit=NO;
    videoView.mediaPlaybackRequiresUserAction=NO;
    videoView.backgroundColor = [UIColor clearColor];
    videoView.opaque= NO;


    [SharedObj showLoadingWithText:@""];

    [videoView loadHTMLString:youTubeVideoHTML baseURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.youtube.com/watch?v=%@",youtubeVideoId]]];


    [self.view addSubview:videoView];

这篇关于ios7 UIWebView Youtube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆