设置好代理
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类型的对象
- (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];
}
摘自:https://www.jianshu.com/p/1a522c2a4bbd
原创文章如转载请注明: