forked from daniulive/SmarterStreaming
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathViewController.m
More file actions
335 lines (261 loc) · 9.76 KB
/
Copy pathViewController.m
File metadata and controls
335 lines (261 loc) · 9.76 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
//
// ViewController.m
// SmartiOSPlayer
//
// GitHub: https://github.com/daniulive/SmarterStreaming
//
// Created by daniulive on 16/01/03.
// Copyright © 2016年 daniulive. All rights reserved.
#import "ViewController.h"
#import "SettingView.h"
#define kBtnHeight 50
#define kHorMargin 10
#define kVerMargin 80
@interface ViewController ()
@end
@implementation ViewController
{
NSString *_streamUrl;
Boolean is_half_screen_;
SmartPlayerSDK * _player;
UIView * _glView;
NSString *copyRights;
UILabel *textModeLabel; //文字提示
Boolean is_audio_only_;
Boolean is_hardware_decoder_; //默认软解码
Boolean is_rtsp_tcp_mode_; //仅用于rtsp流,设置TCP传输模式
NSInteger screenWidth;
NSInteger screenHeight;
NSInteger playerHeight;
Boolean is_mute; //静音接口
UIButton *backSettingsButton; //返回按钮
UILabel *backSettingLable; //返回按钮 lable
UIButton *muteButton; //静音 取消静音
}
- (NSInteger) handleSmartPlayerEvent:(NSInteger)nID param1:(unsigned long long)param1 param2:(unsigned long long)param2 param3:(NSString*)param3 param4:(NSString*)param4 pObj:(void *)pObj;
{
if (nID == EVENT_DANIULIVE_ERC_PLAYER_STARTED) {
NSLog(@"[event]开始播放..");
}
else if (nID == EVENT_DANIULIVE_ERC_PLAYER_CONNECTING)
{
NSLog(@"[event]连接中..");
}
else if (nID == EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED)
{
NSLog(@"[event]连接失败..");
}
else if (nID == EVENT_DANIULIVE_ERC_PLAYER_CONNECTED)
{
NSLog(@"[event]已连接..");
}
else if (nID == EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED)
{
NSLog(@"[event]断开连接..");
}
else if (nID == EVENT_DANIULIVE_ERC_PLAYER_STOP)
{
NSLog(@"[event]停止播放..");
}
else if (nID == EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO)
{
NSLog(@"[event]视频解码分辨率信息..width:%llu, height:%llu", param1, param2);
}
else if (nID == EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED)
{
NSLog(@"[event]收不到RTMP数据..");
}
else
NSLog(@"[event]nID:%lx", (long)nID);
return 0;
}
- (instancetype)initParameter:(NSString*)url isHalfScreen:(Boolean)isHalfScreenVal isAudioOnly:(Boolean)isAudioOnly
isHWDecoder:(Boolean)isHWDecoder isRTSPTcpMode:(Boolean)isRTSPTcpMode
{
self = [super init];
if (!self) {
return nil;
}
else if(self) {
_streamUrl = url;
is_half_screen_ = isHalfScreenVal;
is_audio_only_ = isAudioOnly;
is_hardware_decoder_ = isHWDecoder;
is_rtsp_tcp_mode_ = isRTSPTcpMode;
}
return self;
}
- (void)loadView
{
copyRights = @"Copyright 2014~2016 www.daniulive.com v1.0.16.1205";
is_mute = NO;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChange:)name:UIDeviceOrientationDidChangeNotification object:nil];
//当前屏幕宽高
screenWidth = CGRectGetWidth([UIScreen mainScreen].bounds);
screenHeight = CGRectGetHeight([UIScreen mainScreen].bounds);
playerHeight = screenHeight;
if ( is_half_screen_ )
playerHeight = screenWidth*3/4;
NSLog(@"screenWidth:%ld, screenHeight:%ld",(long)screenWidth, (long)screenHeight);
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
_player = [[SmartPlayerSDK alloc] init];
if (_player ==nil ) {
NSLog(@"SmartPlayerSDK init failed..");
return;
}
if (_player.delegate == nil)
{
_player.delegate = self;
NSLog(@"SmartPlayerSDK _player.delegate:%@", _player);
}
NSString* sdkVersion = [_player SmartPlayerGetSDKVersionID];
NSLog(@"sdk version:%@",sdkVersion);
NSInteger initRet = [_player SmartPlayerInitPlayer];
if ( initRet != DANIULIVE_RETURN_OK )
{
NSLog(@"SmartPlayerSDK call SmartPlayerInitPlayer failed, ret=%ld", (long)initRet);
return;
}
NSInteger videoDecoderMode = 0;
if (is_hardware_decoder_)
{
videoDecoderMode = 1;
}
[_player SmartPlayerSetVideoDecoderMode:videoDecoderMode];
if (is_audio_only_) {
[_player SmartPlayerSetPlayView:nil];
}
else
{
_glView = (__bridge UIView *)([SmartPlayerSDK SmartPlayerCreatePlayView:0 y:0 width:screenWidth height:playerHeight]);
if (_glView == nil ) {
NSLog(@"createPlayView failed..");
return;
}
[self.view addSubview:_glView];
[_player SmartPlayerSetPlayView:(__bridge void *)(_glView)];
}
if (_streamUrl.length == 0) {
NSLog(@"_streamUrl with nil..");
return;
}
NSInteger bufferTime = 200;
[_player SmartPlayerSetBuffer:bufferTime];
NSLog(@"playback URL: %@", _streamUrl);
[_player SmartPlayerSetPlayURL:_streamUrl];
[_player SmartPlayerSetRTSPTcpMode:is_rtsp_tcp_mode_];
[_player SmartPlayerStart];
CGFloat lineWidth = muteButton.frame.size.width * 0.12f;
//muteButton
muteButton = [UIButton buttonWithType:UIButtonTypeCustom];
muteButton.frame = CGRectMake(45, playerHeight - 200, 120, 80);
muteButton.center = CGPointMake(self.view.frame.size.width / 6, muteButton.frame.origin.y + muteButton.frame.size.height / 2);
muteButton.layer.cornerRadius = muteButton.frame.size.width / 2;
muteButton.layer.borderColor = [UIColor greenColor].CGColor;
muteButton.layer.borderWidth = lineWidth;
[muteButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[muteButton setTitle:@"静音" forState:UIControlStateNormal];
[muteButton addTarget:self action:@selector(MuteBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:muteButton];
//muteButton
backSettingsButton = [UIButton buttonWithType:UIButtonTypeCustom];
backSettingsButton.frame = CGRectMake(45, playerHeight - 80, 120, 80);
backSettingsButton.center = CGPointMake(self.view.frame.size.width / 6, backSettingsButton.frame.origin.y + backSettingsButton.frame.size.height / 2);
backSettingsButton.layer.cornerRadius = muteButton.frame.size.width / 2;
backSettingsButton.layer.borderColor = [UIColor greenColor].CGColor;
backSettingsButton.layer.borderWidth = lineWidth;
[backSettingsButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[backSettingsButton setTitle:@"返回" forState:UIControlStateNormal];
[backSettingsButton addTarget:self action:@selector(backSettingsBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backSettingsButton];
// 创建文字提示 UILable
textModeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, 50)];
// 设置UILabel的背景色
textModeLabel.backgroundColor = [UIColor clearColor];
// 设置UILabel的文本颜色
textModeLabel.textColor = [UIColor colorWithRed:1.0 green:0.0
blue:1.0 alpha:1.0];
textModeLabel.adjustsFontSizeToFitWidth = YES;
NSString *str = @"欢迎使用SmartPlayer, ";
textModeLabel.text = [str stringByAppendingString:copyRights];
[self.view addSubview:textModeLabel];
}
- (void)MuteBtn:(id)sender {
if ( _player != nil )
{
is_mute = !is_mute;
if ( is_mute )
{
[muteButton setTitle:@"取消静音" forState:UIControlStateNormal];
}
else
{
[muteButton setTitle:@"静音" forState:UIControlStateNormal];
}
[_player SmartPlayerSetMute:is_mute];
}
}
- (void)backSettingsBtn:(UIButton *)button
{
NSLog(@"Run into backSettingsBtn..");
if (_player != nil)
{
[_player SmartPlayerStop];
[_player SmartPlayerUnInitPlayer];
//[_player release];
_player = nil;
}
if (!is_audio_only_) {
if (_glView != nil) {
[_glView removeFromSuperview];
[SmartPlayerSDK SmartPlayeReleasePlayView:(__bridge void *)(_glView)];
_glView = nil;
}
}
//返回设置分辨率页面
SettingView * settingView =[[SettingView alloc] init];
[self presentViewController:settingView animated:YES completion:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)orientChange:(NSNotification *)noti
{
UIDeviceOrientation orient = [UIDevice currentDevice].orientation;
NSLog(@"[orgientChange] orient:%ld" ,(long)orient);
Boolean isPortrait = false;
switch (orient)
{
case UIDeviceOrientationPortrait:
isPortrait = true;
break;
case UIDeviceOrientationLandscapeLeft:
isPortrait = false;
break;
case UIDeviceOrientationPortraitUpsideDown:
isPortrait = false;
break;
case UIDeviceOrientationLandscapeRight:
isPortrait = false;
break;
default:
break;
}
CGRect f = _glView.frame;
if (isPortrait) {
f.size.width = screenWidth;
f.size.height = playerHeight;
}
else
{
f.size.width = screenHeight;
f.size.height = screenWidth;
}
_glView.frame = f;
}
@end