delete VideoPublisherActivity.java useless for this project,because major push v…
…ideo function move to VideoPlayActivity.java.
正在显示
1 个修改的文件
包含
0 行增加
和
487 行删除
MyApplication/XdyDemo/src/main/java/com/mang/xdy/demo/activity/VideoPublisherActivity.java
已删除
100644 → 0
1 | -package com.mang.xdy.demo.activity; | ||
2 | - | ||
3 | - import android.app.AlertDialog; | ||
4 | - import android.app.Dialog; | ||
5 | - import android.content.Context; | ||
6 | - import android.content.DialogInterface; | ||
7 | - import android.media.Image; | ||
8 | - import android.os.Bundle; | ||
9 | - import android.os.Handler; | ||
10 | - import android.os.Message; | ||
11 | - import android.support.design.widget.TabLayout; | ||
12 | - import android.support.v4.view.ViewPager; | ||
13 | - import android.support.v7.app.AppCompatActivity; | ||
14 | - import android.text.TextUtils; | ||
15 | - import android.util.Log; | ||
16 | - import android.view.Gravity; | ||
17 | - import android.view.SurfaceView; | ||
18 | - import android.view.View; | ||
19 | - import android.view.Window; | ||
20 | - import android.view.WindowManager; | ||
21 | - import android.widget.Button; | ||
22 | - import android.widget.EditText; | ||
23 | - import android.widget.ImageView; | ||
24 | - import android.widget.TextView; | ||
25 | - import android.widget.Toast; | ||
26 | - | ||
27 | - import com.eventhandle.SmartEventCallback; | ||
28 | - import com.google.gson.Gson; | ||
29 | - import com.mang.xdy.common.Constants; | ||
30 | - import com.mang.xdy.core.XdySdk; | ||
31 | - import com.mang.xdy.demo.R; | ||
32 | - import com.mang.xdy.demo.adapter.SimpleFragmentPagerAdapter; | ||
33 | - import com.mang.xdy.demo.bean.AudioPlayBean; | ||
34 | - import com.mang.xdy.demo.bean.ChatBean; | ||
35 | - import com.mang.xdy.demo.bean.DocEntity; | ||
36 | - import com.mang.xdy.demo.bean.ErrorEntity; | ||
37 | - import com.mang.xdy.demo.bean.InitClassSuccessEntity; | ||
38 | - import com.mang.xdy.demo.bean.JoinClass; | ||
39 | - import com.mang.xdy.demo.bean.LiveBean; | ||
40 | - import com.mang.xdy.demo.bean.PublisherEntity; | ||
41 | - import com.mang.xdy.demo.bean.PublisherVideoExitBean; | ||
42 | - import com.mang.xdy.demo.bean.PublisherVideoReturnBean; | ||
43 | - import com.mang.xdy.demo.bean.VideoPlayBean; | ||
44 | - import com.mang.xdy.demo.utils.JsonUtil; | ||
45 | - import com.mang.xdy.demo.utils.ToastUtil; | ||
46 | - import com.mang.xdy.demo.widget.dialog.LoginDialog; | ||
47 | - import com.mang.xdy.listener.ObserverListener; | ||
48 | - import com.mang.xdy.utils.UIUtils; | ||
49 | - import com.mang.xdy.utils.XdyLogUtil; | ||
50 | - import com.mang.xdy.utils.XdyStringUtils; | ||
51 | - | ||
52 | - import butterknife.BindView; | ||
53 | - import butterknife.ButterKnife; | ||
54 | - import butterknife.OnClick; | ||
55 | - | ||
56 | -public class VideoPublisherActivity extends AppCompatActivity implements ObserverListener{ | ||
57 | - private final static String TAG = "VideoPlayActivity"; | ||
58 | - @BindView(R.id.btn_videoPlay_pubsherVideo) | ||
59 | - Button btnVideoPlayPubsherVideo; | ||
60 | - @BindView(R.id.btn_videoPlay_chat) | ||
61 | - Button btnVideoPlayChat; | ||
62 | - @BindView(R.id.tv_videoPlay_url) | ||
63 | - TextView tv_videoPlay_url; | ||
64 | - @BindView(R.id.surfaceview_pubisherVideo) | ||
65 | - SurfaceView surfaceview_pubisherVideo; | ||
66 | - @BindView(R.id.btn_videoPlay_publisherAudio) | ||
67 | - Button btn_videoPlay_publisherAudio; | ||
68 | -// @BindView(R.id.img_playVideo_novideo) | ||
69 | -// ImageView img_playVideo_novideo; | ||
70 | - private String username=""; | ||
71 | - private String userpwd=""; | ||
72 | - private PersonDialog personDialog; | ||
73 | - private SimpleFragmentPagerAdapter pagerAdapter; | ||
74 | - private XdySdk xdySdk; | ||
75 | - private ViewPager viewPager; | ||
76 | - //默认推送视频 | ||
77 | - private boolean isPusherAudio=false; | ||
78 | - /*默认是可以退出的,如果进行推流则需要主动退出*/ | ||
79 | - private boolean isAbleback=false; | ||
80 | - private TabLayout tabLayout; | ||
81 | - @BindView(R.id.surfaceview_playVideo) | ||
82 | - SurfaceView surfaceviewPlayVideo; | ||
83 | - @BindView(R.id.btn_videoPlay_stop) | ||
84 | - Button btn_videoPlay_stop; | ||
85 | - private String initClass = ""; | ||
86 | - private String publisherSuccess=""; | ||
87 | - /*视频成功返回值*/ | ||
88 | - private PublisherVideoReturnBean publisherVideoReturnBean; | ||
89 | - private Handler handler = new Handler() { | ||
90 | - @Override | ||
91 | - public void handleMessage(Message msg) { | ||
92 | - super.handleMessage(msg); | ||
93 | - switch (msg.what) { | ||
94 | - case -2: | ||
95 | - //加入课堂输入用户名,密码 | ||
96 | - joinClass("", (Boolean) msg.obj); | ||
97 | - break; | ||
98 | - case -1: | ||
99 | - //退出 | ||
100 | - // xdySdk.api("leaveClass", ""); | ||
101 | - break; | ||
102 | - case 0: | ||
103 | - parseJoinClass((String) msg.obj,true); | ||
104 | - break; | ||
105 | - case 7: | ||
106 | - break; | ||
107 | - case 8: | ||
108 | - btnVideoPlayPubsherVideo.setEnabled(true); | ||
109 | - btn_videoPlay_publisherAudio.setEnabled(true); | ||
110 | - break; | ||
111 | - | ||
112 | - } | ||
113 | - } | ||
114 | - }; | ||
115 | - | ||
116 | - @Override | ||
117 | - protected void onCreate(final Bundle savedInstanceState) { | ||
118 | - super.onCreate(savedInstanceState); | ||
119 | - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //屏幕常亮 | ||
120 | - setContentView(R.layout.activity_video_publisher); | ||
121 | - ButterKnife.bind(this); | ||
122 | - btn_videoPlay_publisherAudio.setVisibility(View.GONE); | ||
123 | -// setTablayout(); | ||
124 | - xdySdk=XdySdk.getXdyInstance(); | ||
125 | - xdySdk.add(this); | ||
126 | - init(); | ||
127 | - XdyLogUtil.e(TAG,"当前线程 main:"+android.os.Process.myPid()+"线程:"+Thread.currentThread().getId()+""); | ||
128 | - xdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() { | ||
129 | - @Override | ||
130 | - public void onXdyAsyncMessageReceiver(String type, String response) { | ||
131 | - | ||
132 | - switch (type) { | ||
133 | - case "class_init_success": | ||
134 | - ToastUtil.showToastshort("初始化课堂成功", VideoPublisherActivity.this); | ||
135 | - Message message = Message.obtain(); | ||
136 | - message.obj = response; | ||
137 | - message.what = 0; | ||
138 | - handler.sendMessage(message); | ||
139 | - break; | ||
140 | - case "class_join_success": | ||
141 | - //加入课堂成功 | ||
142 | - UIUtils.closeDialog(mLoginDialog); | ||
143 | - ToastUtil.showToastshort("加入课堂成功", VideoPublisherActivity.this); | ||
144 | - //只有加入课堂成功才可以点击推流的按钮 | ||
145 | - handler.sendEmptyMessage(8); | ||
146 | - break; | ||
147 | - case "video_stop": | ||
148 | -// handler.sendEmptyMessage(7); | ||
149 | - break; | ||
150 | - case "audio_stop": | ||
151 | - | ||
152 | - break; | ||
153 | - } | ||
154 | - XdyLogUtil.e(TAG,"type:"+type+" response:"+response); | ||
155 | - } | ||
156 | - }); | ||
157 | - } | ||
158 | - | ||
159 | - public void init() { | ||
160 | - initClass = getIntent().getStringExtra("init"); | ||
161 | - xdySdk.api("init", initClass); | ||
162 | - | ||
163 | - } | ||
164 | -private LoginDialog mLoginDialog; | ||
165 | - //判断解析是否有密码 | ||
166 | - public void parseJoinClass(String rsponse,boolean isShowPwd){ | ||
167 | - InitClassSuccessEntity initClassSuccessEntity=JsonUtil.parseJsonToBean(rsponse,InitClassSuccessEntity.class); | ||
168 | - if(initClassSuccessEntity!=null) { | ||
169 | - if (initClassSuccessEntity.isPasswordRequired()) { | ||
170 | - isShowPwd=true; | ||
171 | - } else { | ||
172 | - isShowPwd=false; | ||
173 | - userpwd = "123321"; | ||
174 | - } | ||
175 | - } | ||
176 | - | ||
177 | - if (mLoginDialog == null) { | ||
178 | - mLoginDialog = new LoginDialog(this, isShowPwd, null); | ||
179 | - mLoginDialog.show(); | ||
180 | - mLoginDialog.setCanceledOnTouchOutside(false); | ||
181 | - final boolean finalIsShowPwd = isShowPwd; | ||
182 | - mLoginDialog.setBtnClick(new View.OnClickListener() { | ||
183 | - @Override | ||
184 | - public void onClick(View view) { | ||
185 | - String[] nameAndPwd = mLoginDialog.getNameAndPwd(); | ||
186 | - joinClass(nameAndPwd[0], nameAndPwd[1], finalIsShowPwd); | ||
187 | - } | ||
188 | - }); | ||
189 | - }else if (mLoginDialog != null) { | ||
190 | - UIUtils.closeDialog(mLoginDialog); | ||
191 | - } | ||
192 | - } | ||
193 | - //加入课堂 | ||
194 | - public void joinClass(String username,String userpwd,boolean isShowPwd) { | ||
195 | - JoinClass joinClass=new JoinClass(); | ||
196 | - joinClass.setHasCamera(false); | ||
197 | - joinClass.setHasMicrophone(false); | ||
198 | - joinClass.setUserName(username); | ||
199 | - if(!isShowPwd){ | ||
200 | - joinClass.setPassword("123321"); | ||
201 | - }else{ | ||
202 | - joinClass.setPassword(userpwd); | ||
203 | - } | ||
204 | - String temp=new Gson().toJson(joinClass); | ||
205 | - String jsonParmp = XdyStringUtils.stringToJson(temp, true); | ||
206 | - XdyLogUtil.e("加入课堂", jsonParmp); | ||
207 | - xdySdk.api("joinClass", jsonParmp); | ||
208 | - } | ||
209 | - | ||
210 | - //加入课堂 | ||
211 | - public void joinClass(String rsponse,boolean isShowPwd) { | ||
212 | - | ||
213 | -// String temp = "{\n" + | ||
214 | -// " \"userName\":\"base\",\n" + | ||
215 | -// " \"password\":\"123321\",\n" + | ||
216 | -// " \"hasCamera\":false,\n" + | ||
217 | -// " \"hasMicrophone\":false}"; | ||
218 | - JoinClass joinClass=new JoinClass(); | ||
219 | - joinClass.setHasCamera(false); | ||
220 | - joinClass.setHasMicrophone(false); | ||
221 | - joinClass.setUserName(username); | ||
222 | - if(!isShowPwd){ | ||
223 | - joinClass.setPassword("123321"); | ||
224 | - }else{ | ||
225 | - joinClass.setPassword(userpwd); | ||
226 | - } | ||
227 | - String temp=new Gson().toJson(joinClass); | ||
228 | - String jsonParmp = XdyStringUtils.stringToJson(temp, true); | ||
229 | - XdyLogUtil.e("加入课堂", jsonParmp); | ||
230 | - xdySdk.api("joinClass", jsonParmp); | ||
231 | - } | ||
232 | - | ||
233 | - | ||
234 | - | ||
235 | - public void sendMeg() { | ||
236 | - String temp = "{\n" + | ||
237 | - " \"message\": \"固定发送测试 hello\",\n" + | ||
238 | - " \"to\": 0\n" + | ||
239 | - "}"; | ||
240 | - String jsonParmp = XdyStringUtils.stringToJson(temp, true); | ||
241 | - XdyLogUtil.e(TAG, "聊天" + jsonParmp); | ||
242 | - xdySdk.api("sendChatMsg", jsonParmp); | ||
243 | - | ||
244 | - } | ||
245 | - | ||
246 | - /** | ||
247 | - * 获取封装的推流地址 | ||
248 | - */ | ||
249 | - public void publisherVideoText(){ | ||
250 | - xdySdk.api("publishVideo", "", surfaceview_pubisherVideo, VideoPublisherActivity.this); | ||
251 | -// xdySdk.api(Constants.PUBLISH_AUDIO, "", surfaceview_pubisherVideo, VideoPublisherActivity.this); | ||
252 | - | ||
253 | - } | ||
254 | - | ||
255 | - @Override | ||
256 | - protected void onPause() { | ||
257 | - super.onPause(); | ||
258 | - xdySdk.onPublisherPause(); | ||
259 | - } | ||
260 | - | ||
261 | - @Override | ||
262 | - protected void onResume() { | ||
263 | - super.onResume(); | ||
264 | - xdySdk.onPublisherResume(); | ||
265 | - } | ||
266 | - | ||
267 | - @Override | ||
268 | - protected void onDestroy() { | ||
269 | - xdySdk.onPublisherStop(); | ||
270 | - super.onDestroy(); | ||
271 | - } | ||
272 | - | ||
273 | - @OnClick({R.id.btn_videoPlay_chat, R.id.btn_videoPlay_pubsherVideo,R.id.btn_videoPlay_publisherAudio,R.id.btn_videoPlay_stop}) | ||
274 | - public void onViewClicked(View view) { | ||
275 | - switch (view.getId()) { | ||
276 | - case R.id.btn_videoPlay_chat: | ||
277 | - handler.sendEmptyMessage(4); | ||
278 | - break; | ||
279 | - case R.id.btn_videoPlay_pubsherVideo: | ||
280 | -// getPublish(); | ||
281 | - publisherVideoText(); | ||
282 | -// publisherAudioText(); | ||
283 | - ToastUtil.showToastshort("推送视频",VideoPublisherActivity.this); | ||
284 | - btnVideoPlayPubsherVideo.setClickable(false); | ||
285 | - | ||
286 | - break; | ||
287 | - case R.id.btn_videoPlay_stop: | ||
288 | - ToastUtil.showToastshort("正在退出,请稍等",this); | ||
289 | - xdySdk.api("unPublishVideo",""); | ||
290 | -// finish(); | ||
291 | - break; | ||
292 | - } | ||
293 | - } | ||
294 | - | ||
295 | - @Override | ||
296 | - public void observerUpData(final String type, final String parameter) { | ||
297 | - handler.post(new Runnable() { | ||
298 | - @Override | ||
299 | - public void run() { | ||
300 | - handError(type,parameter); | ||
301 | - } | ||
302 | - }); | ||
303 | - } | ||
304 | - public void handError(String errorId, String errorMsg) { | ||
305 | - ErrorEntity errorEntity = JsonUtil.parseJsonToBean(errorMsg, ErrorEntity.class); | ||
306 | - if (errorEntity == null) { | ||
307 | - return; | ||
308 | - } | ||
309 | - switch (errorEntity.getCode() + "") { | ||
310 | - case "100": | ||
311 | - case "101": | ||
312 | - case "102": | ||
313 | - case "103": | ||
314 | - case "104": | ||
315 | - case "105": | ||
316 | - case "106": | ||
317 | - case "107": | ||
318 | - case "200": | ||
319 | - case "201": | ||
320 | - case "202": | ||
321 | - case "203": | ||
322 | - case "204": | ||
323 | - case "205": | ||
324 | - case "206": | ||
325 | - case "207": | ||
326 | - case "208": | ||
327 | - ToastUtil.showToastshort(errorEntity.getReson(), this); | ||
328 | - exit(); | ||
329 | - break; | ||
330 | - case "300": | ||
331 | - case "301": | ||
332 | - break; | ||
333 | - case "10000": | ||
334 | - ToastUtil.showToastshort(errorEntity.getReson(), this); | ||
335 | - break; | ||
336 | - case "10001": | ||
337 | - ToastUtil.showToastshort(errorEntity.getReson(), this); | ||
338 | - break; | ||
339 | - case "20000": | ||
340 | - isDefaultExit=false; | ||
341 | - showErrorDialog(); | ||
342 | - ToastUtil.showToastshort(errorEntity.getReson(), this); | ||
343 | - break; | ||
344 | - } | ||
345 | - | ||
346 | - | ||
347 | - } | ||
348 | - | ||
349 | - class EventHande implements SmartEventCallback { | ||
350 | - @Override | ||
351 | - public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) { | ||
352 | - switch (code) { | ||
353 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED: | ||
354 | - Log.i(TAG, "开始。。"); | ||
355 | - break; | ||
356 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING: | ||
357 | - Log.i(TAG, "连接中。。"); | ||
358 | - break; | ||
359 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED: | ||
360 | - Log.i(TAG, "连接失败。。"); | ||
361 | - break; | ||
362 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED: | ||
363 | - Log.i(TAG, "连接成功。。"); | ||
364 | -// PublisherEntity publisherEntity=new PublisherEntity(); | ||
365 | -// if(TextUtils.isEmpty(publisherSuccess)) { | ||
366 | -// publisherEntity.setPublishUrl(publisherSuccess); | ||
367 | -// XdySdk.setAsyncApi("publishVideo", new Gson().toJson(publisherEntity)); | ||
368 | -// } | ||
369 | - //TODO | ||
370 | - break; | ||
371 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED: | ||
372 | - Log.i(TAG, "连接断开。。"); | ||
373 | - break; | ||
374 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP: | ||
375 | - Log.i(TAG, "关闭。。"); | ||
376 | - break; | ||
377 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO: | ||
378 | - Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2); | ||
379 | - break; | ||
380 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED: | ||
381 | - Log.i(TAG, "收不到媒体数据,可能是url错误。。"); | ||
382 | - } | ||
383 | - | ||
384 | - } | ||
385 | - } | ||
386 | - /*mcu断开或者网络原因为false*/ | ||
387 | - private boolean isDefaultExit=true; | ||
388 | - private android.support.v7.app.AlertDialog mErrorDialog; | ||
389 | - public void showErrorDialog() { | ||
390 | -// if(isDefaultExit){ | ||
391 | -// return; | ||
392 | -// } | ||
393 | - if (mErrorDialog != null) | ||
394 | - return; | ||
395 | - | ||
396 | - mErrorDialog = new android.support.v7.app.AlertDialog.Builder(this) | ||
397 | - .setTitle("退出") | ||
398 | - .setMessage("您设备的网络属于断开状态,请重新进入") | ||
399 | - .setPositiveButton("确认", new DialogInterface.OnClickListener() { | ||
400 | - @Override | ||
401 | - public void onClick(DialogInterface dialogInterface, int i) { | ||
402 | - dialogInterface.dismiss(); | ||
403 | - exit(); | ||
404 | - } | ||
405 | - }) | ||
406 | - .create(); | ||
407 | - mErrorDialog.setCanceledOnTouchOutside(false); | ||
408 | - | ||
409 | - mErrorDialog.show(); | ||
410 | - | ||
411 | - } | ||
412 | - | ||
413 | - /** | ||
414 | - * 错误情况退出 | ||
415 | - */ | ||
416 | - public void exit() { | ||
417 | - | ||
418 | - UIUtils.closeDialog(mLoginDialog); | ||
419 | -// xdySdk.onPublisherStop(); | ||
420 | - xdySdk.remove(this); | ||
421 | - handler.removeCallbacksAndMessages(null); | ||
422 | - this.finish(); | ||
423 | - } | ||
424 | - class PersonDialog extends Dialog { | ||
425 | - public PersonDialog(Context context) { | ||
426 | - this(context, false); | ||
427 | - | ||
428 | - } | ||
429 | - | ||
430 | - public PersonDialog(Context context, boolean showPwd) { | ||
431 | - this(context, R.style.bottom_dialog, showPwd); | ||
432 | - } | ||
433 | - | ||
434 | - public PersonDialog(Context context, int themeResId, boolean showPwd) { | ||
435 | - super(context, themeResId); | ||
436 | - init(context, showPwd); | ||
437 | - } | ||
438 | - | ||
439 | - public void init(Context context, boolean showPwd) { | ||
440 | - View view = View.inflate(context, R.layout.dialog_item, null); | ||
441 | - setContentView(view); | ||
442 | - initView(view,showPwd); | ||
443 | - setCanceledOnTouchOutside(false); | ||
444 | - Window window = getWindow(); | ||
445 | - WindowManager.LayoutParams params = window.getAttributes(); | ||
446 | - params.width = WindowManager.LayoutParams.MATCH_PARENT; | ||
447 | - params.height = dp2px(context, 220); | ||
448 | - window.setAttributes(params); | ||
449 | - window.setGravity(Gravity.CENTER); | ||
450 | - } | ||
451 | - | ||
452 | - public int dp2px(Context context, float dp) { | ||
453 | - return (int) Math.ceil(context.getResources().getDisplayMetrics().density * dp); | ||
454 | - } | ||
455 | - public void initView(View view, final boolean showPwd){ | ||
456 | - final EditText edt_uername= (EditText) view.findViewById(R.id.dialog_edt_username); | ||
457 | - final EditText edt_userpwd= (EditText) view.findViewById(R.id.dialog_edt_userpwd); | ||
458 | - if(showPwd){ | ||
459 | - edt_userpwd.setVisibility(View.VISIBLE); | ||
460 | - }else{ | ||
461 | - edt_userpwd.setVisibility(View.GONE); | ||
462 | - } | ||
463 | - Button btn_enter= (Button) view.findViewById(R.id.dialog_btn_enter); | ||
464 | - btn_enter.setOnClickListener(new View.OnClickListener() { | ||
465 | - @Override | ||
466 | - public void onClick(View v) { | ||
467 | - username=edt_uername.getText().toString(); | ||
468 | - userpwd=edt_userpwd.getText().toString(); | ||
469 | - if(TextUtils.isEmpty(username)){ | ||
470 | - ToastUtil.showToastshort("用户名不能为空",VideoPublisherActivity.this); | ||
471 | - return; | ||
472 | - } | ||
473 | - if(showPwd&&TextUtils.isEmpty(userpwd)){ | ||
474 | - ToastUtil.showToastshort("密码不能为空",VideoPublisherActivity.this); | ||
475 | - return; | ||
476 | - } | ||
477 | - dismiss(); | ||
478 | - Message message=Message.obtain(); | ||
479 | - message.what=-2; | ||
480 | - message.obj=showPwd; | ||
481 | - handler.sendMessage(message); | ||
482 | - } | ||
483 | - }); | ||
484 | - } | ||
485 | - } | ||
486 | - | ||
487 | -} |
-
请 注册 或 登录 后发表评论