2

UIWebView で YouTube API を使用しています。

UIWebView にロードする HTML5 プレーヤーで NSString を作成しました。すべてが iPhone 5 と iPad で完璧に動作します。

しかし、iPhone 4 を使用してアプリをテストすると、プレーヤーは常にバッファリング状態を返します。再生ボタンを明示的に押した場合にのみ、プレーヤーは再生を開始し、バッファリングのために再度停止することはありません。ビデオはバッファリングされていますが、プレーヤーはまだこの状態になっているようです。

誰もこの問題を認識していますか? 何か案が?

事前にどうもありがとうございました!!

4

1 に答える 1

1

LBYouTubePlayerViewController.m ファイル内

古いメソッドの次のメソッドを置き換えます....

それからテスト...

      -(NSURL*)_extractYouTubeURLFromFile:(NSString *)html error:(NSError *__autoreleasing *)error {
NSString *JSONStart = nil;
// NSString *JSONStartFull = @"ls.setItem('PIGGYBACK_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(@"dataWithJSONObject:options: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;
}
于 2013-07-24T13:02:49.917 に答える