Question

I've had an app out for a while which uses UIWebViews to display YouTube videos on certain views. Today, without any changes to the code, my users started complaining about the YouTube embeds not working: the embed with the still frame and play button displays fine, but upon clicking the play button the embed screen just goes black and nothing loads, no sound or video.

Here is my function for generating an embed code to put into the UIWebView from a YouTube ID:

+ (NSString*)codeForYouTubeID:(NSString*)videoID width:(NSUInteger)width height:(NSUInteger)height
{
    static NSString *fmt =
    @"<iframe width='%d' height='%d' src='http://www.youtube.com/embed/%@?showinfo=0&modestbranding=1&rel=0&showsearch=0' frameborder='0' scrolling='0' allowfullscreen></iframe>";

    return [NSString stringWithFormat:fmt, width, height, videoID];
}

Putting the resulting code into JSFiddle the embed displays and plays fine. I have also used the following alternative format string with the same results (from a StackOverflow answer here):

static NSString *fmt =
@"<object>\
    <param name=\"movie\" value=\"http://www.youtube.com/v/%@\"></param>\
    <embed src=\"http://www.youtube.com/v/%@\" type=\"application/x-shockwave-flash\"></embed>\
</object>";

This has the same results, but with an awkwardly auto-sized embed. The behaviour is the same: the user can click the play button, then the embed frame just goes black and nothing else happens. For me, this is happening on my test phone (iPhone 4, iOS 7) and on the simulator (both iOS6 and 7). This didn't happen before today, and no code has been changed. Has anyone else experienced this recently?

Was it helpful?

Solution

Someone found a workaround here, to an extent. Not sure how to mark an answer like that, but I'll copy it over to here for convenience.

Essentially the issue seems to relate to a change in implementation of the playsinline parameter on YouTube's side. It doesn't matter what value you provide, or whether you use the default, but it seems to break every Youtube video embedded in this way.

The solution seems to be adding the following line before you call [myWebView loadHTMLString:string]:

[myWebView setMediaPlaybackRequiresUserAction:NO];

I have no idea why this fixes it, but many thanks to Kyokook Hwang for providing that answer so quickly. It worked for me, and it seemed to work for many others too.

OTHER TIPS

I'm experiencing this exact same issue. I don't know exactly when it started happening since I just got it reported as a bug today, but it manifests in exactly the way you describe.

This very much sounds like something going wrong on Google's end, let's hope it's not intentional.

edit: a friend pointed me at this post which may be related: https://productforums.google.com/forum/#!category-topic/youtube/report-a-technical-issue/iHd0NK33k-I

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top