码迷,mamicode.com
首页 > Web开发 > 详细

webview加载 视频图片的 处理

时间:2015-09-08 12:29:21      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIWebView *webview = [[UIWebView alloc] initWithFrame:self.view.bounds];
//    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.baidu.com"]]];
    [self.view addSubview:webview];

    AFHTTPRequestOperationManager *manger = [AFHTTPRequestOperationManager manager];
    [manger GET:@"http://c.m.163.com/nc/article/AJHTO5LD00011229/full.html" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dict = (NSDictionary *)responseObject;
        NSString *body = [dict valueForKeyPath:@"AJHTO5LD00011229.body"];
        
        NSArray *imgs =  [dict valueForKeyPath:@"AJHTO5LD00011229.img"];
        for (NSDictionary *img in imgs) {
            NSString *url = img[@"src"];
            NSString *ref = img[@"ref"];
            NSString *imgItem = [NSString stringWithFormat:@"<img src=‘%@‘ width=‘300px‘ >",url];
            body =[body stringByReplacingOccurrencesOfString:ref withString:imgItem];
            
        }
        NSArray *videos =  [dict valueForKeyPath:@"AJHTO5LD00011229.video"];
        for (NSDictionary *video in videos) {
            NSString *url = video[@"url_mp4"];
            NSString *ref = video[@"ref"];
            NSString *imgItem = [NSString stringWithFormat:@"<video width=‘300‘ height=auto controls=‘controls‘ autoplay=‘autoplay‘><source src=‘%@‘ type=‘video/mp4‘ /></video>",url];
            body =[body stringByReplacingOccurrencesOfString:ref withString:imgItem];

        }


        [webview loadHTMLString:body baseURL:nil];
    
        NSLog(@"%@",dict.description);
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];

    
    
}

 

webview加载 视频图片的 处理

标签:

原文地址:http://www.cnblogs.com/coder-mh/p/4790991.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!