| | |
| | | #import "MusicSetPage.h" |
| | | #import "MusicPlayCell.h" |
| | | #import "HotelAccount.h" |
| | | #import "CSAudioManager.h" |
| | | #import "NetworkSingleton.h" |
| | | |
| | | #define kPlayID @"ID001" |
| | | #define kPlayID2 @"ID002" |
| | | |
| | | @interface MusicSetPage ()<UITableViewDelegate,UITableViewDataSource,musicPlayDelegate> |
| | | |
| | | { |
| | | |
| | | } |
| | | @property (nonatomic,strong) NSData *mp3Data; |
| | | @property (nonatomic,strong) CSAudioManager *csManager; |
| | | @property(nonatomic,strong) UITableView * tableView; |
| | | @property (nonatomic, strong) NSMutableArray *modelArray; |
| | | @end |
| | |
| | | { |
| | | [super viewDidLoad]; |
| | | // Do any additional setup after loading the view. |
| | | self.navigationItem.title = @"铃声设置"; |
| | | [self setNavigationLeft:@"返回" sel:@selector(backAction)]; |
| | | |
| | | self.csManager = [CSAudioManager defaultManager]; |
| | | self.mp3Data = nil; |
| | | |
| | | MPWeakSelf(self); |
| | | [self.csManager setBlockPlayerStartPlay:^{ |
| | | NSLog(@"控制器-要开始播放了"); |
| | | [weakself.tableView reloadData]; |
| | | }]; |
| | | |
| | | [self.csManager setBlockPlayerStopPlay:^{ |
| | | NSLog(@"控制器-要停止播放了"); |
| | | [weakself.tableView reloadData]; |
| | | }]; |
| | | |
| | | [self.csManager setBlockPlayerDidFinishPlaying:^{ |
| | | NSLog(@"控制器-知道播放结束了"); |
| | | //[weakself.tableView reloadData]; |
| | | }]; |
| | | |
| | | |
| | | //播放系统声音,系统声音名详见CSAudioManager.h 最下方 |
| | | //[self.csManager playSoundWithSoundName:@"sms-received1" PlayID:kPlayID2]; |
| | | |
| | | |
| | | self.modelArray = [[NSMutableArray alloc] init]; |
| | | for( int i =0; i<10;i++) |
| | | { |
| | | HotelAccount * model = [[HotelAccount alloc] init]; |
| | | [self.modelArray addObject:model]; |
| | | } |
| | | |
| | | self.tableView.hidden = NO; |
| | | [self.tableView reloadData]; |
| | | } |
| | | |
| | | -(void)backAction |
| | | { |
| | | [self dismissViewControllerAnimated:YES completion:nil]; |
| | | //[self.navigationController popViewControllerAnimated:YES]; |
| | | } |
| | | |
| | | - (void)didReceiveMemoryWarning |
| | |
| | | cell = [[MusicPlayCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; |
| | | } |
| | | |
| | | cell.delegate = self; |
| | | |
| | | HotelAccount * model = [self.modelArray objectAtIndex:indexPath.row]; |
| | | |
| | | NSInteger selIndex = [[UserDefault stringForKey:@"video"] integerValue]; |
| | | if( selIndex == indexPath.row ) |
| | | { |
| | | model.setStatus = 1; |
| | | } |
| | | |
| | | model.indexRow = indexPath.row; |
| | | model.musicName = @"music.mp3"; |
| | | model._id = [NSString stringWithFormat:@"judqiowu%ld",indexPath.row]; |
| | | model.xuhaoIndex = [NSString stringWithFormat:@"%02ld",indexPath.row+1]; |
| | | [cell setItemView:model]; |
| | | |
| | | return cell; |
| | |
| | | |
| | | - (void)musicPlaySection:(HotelAccount*)model |
| | | { |
| | | if ( model.cmd == 1 ) |
| | | { |
| | | if( model.playStatus == 1 ) |
| | | { |
| | | // 已存在销毁音频文件 |
| | | if( self.mp3Data != nil ) |
| | | { |
| | | //停止音频 |
| | | [self.csManager stopMusicWithPlayID:kPlayID]; |
| | | [self.csManager disposeSoundWithPlayID:kPlayID]; |
| | | } |
| | | |
| | | // 其他播放恢复默认值 |
| | | for( NSUInteger i = 0; i < self.modelArray.count;i++) |
| | | { |
| | | HotelAccount * tempModel = [self.modelArray objectAtIndex:i]; |
| | | if( [tempModel._id isEqualToString:model._id] ) |
| | | continue; |
| | | |
| | | tempModel.playStatus = 0; |
| | | } |
| | | |
| | | NSString *mp3Path = [[NSBundle mainBundle] pathForResource:model.musicName ofType:nil]; |
| | | NSLog(@"mp3Path : %@",mp3Path); |
| | | self.mp3Data = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:mp3Path]]; |
| | | |
| | | //播放音频 |
| | | [self.csManager playingMusicWithData:self.mp3Data playID:kPlayID]; |
| | | } |
| | | else if( model.playStatus == 2 ) |
| | | { |
| | | //停止音频 |
| | | [self.csManager stopMusicWithPlayID:kPlayID]; |
| | | } |
| | | } |
| | | else if( model.cmd == 2 ) |
| | | { |
| | | if( model.setStatus == 1 ) |
| | | { |
| | | //设置默认 |
| | | // 其他恢复默认值 |
| | | for( NSUInteger i = 0; i < self.modelArray.count;i++) |
| | | { |
| | | HotelAccount * tempModel = [self.modelArray objectAtIndex:i]; |
| | | if( [tempModel._id isEqualToString:model._id] ) |
| | | continue; |
| | | |
| | | tempModel.setStatus = 0; |
| | | } |
| | | |
| | | // 调用设置方法 |
| | | [self update_video:model]; |
| | | |
| | | } |
| | | else if( model.setStatus == 2 ) |
| | | { |
| | | //取消默认 |
| | | [self update_video:model]; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | -(void)update_video:(HotelAccount *)model |
| | | { |
| | | //[UserDefault stringForKey:@"user_id"] |
| | | NSString *path = [[NSString alloc] initWithFormat:UPDATE_USERINFO]; |
| | | |
| | | NSMutableDictionary *param = [[NSMutableDictionary alloc] init]; |
| | | |
| | | //['refresh_frequency', 'video', 'is_open_upload'] |
| | | [param setValue:[UserDefault stringForKey:@"user_id"] forKey:@"user_id"]; |
| | | [param setValue:@"video" forKey:@"field"]; // 1 上传 0 不传 |
| | | [param setValue:[NSString stringWithFormat:@"%ld",model.indexRow] forKey:@"value"]; |
| | | |
| | | MPWeakSelf(self); |
| | | [NetworkSingleton networkingGetMethod:param urlName:path success:^(id responseBody) |
| | | { |
| | | MPStrongSelf(self); |
| | | BaseResModel * resModel = [Global toBaseModel:responseBody]; |
| | | |
| | | if(resModel.code == 0) |
| | | { |
| | | [UserDefault setObject:[NSString stringWithFormat:@"%ld",model.indexRow] forKey:@"video"]; |
| | | [UserDefault synchronize]; |
| | | |
| | | [self.tableView reloadData]; |
| | | [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; |
| | | } |
| | | else |
| | | { |
| | | [Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; |
| | | } |
| | | } |
| | | failure:^(NSString *error) |
| | | { |
| | | |
| | | [Global alertMessageEx:error title:@"获取失败" okTtitle:nil cancelTitle:@"OK" delegate:self]; |
| | | }]; |
| | | } |
| | | |
| | | |
| | | /* |
| | | #pragma mark - Navigation |
| | | |