Authored by 盖剑秋

Add repush.

... ... @@ -17,7 +17,7 @@
@property (nonatomic, copy) NSString *app;//1男2女
@property (nonatomic, copy) NSString *type;//直播状态0未直播1直播中
@property (nonatomic, copy) NSString *room;//资讯合并id作为开始/结束的room参数
@property (nonatomic, assign) NSInteger totalTime;
@property (nonatomic, copy) NSString *totalTime;
@property (nonatomic, copy) NSString *title;
@end
... ...
... ... @@ -19,7 +19,10 @@
_app = [aDecoder decodeObjectForKey:@"app"];
_type = [aDecoder decodeObjectForKey:@"type"];
_room = [aDecoder decodeObjectForKey:@"room"];
_totalTime = [aDecoder decodeIntegerForKey:@"totalTime"];
_totalTime = [aDecoder decodeObjectForKey:@"totalTime"];
if (!_totalTime) {
_totalTime=@"0";
}
_title = [aDecoder decodeObjectForKey:@"title"];
}
... ... @@ -35,7 +38,7 @@
[aCoder encodeObject:_app forKey:@"app"];
[aCoder encodeObject:_type forKey:@"type"];
[aCoder encodeObject:_room forKey:@"room"];
[aCoder encodeInteger:_totalTime forKey:@"totalTime"];
[aCoder encodeObject:_totalTime forKey:@"totalTime"];
[aCoder encodeObject:_title forKey:@"title"];
}
... ...
... ... @@ -59,6 +59,7 @@
@property (nonatomic, strong) UIView *channelPannel;
@property (nonatomic, strong) UIButton *liveButton;//开始直播、结束直播。
@property (nonatomic, assign) BOOL switchLock;
@property (nonatomic, strong) NSArray<YH_ChannelModel *> *channels;
@property (nonatomic, strong) YH_ChannelModel *currentChannel;
... ... @@ -141,6 +142,11 @@
- (void)viewDidLoad {
[super viewDidLoad];
_currentChannelIndex = -1;
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kPushging];
if (data.length) {
_currentChannel = [NSKeyedUnarchiver unarchiveObjectWithData:data];
}
self.view.backgroundColor = [UIColor orangeColor];
[self initUI];
[self loadChannelData];
... ... @@ -154,7 +160,8 @@
if (_currentChannel) {
if ([self startRtmp]) {
[self toastTip:@"开始直播"];
_totalTime = _currentChannel.totalTime;
_switchLock = NO;
_totalTime = _currentChannel.totalTime.integerValue;
_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateInfoView) userInfo:nil repeats:YES];
[_timer fire];
_liveButton.selected = YES;
... ... @@ -166,6 +173,10 @@
self.socketService.userName = @"";
[self.socketService connect];
[_liveButton addTarget:self action:@selector(liveButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[_liveButton setTitle:@"开始直播" forState:UIControlStateNormal];
[_liveButton setTitle:@"结束直播" forState:UIControlStateSelected];
_switchLock=NO;
}
}
}
... ... @@ -181,22 +192,6 @@
- (void)loadChannelData {
//测试数据。
// YH_ChannelModel *model1 = [YH_ChannelModel new];
// model1.roomTitle = @"啦啦啦啦";
// model1.roomURL = @"rtmp://2718.livepush.myqcloud.com/live/2718_01973243308211e6a2cba4dcbef5e35a?bizid=2718";
// YH_ChannelModel *model2 = [YH_ChannelModel new];
// model2.roomTitle = @"噜噜噜噜";
// model2.roomURL = @"rtmp://2718.livepush.myqcloud.com/live/2718_01973243308211e6a2cba4dcbef5e35a?bizid=2718";
// YH_ChannelModel *model3 = [YH_ChannelModel new];
// model3.roomTitle = @"咯囖囖囖囖";
// model3.roomURL = @"rtmp://2718.livepush.myqcloud.com/live/2718_01973243308211e6a2cba4dcbef5e35a?bizid=2718";
// YH_ChannelModel *model4 = [YH_ChannelModel new];
// model4.roomTitle = @"哩哩哩哩哩";
// model4.roomURL = @"rtmp://2718.livepush.myqcloud.com/live/2718_01973243308211e6a2cba4dcbef5e35a?bizid=2718";
// _channels = @[model1,model2,model3,model4];
// [_channelTable reloadData];
if (_loading) {
return;
}
... ... @@ -229,6 +224,9 @@
model.room = obj[@"id"];
model.title = obj[@"title"];
[tempAry addObject:model];
if (_currentChannel&&[_currentChannel.roomURL isEqualToString:model.roomURL]) {
_currentChannelIndex = idx;
}
}];
_channels = [NSArray arrayWithArray:tempAry];
[_channelTable reloadData];
... ... @@ -307,6 +305,12 @@
_timeLabel.text = [NSString stringWithFormat:@"%@:%@:%@",hourStr,minuteStr,secondStr];
if (_totalTime%60==0&&_totalTime/60>=2) {
_currentChannel.totalTime = [NSString stringWithFormat:@"%@",@(_totalTime)];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:_currentChannel];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:kPushging];
}
}
-(BOOL)startRtmp{
... ... @@ -340,7 +344,6 @@
[_livePush startPush:rtmpUrl];
}
_inPushing = YES;
_currentChannel.totalTime = _totalTime;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:_currentChannel];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:kPushging];
return YES;
... ... @@ -646,6 +649,10 @@
[self hideAllToolView];
if (!_liveButton.selected) {
if (_switchLock) {
[self continueRTMP];
return;
}
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
manager.requestSerializer = [YH_HTTPRequestSerializer new];
... ... @@ -1025,11 +1032,7 @@
}
- (void)initChannelPannel {
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kPushging];
if (data.length) {
_currentChannel = [NSKeyedUnarchiver unarchiveObjectWithData:data];
}
_channelPannel = [UIView new];
_channelPannel.backgroundColor = [UIColor clearColor];
[self.view addSubview:_channelPannel];
... ... @@ -1056,10 +1059,10 @@
if (_currentChannel) {
_inPushing = YES;
_liveButton.selected = YES;
[_liveButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[_liveButton setTitle:@"继续上次直播" forState:UIControlStateNormal];
[_liveButton setTitle:@"结束直播" forState:UIControlStateSelected];
_switchLock = YES;
}
... ... @@ -1292,7 +1295,7 @@
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (_inPushing) {
if (_inPushing||_switchLock) {
return;//正在直播的情况下不得选择另外的房间,否则在通知结束的时候无法保证参数正确。。。
}
_currentChannelIndex = indexPath.row;
... ...