MKRPlayControlViewController.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // MKRPlayControlViewController.m
  3. // MKRRadioManager_Example
  4. //
  5. // Created by yyqxiaoyin on 2019/4/17.
  6. // Copyright © 2019 yyqxiaoyin. All rights reserved.
  7. //
  8. #import "MKRPlayControlViewController.h"
  9. @interface MKRPlayControlViewController ()<UITableViewDataSource,UITableViewDelegate>
  10. @property (nonatomic, strong) MKRUPnPDevice *device;
  11. @property (nonatomic, strong) UITableView *tableView;
  12. @property (nonatomic, strong) NSArray *dataSource;
  13. @end
  14. @implementation MKRPlayControlViewController
  15. - (instancetype)initWithDevice:(MKRUPnPDevice *)device{
  16. if (self = [super init]) {
  17. // [[MKRRadioControlMaster shareMaster] changeCurrentDevice:device];
  18. }
  19. return self;
  20. }
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. self.view.backgroundColor = [UIColor whiteColor];
  24. self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
  25. self.tableView.delegate = self;
  26. self.tableView.dataSource = self;
  27. [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
  28. [self.view addSubview:self.tableView];
  29. self.dataSource = @[
  30. @{@"播放":@"play"},
  31. @{@"播放频道":@"playChannel:"},
  32. @{@"暂停":@"pause"},
  33. @{@"上一曲":@"previous"},
  34. @{@"下一曲":@"next"},
  35. @{@"停止":@"stop"},
  36. @{@"音量+":@"volumePlus"},
  37. @{@"音量-":@"volumeMins"},
  38. ];
  39. }
  40. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  41. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  42. NSDictionary *dic = self.dataSource[indexPath.row];
  43. cell.textLabel.text = [dic.allKeys firstObject];
  44. return cell;
  45. }
  46. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  47. return self.dataSource.count;
  48. }
  49. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  50. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  51. NSDictionary *dic = self.dataSource[indexPath.row];
  52. NSString *selString = [dic.allValues firstObject];
  53. SEL sel = NSSelectorFromString(selString);
  54. if ([selString containsString:@":"]) {
  55. int x = arc4random() % (11 - 0 + 1) + 0;
  56. [self performSelector:sel withObject:@(x).stringValue afterDelay:0];
  57. }else{
  58. [self performSelector:sel withObject:nil afterDelay:0];
  59. }
  60. }
  61. - (void)play{
  62. // [_MKRRadioControlMaster play];
  63. // [_MKRWIFIDeviceManager playWithDevice:self.device];
  64. }
  65. - (void)playChannel:(NSString *)channel{
  66. NSLog(@"播放频道:%@",channel);
  67. // [_MKRRadioControlMaster playSongWithChannelNO:channel userID:@""];
  68. // [_MKRWIFIDeviceManager playSongWithChannelNO:[channel integerValue]
  69. // index:0
  70. // device:self.device
  71. // userID:@""];
  72. }
  73. - (void)pause{
  74. // [_MKRRadioControlMaster pause];
  75. // [_MKRWIFIDeviceManager pauseWithDevice:self.device];
  76. }
  77. - (void)previous{
  78. // [_MKRRadioControlMaster previous];
  79. // [_MKRWIFIDeviceManager previousWithDevice:self.device];
  80. }
  81. - (void)next{
  82. // [_MKRRadioControlMaster next];
  83. // [_MKRWIFIDeviceManager nextWithDevice:self.device];
  84. }
  85. - (void)stop{
  86. // [_MKRRadioControlMaster stop];
  87. // [_MKRWIFIDeviceManager stopWithDevice:self.device];
  88. }
  89. - (void)volumePlus{
  90. // [_MKRRadioControlMaster setVolume:80];
  91. // [_MKRWIFIDeviceManager setVolume:80 device:self.device];
  92. }
  93. - (void)volumeMins{
  94. // [_MKRRadioControlMaster setVolume:20];
  95. // [_MKRWIFIDeviceManager setVolume:20 device:self.device];
  96. }
  97. @end