I have a method that load some youtube videos in a UIWebview and i have lots of videos and when i am running the code i am getting Received memory warning and app get crashed. I tried to fix it using did received memory waring
but its not working this is the method that i am using :-
-(void) setScrollView:(UIScrollView *)scrollview :(NSArray *)contentArray{
int x=0;
for(NSDictionary *str in contentArray){
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(x, 0, 123, 123)];
webView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
webView.scrollView.scrollEnabled = NO;
webView.scrollView.bounces = NO;
NSString *link = [str objectForKey:@"UTUBEURL"];
link = [@"http://www.youtube.com/v/" stringByAppendingFormat:link];
NSLog(@"link = %@",link);
NSString *embedHTML = @"\
<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0 \">\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body width=\"%0.0f\" height=\"%0.0f\" style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\" autostart=\"true\"></embed>\
</body></html>";
NSString* html = [NSString stringWithFormat:embedHTML,webView.frame.size.width, webView.frame.size.height,link, webView.frame.size.width, webView.frame.size.height];
[webView loadHTMLString:html baseURL:nil];
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(x,123,200,20)];
[title setFont:[UIFont systemFontOfSize:11]];
[title setBackgroundColor:[UIColor blackColor]];
[title setTextColor:[UIColor whiteColor]];
title.text = [NSString stringWithFormat:@" %@",[str objectForKey:@"DISPLAYTEXT"]];
x += webView.frame.size.width+2;
[scrollview addSubview:webView];
[scrollview addSubview:title];
}
scrollview.contentSize = CGSizeMake(x, scrollview.frame.size.height);
}
i am having about 50 videos here so what can i do to avoid this i am calling this method in side my viewDidLoad. Is there a way to do this better using a thread, can someone help me with this? but i dont have any knowledge on thread on ios.
I can not write the whole code for you, but giving you a short piece of code to help you.
You make a scrollView, having thumbnail images of what video to play and save the urls in an array respectively then