iOS上实现DLNA功能Github上搜一下大多是基于C++的Platinum,于是就想能不能靠OC实现一套方便iOS开发者.于是就有了MRDLNA这个库.
DLNA投屏的相关的介绍,协议,具体XML内容就不细说了. 这里介绍一下 MRDLNA这个库的投屏使用.
支持Pod安装MRDLNA
image.png
一.搜索设备
image.png
设置好代理 self.dlnaManager = [MRDLNA sharedMRDLNAManager]; self.dlnaManager.delegate = self;
调用开始搜索后就会搜索整个局域网中支持投视频的设备 - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.dlnaManager startSearch]; }
二.发现设备后的回调
发现设备后在代理中可以拿到 - (void)searchDLNAResult:(NSArray *)devicesArray{ NSLog(@"发现设备"); self.deviceArr = devicesArray; [self.dlnaTable reloadData]; } //devicesArray中拿到的是CLUPnPDevice类型的对象
Demo中将搜索页面和投屏控制页面分开来的,所以在搜索页面搜索到设备后就把目标设备和播放Url设置给了dlnaManager
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *testUrl = @"http://223.110.239.40:6060/cntvmobile/vod/p_cntvmobile00000000000020150518/m_cntvmobile00000000000659727681"; [tableView deselectRowAtIndexPath:indexPath animated:YES]; if (indexPath.row < self.deviceArr.count) { CLUPnPDevice *model = self.deviceArr[indexPath.row]; self.dlnaManager.device = model; self.dlnaManager.playUrl = testUrl; DLNAControlVC *controlVC = [[DLNAControlVC alloc] init]; controlVC.model = model; [self.navigationController pushViewController:controlVC animated:YES]; } }
三.投屏
- (void)viewDidLoad { [super viewDidLoad]; self.dlnaManager = [MRDLNA sharedMRDLNAManager]; [self.dlnaManager startDLNA]; }
四.投屏后的播放控制
/** 退出 */ - (IBAction)closeAction:(id)sender { [self.dlnaManager endDLNA]; } /** 播放/暂停 */ - (IBAction)playOrPause:(id)sender { if (_isPlaying) { [self.dlnaManager dlnaPause]; }else{ [self.dlnaManager dlnaPlay]; } _isPlaying = !_isPlaying; } /** 进度条seek单位是秒 */ - (IBAction)seekChanged:(UISlider *)sender{ NSInteger sec = sender.value * 60 * 60; NSLog(@"播放进度条======>: %zd",sec); [self.dlnaManager seekChanged:sec]; } /** 音量volume建议传0-100之间字符串 */ - (IBAction)volumeChange:(UISlider *)sender { NSString *vol = [NSString stringWithFormat:@"%.f",sender.value * 100]; NSLog(@"音量========>: %@",vol); [self.dlnaManager volumeChanged:vol]; } /** 切集 */ - (IBAction)playNext:(id)sender { NSString *testVideo = @"http://wvideo.spriteapp.cn/video/2016/0328/56f8ec01d9bfe_wpd.mp4"; [self.dlnaManager playTheURL:testVideo]; }
作者:MccReeee
链接:https://www.jianshu.com/p/1a522c2a4bbd#comments