2

奇怪的问题,因为据我所知,实施中没有任何改变。我有一个嵌入式 YouTube 剪辑播放器(下面的代码),它可以很好地播放我想要的视频。但是,如果我旋转屏幕,视频会保持纵向模式——它过去工作得很好。有什么想法吗?

- (void)autoplay:(NSString *)youtubeID sender:(UIView *)sender
{

    NSLog(@"%@", [NSString stringWithFormat:@"Youtube ID: %@", youtubeID]);

    // Template for youtube video embedded play
    NSString * htmlTemplate = @"\
    <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\
    <html><head>\
    <META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\
    <style>body{background:#000;margin:0px}</style>\
    </head>\
    <body>\
    <script type=\"text/javascript\" src=\"http://www.youtube.com/iframe_api\"></script>\
    <script type=\"text/javascript\">\
    var intervalTimer;\
    var ytplayer;\
    var doesPlay = 0;\
    function onYouTubeIframeAPIReady() {\
    ytplayer = new YT.Player('playerId', {\
    playerVars: {'controls': 0},\
    events: {\
    'onReady': onPlayerReady,\
    'onStateChange': onPlayerStateChange,\
    'onError' : onPlayerError\
    }\
    });\
    }\
    function onPlayerReady(event) {\
    event.target.playVideo();\
    }\
    function onPlayerError(event) {\
    window.location.href = \"yidio://failure\";\
    }\
    function onPlayerStateChange(event) {\
    if (event.data == YT.PlayerState.PLAYING)\
    {\
    doesPlay = 1;\
    }\
    else if (event.data == YT.PlayerState.PAUSED)\
    {\
    doesPlay = 0;\
    }\
    else if (event.data == YT.PlayerState.ENDED)\
    {\
    clearInterval(intervalTimer);\
    event.target.destroy();\
    }\
    }\
    intervalTimer = window.setInterval('passPlayedTime()',1000);\
    function passPlayedTime(){\
    if (doesPlay)\
    {\
    window.location.href = \"playedpercentage://\" + ytplayer.getCurrentTime() / ytplayer.getDuration();\
    }\
    }\
    </script>\
    <iframe id=\"playerId\" type=\"text/html\" width=\"160\" height=\"90\"\
    src=\"http://www.youtube.com/embed/%@?vq=hd720&version=3&enablejsapi=1&rel=0&controls=0\"\
    frameborder=\"0\">\
    </body>\
    </html>";

    NSString * htmlString = [NSString stringWithFormat:htmlTemplate, youtubeID];
    UIWebView * embedded = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
    [embedded setDelegate:self];
    [embedded setMediaPlaybackRequiresUserAction:FALSE];
    [embedded setHidden:TRUE];
    [embedded setTag:EMBEDDED_VIEW_TAG];        

    // Add the embedded webview
    [sender addSubview:embedded];
    [embedded loadHTMLString:htmlString baseURL:nil];

        NSError *error = nil;
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
        [[AVAudioSession sharedInstance] setActive:YES error:&error];
    }
4

0 回答 0