• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iphone - Javascript Youtube API : buffering for ever - UIWebView iOS

[复制链接]
菜鸟教程小白 发表于 2022-12-12 12:49:09 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我在 UIWebView 中使用 YouTube API。

我已经用我在 UIWebView 中加载的 HTML5 播放器创建了一个 NSString。一切都在 iPhone 5 和 iPad 上完美运行。

但是,如果我使用 iPhone 4 测试应用程序,播放器会一直返回缓冲状态。只有当我明确按下播放按钮时,播放器才会开始播放,而不会再次停止缓冲。好像虽然视频已经缓冲了,但是播放器还是给我这个状态。

有人知道这个问题吗?有什么想法吗?

非常感谢您!



Best Answer-推荐答案


在 LBYouTubePlayerViewController.m 文件中

在旧方法上替换以下方法....

然后测试...

      -(NSURL*)_extractYouTubeURLFromFileNSString *)html errorNSError *__autoreleasing *)error {
NSString *JSONStart = nil;
// NSString *JSONStartFull = @"ls.setItem('IGGYBACK_DATA', \")]}'";
NSString *JSONStartFull = @"bootstrap_data = \")]}'";
NSString *JSONStartShrunk = [JSONStartFull stringByReplacingOccurrencesOfString" " withString""];
if ([html rangeOfString:JSONStartFull].location != NSNotFound)
    JSONStart = JSONStartFull;
else if ([html rangeOfString:JSONStartShrunk].location != NSNotFound)
    JSONStart = JSONStartShrunk;

if (JSONStart != nil) {
    NSScanner* scanner = [NSScanner scannerWithString:html];
    [scanner scanUpToString:JSONStart intoString:nil];
    [scanner scanString:JSONStart intoString:nil];

    NSString *JSON = nil;
    [scanner scanUpToString"}\";" intoString:&JSON];
    JSON = [NSString stringWithFormat"%@}",JSON]; // Add closing bracket } to get vallid JSON again
    // [scanner scanUpToString"\");" intoString:&JSON];
    JSON = [self _unescapeString:JSON];
    NSError* decodingError = nil;
    NSDictionary* JSONCode = nil;

    // First try to invoke NSJSONSerialization (Thanks Mattt Thompson)

    id NSJSONSerializationClass = NSClassFromString(@"NSJSONSerialization");
    SEL NSJSONSerializationSelector = NSSelectorFromString(@"dataWithJSONObjectptions:error:");
    if (NSJSONSerializationClass && [NSJSONSerializationClass respondsToSelector:NSJSONSerializationSelector]) {
        JSONCode = [NSJSONSerialization JSONObjectWithData:[JSON dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:&decodingError];
    }
    else {
        JSONCode = [JSON objectFromJSONStringWithParseOptions:JKParseOptionNone error:&decodingError];
    }

    if (decodingError) {
        // Failed

        *error = decodingError;
    }
    else {
        // Success

        NSDictionary *dict = [JSONCode objectForKey"content"];
        NSDictionary *dictTemp = [dict objectForKey"video"];
        NSArray* videos = [dictTemp objectForKey"fmt_stream_map"];

        NSString* streamURL = nil;
        if (videos.count) {
            NSString* streamURLKey = @"url";

            if (self.quality == LBYouTubePlayerQualityLarge) {
                streamURL = [[videos objectAtIndex:0] objectForKey:streamURLKey];
            }
            else if (self.quality == LBYouTubePlayerQualityMedium) {
                unsigned int index = MAX(0, videos.count-2);
                streamURL = [[videos objectAtIndex:index] objectForKey:streamURLKey];
            }
            else {
                streamURL = [[videos lastObject] objectForKey:streamURLKey];
            }
        }

        if (streamURL) {
            return [NSURL URLWithString:streamURL];
        }
        else {
            *error = [NSError errorWithDomain:kLBYouTubePlayerControllerErrorDomain code:2 userInfo:[NSDictionary dictionaryWithObject"Couldn't find the stream URL." forKey:NSLocalizedDescriptionKey]];
        }
    }
}
else {
    *error = [NSError errorWithDomain:kLBYouTubePlayerControllerErrorDomain code:3 userInfo:[NSDictionary dictionaryWithObject"The JSON data could not be found." forKey:NSLocalizedDescriptionKey]];
}

return nil;
}

关于iphone - Javascript Youtube API : buffering for ever - UIWebView iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17834381/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap