...
|
...
|
@@ -43,7 +43,7 @@ |
|
|
#define kPushging @"pushing_key"
|
|
|
#define END_ACKCMD @"99"
|
|
|
|
|
|
@interface YH_RootViewController ()<TXLivePushListener, UITableViewDelegate, UITableViewDataSource,YH_SocketServiceDelegate,UIAlertViewDelegate>
|
|
|
@interface YH_RootViewController ()<TXLivePushListener,YH_SocketServiceDelegate,UIAlertViewDelegate>
|
|
|
|
|
|
@property (nonatomic, strong) TXLivePush *livePush;
|
|
|
|
...
|
...
|
@@ -57,15 +57,7 @@ |
|
|
@property (nonatomic, strong) UIButton *logButton;
|
|
|
@property (nonatomic, strong) UIButton *hdButton;
|
|
|
|
|
|
@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;
|
|
|
@property (nonatomic, strong) UITableView *channelTable;
|
|
|
|
|
|
@property (nonatomic, assign) NSInteger currentChannelIndex;
|
|
|
|
|
|
@property (nonatomic, strong) UIView *vBeauty;
|
|
|
@property (nonatomic, strong) UISlider *sdBeauty;
|
...
|
...
|
@@ -97,11 +89,8 @@ |
|
|
@property (nonatomic, assign) NSInteger totalTime;
|
|
|
@property (nonatomic, strong) NSTimer *timer;
|
|
|
|
|
|
@property (nonatomic, assign) BOOL loading;
|
|
|
|
|
|
@property (nonatomic, strong) GCDAsyncSocket *socket;
|
|
|
@property (nonatomic, strong) NSTimer *socketTimer;
|
|
|
@property (nonatomic, assign) BOOL inPushing;//是否正在直播,直播中无法切换房间以及开始新的频道直播。
|
|
|
|
|
|
@property (strong, nonatomic) YH_BarrageViewController *barrageViewController;
|
|
|
@property (strong, nonatomic) YH_SocketService *socketService;
|
...
|
...
|
@@ -112,10 +101,6 @@ |
|
|
|
|
|
@implementation YH_RootViewController
|
|
|
|
|
|
- (void)liveNotifyEndSuccess {
|
|
|
|
|
|
}
|
|
|
|
|
|
- (void)resetAfterPushEnd {
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
[self.barrageViewController reset];
|
...
|
...
|
@@ -167,8 +152,6 @@ |
|
|
}];
|
|
|
[manager startMonitoring];
|
|
|
|
|
|
_currentChannelIndex = -1;
|
|
|
|
|
|
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kPushging];
|
|
|
if (data.length) {
|
|
|
_currentChannel = [NSKeyedUnarchiver unarchiveObjectWithData:data];
|
...
|
...
|
@@ -180,9 +163,7 @@ |
|
|
}
|
|
|
self.view.backgroundColor = [UIColor orangeColor];
|
|
|
[self initUI];
|
|
|
// [self loadChannelData];
|
|
|
[self setUpPush];
|
|
|
DLog(@"=====%@",[TXLivePush getSDKVersion]);
|
|
|
}
|
|
|
|
|
|
- (void)continueRTMP {
|
...
|
...
|
@@ -196,14 +177,10 @@ |
|
|
}else {
|
|
|
if ([self startRtmp]) {
|
|
|
[YH_Tool alertMessage:@"直播开始"];
|
|
|
_switchLock = NO;
|
|
|
_totalTime = _currentChannel.totalTime.integerValue;
|
|
|
_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateInfoView) userInfo:nil repeats:YES];
|
|
|
[_timer fire];
|
|
|
_liveButton.selected = YES;
|
|
|
|
|
|
[self clearLog];
|
|
|
|
|
|
self.socketService.room = _currentChannel.room;
|
|
|
self.socketService.uid = @"";
|
|
|
self.socketService.userName = @"";
|
...
|
...
|
@@ -215,9 +192,6 @@ |
|
|
_currentChannel = nil;
|
|
|
}
|
|
|
}
|
|
|
[_liveButton addTarget:self action:@selector(liveButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
[_liveButton setTitle:@"开始直播" forState:UIControlStateNormal];
|
|
|
[_liveButton setTitle:@"结束直播" forState:UIControlStateSelected];
|
|
|
}];
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -234,53 +208,6 @@ |
|
|
[_livePush startPreview:self.view];
|
|
|
}
|
|
|
|
|
|
- (void)loadChannelData {
|
|
|
|
|
|
if (_loading) {
|
|
|
return;
|
|
|
}
|
|
|
_loading = YES;
|
|
|
[[YH_NetworkAdapter adapter] getPushListFinished:^(NSMutableDictionary *infoDict, NSError *error) {
|
|
|
_loading = NO;
|
|
|
if (error) {
|
|
|
[self toastTip:[NSString stringWithFormat:@"房间加载失败:%@",error.localizedDescription]];
|
|
|
}else {
|
|
|
if ([infoDict isKindOfClass:[NSDictionary class]]) {
|
|
|
id data = infoDict[@"data"];
|
|
|
if (![data isKindOfClass:[NSArray class]]) {
|
|
|
[self toastTip:@"没有可用直播间"];
|
|
|
return;
|
|
|
}
|
|
|
NSMutableArray *tempAry = @[].mutableCopy;
|
|
|
[data enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
if (![obj isKindOfClass:[NSDictionary class]]) {
|
|
|
*stop = YES;
|
|
|
[self toastTip:@"没有可用直播间"];
|
|
|
}
|
|
|
YH_ChannelModel *model = [YH_ChannelModel new];
|
|
|
model.roomTitle = obj[@"name"];
|
|
|
model.roomURL = obj[@"url"];
|
|
|
model.channel_id = obj[@"channel_id"];
|
|
|
model.cid = obj[@"cid"];
|
|
|
model.app = obj[@"app"];
|
|
|
model.type = obj[@"type"];
|
|
|
model.room = obj[@"id"];
|
|
|
model.title = obj[@"title"];
|
|
|
model.secret = obj[@"secret"];
|
|
|
[tempAry addObject:model];
|
|
|
if (_currentChannel&&[_currentChannel.roomURL isEqualToString:model.roomURL]) {
|
|
|
_currentChannelIndex = idx;
|
|
|
}
|
|
|
}];
|
|
|
_channels = [NSArray arrayWithArray:tempAry];
|
|
|
[_channelTable reloadData];
|
|
|
_currentChannelIndex = -1;
|
|
|
}
|
|
|
}
|
|
|
}];
|
|
|
|
|
|
}
|
|
|
|
|
|
#pragma mark --sockerserviceDelegate
|
|
|
- (NSString *)formatNumer:(NSString *)number
|
|
|
{
|
...
|
...
|
@@ -380,7 +307,6 @@ |
|
|
{
|
|
|
[_livePush startPush:rtmpUrl];
|
|
|
}
|
|
|
_inPushing = YES;
|
|
|
self.socketService.room = _currentChannel.room;
|
|
|
self.socketService.uid = @"";
|
|
|
self.socketService.userName = @"";
|
...
|
...
|
@@ -547,14 +473,10 @@ |
|
|
|
|
|
[sock disconnect];
|
|
|
_socket = nil;
|
|
|
// [self loadChannelData];//防止主播再次进入同一间房间。
|
|
|
_inPushing = NO;
|
|
|
[_socketTimer invalidate];
|
|
|
_socketTimer = nil;
|
|
|
[self stopRtmp];
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kPushging];
|
|
|
_liveButton.selected = !_liveButton.selected;
|
|
|
|
|
|
[[YH_NetworkAdapter adapter] setStatusWithStat:PushStatusEnd andRoomId:_currentChannel.room completion:^(BOOL flag, NSError *error) {
|
|
|
_currentChannel = nil;
|
|
|
[self resetAfterPushEnd];
|
...
|
...
|
@@ -594,7 +516,7 @@ |
|
|
}
|
|
|
|
|
|
if(_livePush != nil) {
|
|
|
if (_liveButton.selected) {
|
|
|
if (_currentChannel) {
|
|
|
[self stopRtmp];
|
|
|
}
|
|
|
|
...
|
...
|
@@ -602,7 +524,7 @@ |
|
|
if (configTmp.enableHWAcceleration == NO)
|
|
|
{
|
|
|
NSString* strTip = @"iOS SDK启用硬件加速.";
|
|
|
if (_liveButton.selected)
|
|
|
if (_currentChannel)
|
|
|
{
|
|
|
strTip = @"iOS SDK启用硬件加速,切换后会重新开始推流";
|
|
|
}
|
...
|
...
|
@@ -613,7 +535,7 @@ |
|
|
else
|
|
|
{
|
|
|
NSString* strTip = @"iOS SDK停止硬件加速.";
|
|
|
if (_liveButton.selected)
|
|
|
if (_currentChannel)
|
|
|
{
|
|
|
strTip = @"iOS SDK停止硬件加速,切换后会重新开始推流";
|
|
|
}
|
...
|
...
|
@@ -623,7 +545,7 @@ |
|
|
}
|
|
|
_livePush.config = configTmp;
|
|
|
|
|
|
if (_liveButton.selected) {
|
|
|
if (_currentChannel) {
|
|
|
[self startRtmp];
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -717,73 +639,10 @@ |
|
|
sender.selected = !sender.selected;
|
|
|
}
|
|
|
|
|
|
- (void)liveButtonPressed:(UIButton *)sender {
|
|
|
|
|
|
if (!_currentChannel) {
|
|
|
[self toastTip:@"请先选择房间"];
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
[self hideAllToolView];
|
|
|
if (!_liveButton.selected) {
|
|
|
if (_switchLock) {
|
|
|
[self continueRTMP];
|
|
|
return;
|
|
|
}
|
|
|
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"请输入密码" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
|
|
|
alert.tag = ValidateAlertTag;
|
|
|
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
|
|
|
[alert show];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (_totalTime<122) {
|
|
|
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"直播时间小于2分钟,不可以结束直播。" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
|
|
|
[alert show];
|
|
|
} else {
|
|
|
|
|
|
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"确定结束直播?" delegate:self cancelButtonTitle:@"否" otherButtonTitles:@"是", nil];
|
|
|
[alert show];
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
|
|
|
|
|
|
if (alertView.tag == ContinueAlertTag && buttonIndex == 0) {
|
|
|
[self continueRTMP];
|
|
|
} else if (alertView.tag == ValidateAlertTag && alertView.firstOtherButtonIndex == buttonIndex) {
|
|
|
UITextField *txtField = [alertView textFieldAtIndex:0];
|
|
|
if ([txtField.text isEqualToString:_currentChannel.secret]) {
|
|
|
[[YH_NetworkAdapter adapter] setStatusWithStat:PushStatusStart andRoomId:_currentChannel.room completion:^(BOOL flag, NSError *error) {
|
|
|
|
|
|
if (error) {
|
|
|
[self toastTip:[NSString stringWithFormat:@"开始失败,原因:%@",error.localizedDescription]];
|
|
|
}else {
|
|
|
if ([self startRtmp]) {
|
|
|
[self toastTip:@"开始直播"];
|
|
|
|
|
|
_totalTime = 0;
|
|
|
_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateInfoView) userInfo:nil repeats:YES];
|
|
|
[_timer fire];
|
|
|
_liveButton.selected = !_liveButton.selected;
|
|
|
|
|
|
[self clearLog];
|
|
|
|
|
|
}else {
|
|
|
[self toastTip:@"直播开始失败"];
|
|
|
}
|
|
|
}
|
|
|
}];
|
|
|
} else {
|
|
|
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"密码错误" message:@"请重新输入密码" delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
|
|
|
[alert show];
|
|
|
}
|
|
|
} else {
|
|
|
[_timer invalidate];
|
|
|
[self socketSendEndNotify];//通知结束。
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -805,7 +664,6 @@ |
|
|
|
|
|
_vBeauty.hidden = YES;
|
|
|
_vHD.hidden = YES;
|
|
|
_channelPannel.hidden = YES;
|
|
|
_beautyButton.selected = NO;
|
|
|
_hdButton.selected = NO;
|
|
|
_channelButton.selected = NO;
|
...
|
...
|
@@ -1050,7 +908,7 @@ |
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (_liveButton.selected) {
|
|
|
if (_currentChannel) {
|
|
|
[self stopRtmp];
|
|
|
}
|
|
|
|
...
|
...
|
@@ -1093,78 +951,11 @@ |
|
|
[self setHDUI:_hd_level];
|
|
|
_vHD.hidden = YES;
|
|
|
|
|
|
if (_liveButton.selected) {
|
|
|
if (_currentChannel) {
|
|
|
[self startRtmp];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- (void)initChannelPannel {
|
|
|
|
|
|
_channelPannel = [UIView new];
|
|
|
_channelPannel.backgroundColor = [UIColor clearColor];
|
|
|
[self.view addSubview:_channelPannel];
|
|
|
|
|
|
|
|
|
UILabel *titleLabel = [UILabel new];
|
|
|
titleLabel.backgroundColor = [UIColor whiteColor];
|
|
|
titleLabel.font = [UIFont boldSystemFontOfSize:16];
|
|
|
titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
titleLabel.text = @"直播间";
|
|
|
titleLabel.layer.borderColor = [UIColor lightGrayColor].CGColor;
|
|
|
titleLabel.layer.borderWidth = 0.5;
|
|
|
[_channelPannel addSubview:titleLabel];
|
|
|
|
|
|
_liveButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
_liveButton.backgroundColor = [UIColor whiteColor];
|
|
|
[_liveButton addTarget:self action:@selector(liveButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
[_liveButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
|
|
|
[_liveButton setTitle:@"开始直播" forState:UIControlStateNormal];
|
|
|
[_liveButton setTitle:@"结束直播" forState:UIControlStateSelected];
|
|
|
_liveButton.titleLabel.font = [UIFont systemFontOfSize:16];
|
|
|
[_liveButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
|
|
|
[_channelPannel addSubview:_liveButton];
|
|
|
|
|
|
|
|
|
if (_currentChannel) {
|
|
|
[_liveButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
|
|
|
[_liveButton setTitle:@"继续上次直播" forState:UIControlStateNormal];
|
|
|
[_liveButton setTitle:@"结束直播" forState:UIControlStateSelected];
|
|
|
_switchLock = YES;
|
|
|
}
|
|
|
|
|
|
|
|
|
_channelTable = [UITableView new];
|
|
|
_channelTable.tableFooterView = [UIView new];
|
|
|
_channelTable.backgroundColor = [UIColor whiteColor];
|
|
|
_channelTable.delegate = self;
|
|
|
_channelTable.dataSource = self;
|
|
|
[_channelPannel addSubview:_channelTable];
|
|
|
|
|
|
|
|
|
[_channelPannel autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
|
|
|
[_channelPannel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
|
|
|
[_channelPannel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:60];
|
|
|
[_channelPannel autoSetDimension:ALDimensionHeight toSize:250];
|
|
|
|
|
|
[titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTop];
|
|
|
[titleLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft];
|
|
|
[titleLabel autoPinEdgeToSuperviewEdge:ALEdgeRight];
|
|
|
[titleLabel autoSetDimension:ALDimensionHeight toSize:40];
|
|
|
|
|
|
|
|
|
[_liveButton autoPinEdgeToSuperviewEdge:ALEdgeBottom];
|
|
|
[_liveButton autoPinEdgeToSuperviewEdge:ALEdgeLeft];
|
|
|
[_liveButton autoPinEdgeToSuperviewEdge:ALEdgeRight];
|
|
|
[_liveButton autoSetDimension:ALDimensionHeight toSize:40];
|
|
|
|
|
|
[_channelTable autoPinEdgeToSuperviewEdge:ALEdgeLeft];
|
|
|
[_channelTable autoPinEdgeToSuperviewEdge:ALEdgeRight];
|
|
|
[_channelTable autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:titleLabel];
|
|
|
[_channelTable autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:_liveButton withOffset:-10];
|
|
|
|
|
|
_channelPannel.hidden = YES;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @author Kennaki Kai, 16-06-12 10:06:20
|
|
|
*
|
...
|
...
|
@@ -1334,14 +1125,14 @@ |
|
|
[_orientationButton autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:15];
|
|
|
[_orientationButton autoPinEdge:ALEdgeRight toEdge:ALEdgeLeft ofView:_torchButton withOffset:-15];
|
|
|
|
|
|
[_orientationButton autoSetDimensionsToSize:CGSizeMake(100, 30)];
|
|
|
[_orientationButton setBackgroundColor:[UIColor colorWithWhite:255 alpha:0.85]];
|
|
|
[_orientationButton setTitle:@"设置为横屏" forState:UIControlStateNormal];
|
|
|
[_orientationButton setTitle:@"设置为竖屏" forState:UIControlStateSelected];
|
|
|
_orientationButton.titleLabel.font = [UIFont systemFontOfSize:15];
|
|
|
[_orientationButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
|
|
|
_orientationButton.layer.cornerRadius = 15;
|
|
|
[_orientationButton addTarget:self action:@selector(orientationButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
// [_orientationButton autoSetDimensionsToSize:CGSizeMake(100, 30)];
|
|
|
// [_orientationButton setBackgroundColor:[UIColor colorWithWhite:255 alpha:0.85]];
|
|
|
// [_orientationButton setTitle:@"设置为横屏" forState:UIControlStateNormal];
|
|
|
// [_orientationButton setTitle:@"设置为竖屏" forState:UIControlStateSelected];
|
|
|
// _orientationButton.titleLabel.font = [UIFont systemFontOfSize:15];
|
|
|
// [_orientationButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
|
|
|
// _orientationButton.layer.cornerRadius = 15;
|
|
|
// [_orientationButton addTarget:self action:@selector(orientationButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
|
|
|
|
NSArray *bottomAry = @[_channelButton,_beautyButton,_accellerateButton,_logButton,_hdButton];
|
...
|
...
|
@@ -1351,9 +1142,6 @@ |
|
|
}
|
|
|
|
|
|
[self initBeautyAndHDPannel];
|
|
|
|
|
|
[self initChannelPannel];
|
|
|
|
|
|
}
|
|
|
|
|
|
- (void)orientationButtonPressed:(UIButton *)sender {
|
...
|
...
|
@@ -1374,39 +1162,6 @@ |
|
|
}
|
|
|
}
|
|
|
|
|
|
#pragma mark - table view protocols...
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
|
|
|
return _channels.count;
|
|
|
}
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
|
YH_ChannelCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YH_ChannelCell"];
|
|
|
if (!cell) {
|
|
|
cell = [[YH_ChannelCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YH_ChannelCell"];
|
|
|
}
|
|
|
NSString *title=[NSString stringWithFormat:@"%@---%@",_channels[indexPath.row].roomTitle,_channels[indexPath.row].title];
|
|
|
[cell bindChannelTitle:title selected:(indexPath.row==_currentChannelIndex)];
|
|
|
return cell;
|
|
|
|
|
|
return [UITableViewCell new];
|
|
|
}
|
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
return 40;
|
|
|
}
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
if (_inPushing||_switchLock) {
|
|
|
return;//正在直播的情况下不得选择另外的房间,否则在通知结束的时候无法保证参数正确。。。
|
|
|
}
|
|
|
_currentChannelIndex = indexPath.row;
|
|
|
_currentChannel = _channels[_currentChannelIndex];
|
|
|
[_liveButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
|
|
|
[_channelTable reloadData];
|
|
|
}
|
|
|
|
|
|
- (void) toastTip:(NSString*)toastInfo
|
|
|
{
|
|
|
CGRect frameRC = [[UIScreen mainScreen] bounds];
|
...
|
...
|
|