Pure OC realizes iOS DLNA screen projection function

image.png

  • Implementing DLNA function on iOS Github searched most of the Platinum based on C++, so I wondered if I could rely on OC to implement a set of convenience for iOS developers. So there is the MRDLNA library.

  • The relevant introduction, protocol and specific XML content of DLNA screen projection will not be discussed in detail. Here is an introduction to the screen projection use of the MRDLNA library.

Support Pod to install MRDLNA

image.png

1. Search equipment

image.png

设置好代理
self.dlnaManager = [MRDLNA sharedMRDLNAManager];
self.dlnaManager.delegate = self;
调用开始搜索后就会搜索整个局域网中支持投视频的设备
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.dlnaManager startSearch];
}

2. Callback after device discovery

发现设备后在代理中可以拿到
- (void)searchDLNAResult:(NSArray *)devicesArray{
    NSLog(@"发现设备");
    self.deviceArr = devicesArray;
    [self.dlnaTable reloadData];
}

//devicesArray中拿到的是CLUPnPDevice类型的对象
  • In the Demo, the search page and the screen projection control page are separated, so after the device is found on the search page, the target device and playback Url are set to 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];
    }
}

3. Projection

- (void)viewDidLoad {
    [super viewDidLoad];
    self.dlnaManager = [MRDLNA sharedMRDLNAManager];
    [self.dlnaManager startDLNA];
}

4. Playback control after screen projection

/**
 退出
 */
- (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];
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325966407&siteId=291194637