开发者

How to embed video url for ipad

开发者 https://www.devze.com 2023-04-11 02:11 出处:网络
- (void)embedYouTube:(NSString*)url frame:(CGRect)frame { NSString *htmlString = [NSString stringWithFormat:<html><head>\\
- (void)embedYouTube:(NSString*)url frame:(CGRect)frame {   

    NSString *htmlString = [NSString stringWithFormat:<html><head>\
    <meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head>\
    <body style=\"background:#F00;margin-top:0px;margin-left:0px\">\
    <div><object width=\"100\" height=\"100\">\
    <param name=\"movie\" value=\"%@\"></param>\
    <param name=\"wmode\" value=\"transparent\"></param>\
    <embed src=\"%@\"\
    type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"100\" height=\"100\"></embed>\
    </object></div></body></html>",url,url];

    webView = [[UIWebView alloc] initWithFrame:frame];
    webView.delegate = self;
    [开发者_Python百科webView setScalesPageToFit:TRUE];
    [webView setContentMode:UIViewContentModeTop];
    [self.view addSubview:webView];
    [webView loadHTMLString:htmlString baseURL:nil];

}

I have implemented above code. It works fine on iPhone, but on iPad I just hear the audio, the video is not displayed.

How can I make this work on both types of devices?


I got solution after working more then two days... Solution is that I need to add controller in view not same as iphone. But remember one thing just write this two line while dismissing view.

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];


this will do the trick. try the following code:

(mind you, it will work only on the device and not the simulator)

  NSURL *videoURL = [NSURL URLWithString: @"http://www.youtube.com/embed/iyKsSPHM0wE"];



    NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]; 
    [NSURLCache setSharedURLCache:sharedCache]; [sharedCache release];
    //

    NSURLRequest *request = [[NSURLRequest alloc] initWithURL: videoURL cachePolicy: NSURLRequestReloadIgnoringLocalCacheData timeoutInterval: 30.0];  
    [webView loadRequest: request];  
    [request release];
0

精彩评论

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

关注公众号