YouTube video playback broken on iOS6 (works fine on iOS5)

前端 未结 8 2185
南旧
南旧 2020-12-13 16:13

In my app, I have a button which, when pressed, lets you watch a youtube video (a movie trailer). Within the app, without launching safari. Below you can see a code snippet.

相关标签:
8条回答
  • 2020-12-13 16:47
    - (void) performTapInView: (UIView *) view {
        BOOL found = NO;
        if ([view gestureRecognizers] != nil) {
            for (UIGestureRecognizer *gesture in  [view gestureRecognizers]) {
                if ([gesture isKindOfClass: [UITapGestureRecognizer class]]) {
                    if ([gesture.view respondsToSelector: @selector(_singleTapRecognized:)]) {
                        found = YES;
                        [gesture.view performSelector: @selector(_singleTapRecognized:) withObject: gesture afterDelay: 0.07];
                        break;
                    }
                }
            }
        }
    
        if (!found) {
            for (UIView *v in view.subviews) {
                [self performTapInView: v];
            }
        }
    }
    #pragma mark - UIWebViewDelegate methods
    - (void) webViewDidFinishLoad: (UIWebView *) webView {
        if (findWorking) {
            return;
        }
        findWorking = YES;
        [self performTapInView: webView];
    }
    
    0 讨论(0)
  • 2020-12-13 16:49

    I'm working on this same general problem and I'll share the approach I've come up with. I have some remaining kinks to work out for my particular situation, but the general approach may work for you, depending on your UI requirements.

    If you structure your HTML embed code so that the YouTube player covers the entire bounds of the UIWebView, that UIWebView effectively becomes a big play button - a touch anywhere on it's surface will make the video launch into the native media player. To create your button, simply cover the UIWebView with a UIView that has userInteractionEnabled set to NO. Does it matter what the size the UIWebView is in this situation? Not really, since the video will open into the native player anyway.

    If you want the user to perceive an area of your UI as being where the video is going to "play", then you can grab the thumbnail for the video from YouTube and position that wherever. If need be, you could put a second UIWebView behind that view, so if the user touches that view, the video would also launch - or just spread the other UIWebView out so that it is "behind" both of these views.

    If you post a screenshot of your UI, I can make some more specific suggestions, but the basic idea is to turn the UIWebView into a button by putting a view in front of it that has user interaction disabled.

    0 讨论(0)
提交回复
热议问题