开发者

Return to specific view after playing embedded youtube video in iOS

I'm playing a youtube video from a specific view (not the view that appears for first at app launch) in an iPhone app I'm developing.

Everyt开发者_开发知识库hing works fine: the video preview shows up in the web view inside my specific view and when I tap on it the video plays full screen.

When the video ends (or when I press the Done button) my app shows back, but showing the first view (the one that appears at app launch), not the one from which I launched the video. And what's even worst, the app doesn't respond to events (it doesn't crash, it just doesn't respond).

I tried to put some NSLogs in all the AppDelegate methods (in case the youtube plugin acts as if leaving my app and then returning), but none gets triggered...

I really have no clue what the problem can be...


I finally avoided the problem using the syntax introduced here http://apiblog.youtube.com/2010/07/new-way-to-embed-youtube-videos.html

In this way, the youtube player correctly returns to the "calling" view containing the web view.


I had the same problem, so try with this code:

NSString* embedHTML = [NSString stringWithFormat: @"\
                       <html><head>\
                       <style type=\"text/css\">\
                       body {\
                       background-color: transparent;\
                       color: white;\
                       }\
                       </style>\
                       </head><body style=\"margin:0\">\
                       <iframe class=\"youtube-player\" type=\"text/html\" width=\"%1.0f\"\
                       height=\"%0.0f\" src=\"%@\"\
                       frameborder=\"0\">\
                       </iframe> \
                       </body></html>", theFrame.size.width, theFrame.size.height, url];

UIWebView *videoView = [[[UIWebView alloc] initWithFrame:theFrame] autorelease];
[videoView loadHTMLString:embedHTML baseURL:nil];
[scrollView addSubview:videoView];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜