10

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?

0

2 Answers 2

7

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.

3
  • 1
    Do you know any other workaround? All videos on my apps are not working due to the exact same issue.
    – Mustafa
    Mar 1, 2014 at 8:34
  • This was the only one I could find. It worked for me, is your embed code format the same as the one I gave in the first example?
    – benwad
    Mar 4, 2014 at 10:48
  • Now, for some reason which I believe in Google Ends, it's working.
    – Mustafa
    Mar 12, 2014 at 14:40
0

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.