-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathLebAutoBitrateViewController.m
More file actions
135 lines (114 loc) · 5.56 KB
/
LebAutoBitrateViewController.m
File metadata and controls
135 lines (114 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright © 2022 Tencent. All rights reserved.
/*
Webrtc Auto Bitrate
MLVB APP Webrtc Auto Bitrate
1、Set Render View API:[self.livePlayer setRenderView:self.view];
2、Start Play API: [self.livePlayer startLivePlay:url];
Documentation: https://cloud.tencent.com/document/product/454/81212
After the adaptive bitrate playback is started, seamless streaming cannot be performed.
If you enter the adaptive bit rate in the playback state,
Need to stop current playback before starting adaptive playback
*/
#import "LebAutoBitrateViewController.h"
typedef NS_ENUM(NSInteger, PlayResolution) {
Resolution1080p,
Resolution720p,
Resolution540p,
};
@interface LebAutoBitrateViewController () <V2TXLivePlayerObserver>
@property (strong, nonatomic) V2TXLivePlayer *livePlayer;
@property (weak, nonatomic) IBOutlet UIButton *autoBitrateButton;
@property (weak, nonatomic) IBOutlet UIButton *switch1080pButton;
@property (weak, nonatomic) IBOutlet UIButton *switch720pButton;
@property (weak, nonatomic) IBOutlet UIButton *switch540pButton;
@end
@implementation LebAutoBitrateViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupDefaultUIConfig];
self.livePlayer = [[V2TXLivePlayer alloc] init];
[self.livePlayer setObserver:self];
[self.livePlayer setRenderView:self.view];
[self.livePlayer setRenderFillMode:V2TXLiveFillModeFit];
NSString* url = [self generateUrlWithResolution:Resolution720p];
[self.livePlayer startLivePlay:url];
}
- (void)setupDefaultUIConfig {
self.title = localize(@"MLVB-API-Example.LebAutoBitrate.title");
[self.autoBitrateButton setTitle:localize(@"MLVB-API-Example.LebAutoBitrate.startAutoBitrate") forState:UIControlStateNormal];
[self.autoBitrateButton setTitle:localize(@"MLVB-API-Example.LebAutoBitrate.stopAutoBitrate") forState:UIControlStateSelected];
[self.autoBitrateButton setBackgroundColor:[UIColor themeBlueColor]];
self.autoBitrateButton.titleLabel.adjustsFontSizeToFitWidth = true;
[self.switch1080pButton setTitle:localize(@"MLVB-API-Example.LebAutoBitrate.1080p") forState:UIControlStateNormal];
[self.switch1080pButton setBackgroundColor:[UIColor themeBlueColor]];
self.switch1080pButton.titleLabel.adjustsFontSizeToFitWidth = true;
[self.switch720pButton setTitle:localize(@"MLVB-API-Example.LebAutoBitrate.720p") forState:UIControlStateNormal];
[self.switch720pButton setBackgroundColor:[UIColor themeBlueColor]];
self.switch720pButton.titleLabel.adjustsFontSizeToFitWidth = true;
[self.switch540pButton setTitle:localize(@"MLVB-API-Example.LebAutoBitrate.540p") forState:UIControlStateNormal];
[self.switch540pButton setBackgroundColor:[UIColor themeBlueColor]];
self.switch540pButton.titleLabel.adjustsFontSizeToFitWidth = true;
}
- (NSString*)generateUrlWithResolution:(PlayResolution)resolution {
NSString* baseUrl = @"webrtc://liteavapp.qcloud.com/live/liteavdemoplayerstreamid";
NSString* transcodingName = @"";
switch (resolution) {
case Resolution1080p:
transcodingName = @"demo1080p";
break;
case Resolution720p:
transcodingName = @"demo720p";
break;
case Resolution540p:
transcodingName = @"demo540p";
break;
}
return [NSString stringWithFormat:@"%@?tabr_bitrates=demo1080p,demo720p,demo540p&tabr_start_bitrate=%@",
baseUrl,transcodingName];
}
- (NSString*)generateUrlIsAutoBitrate:(BOOL)isAutoBitrate {
NSString* url = [self generateUrlWithResolution:Resolution540p];
if (isAutoBitrate) {
url = [url stringByAppendingString:@"&tabr_control=auto"];
}
return url;
}
#pragma mark - V2TXLivePlayerObserver
- (void)onVideoResolutionChanged:(id<V2TXLivePlayer>)player width:(NSInteger)width height:(NSInteger)height {
[self showAlertViewController:localize(@"MLVB-API-Example.LebAutoBitrate.tips") message:[NSString stringWithFormat:localize(@"MLVB-API-Example.LebAutoBitrate.currentResolution"), (long)width, height] handler:nil];
}
#pragma mark - Actions
- (IBAction)onAutoBitrateButtonClick:(UIButton*)sender {
sender.selected = !sender.isSelected;
if (sender.isSelected) {
[self.switch1080pButton setBackgroundColor:[UIColor themeGrayColor]];
[self.switch720pButton setBackgroundColor:[UIColor themeGrayColor]];
[self.switch540pButton setBackgroundColor:[UIColor themeGrayColor]];
[self.switch1080pButton setEnabled:false];
[self.switch720pButton setEnabled:false];
[self.switch540pButton setEnabled:false];
} else {
[self.switch1080pButton setBackgroundColor:[UIColor themeBlueColor]];
[self.switch720pButton setBackgroundColor:[UIColor themeBlueColor]];
[self.switch540pButton setBackgroundColor:[UIColor themeBlueColor]];
[self.switch1080pButton setEnabled:true];
[self.switch720pButton setEnabled:true];
[self.switch540pButton setEnabled:true];
}
NSString* url = [self generateUrlIsAutoBitrate:sender.isSelected];
[self.livePlayer stopPlay];
[self.livePlayer startLivePlay:url];
}
- (IBAction)onSwitch1080pButtonClick:(UIButton*)sender {
NSString* url = [self generateUrlWithResolution:Resolution1080p];
[self.livePlayer switchStream:url];
}
- (IBAction)onSwitch720pButtonClick:(UIButton*)sender {
NSString* url = [self generateUrlWithResolution:Resolution720p];
[self.livePlayer switchStream:url];
}
- (IBAction)onSwitch540pButtonClick:(UIButton*)sender {
NSString* url = [self generateUrlWithResolution:Resolution540p];
[self.livePlayer switchStream:url];
}
@end