• Github search is mostly based on C++ Platinum, so I want to rely on OC to achieve a set of convenient iOS developers. Hence the MRDLNA library.

  • DLNA screen casting related introduction, protocol, specific XML content will not be detailed. Here is an introduction to MRDLNA this library screen casting use.

Supports Pod installation of MRDLNA

I. Search equipment

Set agent self.dlnaManager = [MRDLNA sharedMRDLNAManager]; self.dlnaManager.delegate = self;Copy the code
- (void)viewWillAppear:(BOOL)animated{[super viewWillAppear:animated]; [self.dlnaManager startSearch]; }Copy the code

2. Callback after device discovery

- (void)searchDLNAResult:(NSArray *)devicesArray{NSLog(@)"Device discovery"); self.deviceArr = devicesArray; [self.dlnaTable reloadData]; } //devicesArray gets objects of type CLUPnPDeviceCopy the code
  • Demo separates the search page from the screen casting control page, so after the search page finds the device, the target device and the playing 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]; }}Copy the code

3. Screen

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

Iv. Playback control after screen casting

/** exit */ - (IBAction)closeAction (id)sender {[self.dlnamanager endDLNA]; } /** play/pause */ - (IBAction)playOrPause:(id)sender {if (_isPlaying) {
        [self.dlnaManager dlnaPause];
    }else{ [self.dlnaManager dlnaPlay]; } _isPlaying = ! _isPlaying; } /** seekChanged:(UISlider *)sender{NSInteger SEC = sender.value * 60 * 60; NSLog(@"Play progress bar ======>: %zd",sec); [self.dlnaManager seekChanged:sec]; } /** the recommended value is a string between 0 and 100 */ - (IBAction)volumeChange:(UISlider *)sender {NSString *vol = [NSString stringWithFormat:@"%.f",sender.value * 100];
    NSLog(@"Volume ========>: %@",vol); [self.dlnaManager volumeChanged:vol]; } /** cut set */ - (IBAction)playNext:(id)sender {NSString *testVideo = @"http://wvideo.spriteapp.cn/video/2016/0328/56f8ec01d9bfe_wpd.mp4";
    [self.dlnaManager playTheURL:testVideo];
}
Copy the code