美文网首页工作中用到的好技术
iOS - YYWebImage, SDWebImage, AV

iOS - YYWebImage, SDWebImage, AV

作者: 浅宇落 | 来源:发表于2019-09-29 08:23 被阅读0次

开发中可能添加请求头网络图片请求, 例如: 添加Referer

SDWebImage

// 请求头的 key
NSString *key = @"Referer";
// 请求头的 value
NSString *value = @"https://vdapi54.daoxiaomian123.cn/";

// 设置请求头
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
[downloader setValue:value forHTTPHeaderField:key];

// 需要请求头的图片
NSString *imageStr = @"http://sptest.ohtorichina.com.cn/upload/vod/2017-12-13/201712131513155070.jpg";
UIImageView *imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(100, 100, 200, 200);
imageView.backgroundColor = [UIColor redColor];
[self.view addSubview:imageView];
[imageView sd_setImageWithURL:[NSURL URLWithString:imageStr]];

// 不需要请求头的图片
NSString *str = @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1568030373084&di=e132e34de28b5031d8c8abbd2e4a1d0f&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201502%2F02%2F20150202125117_SdVsk.jpeg";
UIImageView *imgView1 = [[UIImageView alloc] init];
imgView1.frame = CGRectMake(100, CGRectGetMaxY(imageView.frame) + 10, 200, 200);
imgView1.backgroundColor = [UIColor redColor];
[self.view addSubview:imgView1];
[imgView1 sd_setImageWithURL:[NSURL URLWithString:str]];
需要请求头的图片.png
不需要请求头的图片.png

YYWebImage

// 请求头的 key
NSString *key = @"Referer";
// 请求头的 value
NSString *value = @"https://vdapi54.daoxiaomian123.cn/";

// 设置请求头
YYWebImageManager *imageManage = [YYWebImageManager sharedManager];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithDictionary:imageManage.headers];
dictionary[@"Referer"] = refererStr;
imageManage.headers = dictionary;

// 需要请求头的图片
NSString *imageStr = @"http://sptest.ohtorichina.com.cn/upload/vod/2017-12-13/201712131513155070.jpg";
YYAnimatedImageView *imageView = [[YYAnimatedImageView alloc] init];
imageView.frame = CGRectMake(100, 100, 200, 200);
imageView.backgroundColor = [UIColor redColor];
[self.view addSubview:imageView];
[imageView yy_setImageWithURL:[NSURL URLWithString:str] placeholder:nil];

// 不需要请求头的图片
NSString *str = @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1568030373084&di=e132e34de28b5031d8c8abbd2e4a1d0f&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201502%2F02%2F20150202125117_SdVsk.jpeg";
YYAnimatedImageView *imgView2 = [[YYAnimatedImageView alloc] init];
imgView2.frame = CGRectMake(100, 100, 200, 200);
imgView2.backgroundColor = [UIColor redColor];
[self.view addSubview:imgView2];
[imgView2 yy_setImageWithURL:[NSURL URLWithString:str] placeholder:nil];

需要请求头的图片.png
不需要请求头的图片.png

AVPlayer

#import <AVFoundation/AVFoundation.h>

@interface AvplayerVc ()
/** 播放器 */
@property (nonatomic, strong) AVPlayer *player;
/** 图层 */
@property (nonatomic, strong) AVPlayerLayer *playerLayer;
@end

// 设置header
NSDictionary *header = @{@"Referer":@"https://vdapi54.daoxiaomian123.cn/"};
NSURL *url = [NSURL URLWithString:@"http://sksk2.afadd.cn/upload/preview/waichu/waichu.m3u8"];
AVURLAsset *urlAssert = [AVURLAsset URLAssetWithURL:url options:@{@"AVURLAssetHTTPHeaderFieldsKey" : header}];
AVPlayerItem *playItem = [AVPlayerItem playerItemWithAsset:urlAssert];
self.player = [[AVPlayer alloc] initWithPlayerItem:playItem];
// 图层
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
self.playerLayer.videoGravity     = AVLayerVideoGravityResizeAspect;
self.playerLayer.frame = self.view.bounds;
[self.view.layer addSublayer:self.playerLayer];
// 播放
[self.player play];

希望此篇文章对你们有用,如果错误请指出。

相关文章

  • iOS - YYWebImage, SDWebImage, AV

    开发中可能添加请求头网络图片请求, 例如: 添加Referer SDWebImage YYWebImage AVP...

  • iOS 几种图片或Gif异步加载

    iOS 加载加载图片的方式主流的有两种(本地图片略过):1、SDWebImage。2、YYWebImage。 区别...

  • YYKit

    YYWebImage:1、相比SDWebImage播放gif图片时内存占用大大降低。SDWebImage中对gif...

  • YYWebImage,SDWebImage和PINRemoteI

    YYWebImage,SDWebImage和PINRemoteImage比较 共同的特性 以类别 api 下载远程...

  • YYWebImage 与 SDWebImage

    未完待续

  • SDWebImage、YYWebImage让UIImageVie

    参考: iOS Runtime交换对象方法和类方法探讨 YYImage SDWebImage SDWebimage...

  • 源码解析--YYWebImage

    前言:YYWebImage是YYKit系列中图片请求的框架。作者号称是可以替代SDWebImage框架。至于优秀的...

  • tableView的优化

    cell里的image使用SDWebimage,高清大图用YYWebimage来下载缓存图片 cell内部控件的层...

  • SDWebImage

    上文 码完YYWebImage后发现,SDWebImage 已经更新4.0-Beta2,一并记录一下。 动图 图片...

  • iOS 清理缓存

    通常,在我们加载图片的时候,一般都会做缓存处理,像SDWebImage,YYWebImage都是有的,但是有缓存,...

网友评论

    本文标题:iOS - YYWebImage, SDWebImage, AV

    本文链接:https://www.haomeiwen.com/subject/mbmmyctx.html