iphone - Javascript Youtube API : buffering for ever - UIWebView iOS
<p><p>我在 UIWebView 中使用 YouTube API。</p>
<p>我已经用我在 UIWebView 中加载的 HTML5 播放器创建了一个 NSString。一切都在 iPhone 5 和 iPad 上完美运行。 </p>
<p>但是,如果我使用 iPhone 4 测试应用程序,播放器会一直返回缓冲状态。只有当我明确按下播放按钮时,播放器才会开始播放,而不会再次停止缓冲。好像虽然视频已经缓冲了,但是播放器还是给我这个状态。</p>
<p>有人知道这个问题吗?有什么想法吗?</p>
<p>非常感谢您!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在 LBYouTubePlayerViewController.m 文件中</p>
<p>在旧方法上替换以下方法....</p>
<p>然后测试...</p>
<pre><code> -(NSURL*)_extractYouTubeURLFromFile:(NSString *)html error:(NSError *__autoreleasing *)error {
NSString *JSONStart = nil;
// NSString *JSONStartFull = @"ls.setItem('PIGGYBACK_DATA', \")]}'";
NSString *JSONStartFull = @"bootstrap_data = \")]}'";
NSString *JSONStartShrunk = ;
if (.location != NSNotFound)
JSONStart = JSONStartFull;
else if (.location != NSNotFound)
JSONStart = JSONStartShrunk;
if (JSONStart != nil) {
NSScanner* scanner = ;
;
;
NSString *JSON = nil;
;
JSON = ; // Add closing bracket } to get vallid JSON again
// ;
JSON = ;
NSError* decodingError = nil;
NSDictionary* JSONCode = nil;
// First try to invoke NSJSONSerialization (Thanks Mattt Thompson)
id NSJSONSerializationClass = NSClassFromString(@"NSJSONSerialization");
SEL NSJSONSerializationSelector = NSSelectorFromString(@"dataWithJSONObject:options:error:");
if (NSJSONSerializationClass && ) {
JSONCode = options:NSJSONReadingAllowFragments error:&decodingError];
}
else {
JSONCode = ;
}
if (decodingError) {
// Failed
*error = decodingError;
}
else {
// Success
NSDictionary *dict = ;
NSDictionary *dictTemp = ;
NSArray* videos = ;
NSString* streamURL = nil;
if (videos.count) {
NSString* streamURLKey = @"url";
if (self.quality == LBYouTubePlayerQualityLarge) {
streamURL = [ objectForKey:streamURLKey];
}
else if (self.quality == LBYouTubePlayerQualityMedium) {
unsigned int index = MAX(0, videos.count-2);
streamURL = [ objectForKey:streamURLKey];
}
else {
streamURL = [ objectForKey:streamURLKey];
}
}
if (streamURL) {
return ;
}
else {
*error = ];
}
}
}
else {
*error = ];
}
return nil;
}
</code></pre></p>
<p style="font-size: 20px;">关于iphone - Javascript Youtube API : buffering for ever - UIWebView iOS,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/17834381/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/17834381/
</a>
</p>
页:
[1]