add xdysdk for push onPause() and resume().
modify package for push and play.
正在显示
14 个修改的文件
包含
197 行增加
和
823 行删除
@@ -53,4 +53,5 @@ dependencies { | @@ -53,4 +53,5 @@ dependencies { | ||
53 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' | 53 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' |
54 | compile 'com.qiniu:happy-dns:0.2.+' | 54 | compile 'com.qiniu:happy-dns:0.2.+' |
55 | compile 'org.greenrobot:eventbus:3.0.0' | 55 | compile 'org.greenrobot:eventbus:3.0.0' |
56 | + compile 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar' | ||
56 | } | 57 | } |
1 | package com.mang.xdy.demo.activity; | 1 | package com.mang.xdy.demo.activity; |
2 | ; | 2 | ; |
3 | -import android.Manifest; | ||
4 | import android.annotation.SuppressLint; | 3 | import android.annotation.SuppressLint; |
5 | import android.app.ProgressDialog; | 4 | import android.app.ProgressDialog; |
6 | import android.content.DialogInterface; | 5 | import android.content.DialogInterface; |
7 | -import android.content.pm.PackageManager; | ||
8 | import android.os.Bundle; | 6 | import android.os.Bundle; |
9 | import android.os.Handler; | 7 | import android.os.Handler; |
10 | import android.os.Message; | 8 | import android.os.Message; |
11 | import android.support.design.widget.TabLayout; | 9 | import android.support.design.widget.TabLayout; |
12 | -import android.support.v4.app.ActivityCompat; | ||
13 | -import android.support.v4.content.PermissionChecker; | ||
14 | import android.support.v7.app.AlertDialog; | 10 | import android.support.v7.app.AlertDialog; |
15 | import android.support.v7.app.AppCompatActivity; | 11 | import android.support.v7.app.AppCompatActivity; |
16 | import android.text.TextUtils; | 12 | import android.text.TextUtils; |
@@ -25,13 +21,14 @@ import android.widget.ImageView; | @@ -25,13 +21,14 @@ import android.widget.ImageView; | ||
25 | import android.widget.RelativeLayout; | 21 | import android.widget.RelativeLayout; |
26 | import android.widget.SeekBar; | 22 | import android.widget.SeekBar; |
27 | import android.widget.TextView; | 23 | import android.widget.TextView; |
28 | -import android.widget.Toast; | ||
29 | 24 | ||
25 | +import com.flyco.tablayout.SlidingTabLayout; | ||
26 | +import com.flyco.tablayout.listener.OnTabSelectListener; | ||
30 | import com.google.gson.Gson; | 27 | import com.google.gson.Gson; |
31 | import com.mang.xdy.bean.VideoPlayBean; | 28 | import com.mang.xdy.bean.VideoPlayBean; |
32 | import com.mang.xdy.cache.ACache; | 29 | import com.mang.xdy.cache.ACache; |
33 | import com.mang.xdy.common.Constants; | 30 | import com.mang.xdy.common.Constants; |
34 | -import com.mang.xdy.core.SPUtil; | 31 | +import com.mang.xdy.utils.SPUtil; |
35 | import com.mang.xdy.core.XdySdk; | 32 | import com.mang.xdy.core.XdySdk; |
36 | import com.mang.xdy.demo.R; | 33 | import com.mang.xdy.demo.R; |
37 | import com.mang.xdy.demo.adapter.SimpleFragmentPagerAdapter; | 34 | import com.mang.xdy.demo.adapter.SimpleFragmentPagerAdapter; |
@@ -46,6 +43,7 @@ import com.mang.xdy.demo.utils.ToastUtil; | @@ -46,6 +43,7 @@ import com.mang.xdy.demo.utils.ToastUtil; | ||
46 | import com.mang.xdy.demo.widget.dialog.LoginDialog; | 43 | import com.mang.xdy.demo.widget.dialog.LoginDialog; |
47 | import com.mang.xdy.demo.widget.view.NoScrollViewPager; | 44 | import com.mang.xdy.demo.widget.view.NoScrollViewPager; |
48 | import com.mang.xdy.listener.ObserverListener; | 45 | import com.mang.xdy.listener.ObserverListener; |
46 | +import com.mang.xdy.utils.SystemUtils; | ||
49 | import com.mang.xdy.utils.UIUtils; | 47 | import com.mang.xdy.utils.UIUtils; |
50 | import com.mang.xdy.utils.XdyLogUtil; | 48 | import com.mang.xdy.utils.XdyLogUtil; |
51 | import com.mang.xdy.utils.XdyStringUtils; | 49 | import com.mang.xdy.utils.XdyStringUtils; |
@@ -54,6 +52,8 @@ import com.pili.pldroid.player.PLMediaPlayer; | @@ -54,6 +52,8 @@ import com.pili.pldroid.player.PLMediaPlayer; | ||
54 | import com.pili.pldroid.player.widget.PLVideoTextureView; | 52 | import com.pili.pldroid.player.widget.PLVideoTextureView; |
55 | import com.pili.pldroid.player.widget.PLVideoView; | 53 | import com.pili.pldroid.player.widget.PLVideoView; |
56 | import org.greenrobot.eventbus.EventBus; | 54 | import org.greenrobot.eventbus.EventBus; |
55 | +import org.greenrobot.eventbus.Subscribe; | ||
56 | +import org.greenrobot.eventbus.ThreadMode; | ||
57 | import org.json.JSONException; | 57 | import org.json.JSONException; |
58 | import org.json.JSONObject; | 58 | import org.json.JSONObject; |
59 | 59 | ||
@@ -103,8 +103,13 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | @@ -103,8 +103,13 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | ||
103 | ImageView mImageView_Back; | 103 | ImageView mImageView_Back; |
104 | @BindView(R.id.tv_videoPlay_className) | 104 | @BindView(R.id.tv_videoPlay_className) |
105 | TextView mTextView_ClassName; | 105 | TextView mTextView_ClassName; |
106 | + @BindView(R.id.stl_videoPlay_tab) | ||
107 | + SlidingTabLayout mSlidingTab; | ||
106 | /*课堂名字*/ | 108 | /*课堂名字*/ |
107 | private String className; | 109 | private String className; |
110 | + /*课堂类型*/ | ||
111 | + private int classType=1; | ||
112 | + private String[] titles; | ||
108 | private Handler mmHandler = new Handler() { | 113 | private Handler mmHandler = new Handler() { |
109 | @Override | 114 | @Override |
110 | public void handleMessage(Message msg) { | 115 | public void handleMessage(Message msg) { |
@@ -137,6 +142,8 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | @@ -137,6 +142,8 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | ||
137 | jsonObject = new JSONObject(userJson); | 142 | jsonObject = new JSONObject(userJson); |
138 | seek = jsonObject.optLong("recordPlaybackMaxTime"); | 143 | seek = jsonObject.optLong("recordPlaybackMaxTime"); |
139 | className=jsonObject.optString("className"); | 144 | className=jsonObject.optString("className"); |
145 | + classType=jsonObject.optInt("classType"); | ||
146 | + | ||
140 | } catch (JSONException e) { | 147 | } catch (JSONException e) { |
141 | e.printStackTrace(); | 148 | e.printStackTrace(); |
142 | } | 149 | } |
@@ -145,8 +152,13 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | @@ -145,8 +152,13 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | ||
145 | } | 152 | } |
146 | if(replay) { | 153 | if(replay) { |
147 | initRecordSeek(userJson); | 154 | initRecordSeek(userJson); |
155 | + }else { | ||
156 | + if (classType == 1) { | ||
157 | + img_videoPlay_start.setVisibility(View.GONE); | ||
158 | + } else { | ||
159 | + img_videoPlay_start.setVisibility(View.VISIBLE); | ||
160 | + } | ||
148 | } | 161 | } |
149 | - | ||
150 | break; | 162 | break; |
151 | case Constants.VIDEO_PLAY: | 163 | case Constants.VIDEO_PLAY: |
152 | //播放视频 | 164 | //播放视频 |
@@ -188,6 +200,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | @@ -188,6 +200,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | ||
188 | super.onCreate(savedInstanceState); | 200 | super.onCreate(savedInstanceState); |
189 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //屏幕常亮 | 201 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //屏幕常亮 |
190 | setContentView(R.layout.activity_video_play); | 202 | setContentView(R.layout.activity_video_play); |
203 | + EventBus.getDefault().register(this); | ||
191 | ButterKnife.bind(this); | 204 | ButterKnife.bind(this); |
192 | aCache=ACache.get(this); | 205 | aCache=ACache.get(this); |
193 | xdySdk = XdySdk.getXdyInstance(); | 206 | xdySdk = XdySdk.getXdyInstance(); |
@@ -212,7 +225,6 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | @@ -212,7 +225,6 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | ||
212 | if(!replay){ | 225 | if(!replay){ |
213 | mVideoView.setVisibility(View.GONE); | 226 | mVideoView.setVisibility(View.GONE); |
214 | mMediaContainer.setVisibility(View.GONE); | 227 | mMediaContainer.setVisibility(View.GONE); |
215 | - img_videoPlay_start.setVisibility(View.VISIBLE); | ||
216 | // btn_videoPlay_stopPublish.setVisibility(View.VISIBLE); | 228 | // btn_videoPlay_stopPublish.setVisibility(View.VISIBLE); |
217 | }else{ | 229 | }else{ |
218 | surfaceviewPlayVideo.setVisibility(View.GONE); | 230 | surfaceviewPlayVideo.setVisibility(View.GONE); |
@@ -246,6 +258,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | @@ -246,6 +258,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | ||
246 | img_videoPlay_start.setEnabled(false); | 258 | img_videoPlay_start.setEnabled(false); |
247 | btn_videoPlay_stopPublish.setEnabled(true); | 259 | btn_videoPlay_stopPublish.setEnabled(true); |
248 | sh = surfaceView_publish.getHolder(); | 260 | sh = surfaceView_publish.getHolder(); |
261 | + sh.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); | ||
249 | surfaceView_publish.setZOrderMediaOverlay(true); | 262 | surfaceView_publish.setZOrderMediaOverlay(true); |
250 | xdySdk.api("publishVideo", "", surfaceView_publish, VideoPlayActivity.this); | 263 | xdySdk.api("publishVideo", "", surfaceView_publish, VideoPlayActivity.this); |
251 | isVideoMode=true; | 264 | isVideoMode=true; |
@@ -260,13 +273,37 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | @@ -260,13 +273,37 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | ||
260 | }); | 273 | }); |
261 | } | 274 | } |
262 | 275 | ||
263 | - public void setTablayout() { | 276 | +// public void setTablayout() { |
277 | +// pagerAdapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), this,replay); | ||
278 | +// viewPager.setAdapter(pagerAdapter); | ||
279 | +// viewPager.setOnRplayTouchListener(this); | ||
280 | +// viewPager.setPagingEnabled(false); | ||
281 | +// tabLayout = (TabLayout) findViewById(R.id.sliding_tabs); | ||
282 | +// tabLayout.setupWithViewPager(viewPager,false); | ||
283 | +// tabLayout.setTabMode(TabLayout.MODE_FIXED); | ||
284 | +// } | ||
285 | + | ||
286 | + public void setTablayout(){ | ||
287 | + titles = new String[]{"文档", "聊天"}; | ||
264 | pagerAdapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), this,replay); | 288 | pagerAdapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), this,replay); |
265 | viewPager.setAdapter(pagerAdapter); | 289 | viewPager.setAdapter(pagerAdapter); |
266 | viewPager.setOnRplayTouchListener(this); | 290 | viewPager.setOnRplayTouchListener(this); |
267 | - tabLayout = (TabLayout) findViewById(R.id.sliding_tabs); | ||
268 | - tabLayout.setupWithViewPager(viewPager,false); | ||
269 | - tabLayout.setTabMode(TabLayout.MODE_FIXED); | 291 | + viewPager.setPagingEnabled(false); |
292 | + mSlidingTab.setViewPager(viewPager, titles); | ||
293 | + mSlidingTab.setOnTabSelectListener(new OnTabSelectListener() { | ||
294 | + @Override | ||
295 | + public void onTabSelect(int position) { | ||
296 | + if (1 == position && replay) { | ||
297 | + //为了避免回访时切换界面出现桌面 暂时先这样写了 | ||
298 | + showMediaContainer(TIME_OUT); | ||
299 | + } | ||
300 | + } | ||
301 | + | ||
302 | + @Override | ||
303 | + public void onTabReselect(int position) { | ||
304 | + | ||
305 | + } | ||
306 | + }); | ||
270 | } | 307 | } |
271 | 308 | ||
272 | //判断解析是否有密码 | 309 | //判断解析是否有密码 |
@@ -323,7 +360,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | @@ -323,7 +360,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | ||
323 | */ | 360 | */ |
324 | public void playVideo(String response) { | 361 | public void playVideo(String response) { |
325 | 362 | ||
326 | - progressDialogDismiss(); | 363 | +// progressDialogDismiss(); |
327 | 364 | ||
328 | if(replay){ | 365 | if(replay){ |
329 | playRecord(response); | 366 | playRecord(response); |
@@ -362,6 +399,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | @@ -362,6 +399,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | ||
362 | 399 | ||
363 | @Override | 400 | @Override |
364 | public void onBackPressed() { | 401 | public void onBackPressed() { |
402 | + UIUtils.closeDialog(mLoginDialog); | ||
365 | exit_dialog(); | 403 | exit_dialog(); |
366 | } | 404 | } |
367 | 405 | ||
@@ -440,6 +478,19 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | @@ -440,6 +478,19 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | ||
440 | 478 | ||
441 | 479 | ||
442 | } | 480 | } |
481 | + @Subscribe(threadMode = ThreadMode.POSTING) | ||
482 | + public void finishActivity(String res){ | ||
483 | + if("home".equals(res)) { | ||
484 | + this.finish(); | ||
485 | + } | ||
486 | + | ||
487 | + } | ||
488 | + | ||
489 | + @Override | ||
490 | + protected void onDestroy() { | ||
491 | + super.onDestroy(); | ||
492 | + EventBus.getDefault().unregister(this); | ||
493 | + } | ||
443 | 494 | ||
444 | @Override | 495 | @Override |
445 | protected void onPause() { | 496 | protected void onPause() { |
@@ -453,7 +504,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | @@ -453,7 +504,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | ||
453 | if(replay) { | 504 | if(replay) { |
454 | xdySdk.api("pauseRecordPlayback", ""); | 505 | xdySdk.api("pauseRecordPlayback", ""); |
455 | } | 506 | } |
456 | -// xdySdk.onPublisherPause(); | 507 | + xdySdk.onPublisherPause(); |
457 | } | 508 | } |
458 | 509 | ||
459 | @Override | 510 | @Override |
@@ -467,13 +518,15 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | @@ -467,13 +518,15 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | ||
467 | if(replay) { | 518 | if(replay) { |
468 | xdySdk.api("startRecordPlayback", ""); | 519 | xdySdk.api("startRecordPlayback", ""); |
469 | } | 520 | } |
470 | -// xdySdk.onPublisherResume(); | 521 | + xdySdk.onPublisherResume(); |
471 | } | 522 | } |
472 | 523 | ||
473 | /** | 524 | /** |
474 | * 错误情况退出 | 525 | * 错误情况退出 |
475 | */ | 526 | */ |
476 | public void exit() { | 527 | public void exit() { |
528 | + progressDialogDismiss(); | ||
529 | + isDefaultExit=true; | ||
477 | xdySdk.api("stopPublishVideo",""); | 530 | xdySdk.api("stopPublishVideo",""); |
478 | xdySdk.api("leaveClass", ""); | 531 | xdySdk.api("leaveClass", ""); |
479 | xdySdk.remove(this); | 532 | xdySdk.remove(this); |
@@ -534,7 +587,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | @@ -534,7 +587,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | ||
534 | } | 587 | } |
535 | if (mErrorDialog != null) | 588 | if (mErrorDialog != null) |
536 | return; | 589 | return; |
537 | - | 590 | + progressDialogDismiss(); |
538 | mErrorDialog = new AlertDialog.Builder(this) | 591 | mErrorDialog = new AlertDialog.Builder(this) |
539 | .setTitle("退出") | 592 | .setTitle("退出") |
540 | .setMessage("您设备的网络属于断开状态,请重新进入") | 593 | .setMessage("您设备的网络属于断开状态,请重新进入") |
@@ -548,7 +601,6 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | @@ -548,7 +601,6 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList | ||
548 | }) | 601 | }) |
549 | .create(); | 602 | .create(); |
550 | mErrorDialog.setCanceledOnTouchOutside(false); | 603 | mErrorDialog.setCanceledOnTouchOutside(false); |
551 | - | ||
552 | mErrorDialog.show(); | 604 | mErrorDialog.show(); |
553 | 605 | ||
554 | } | 606 | } |
@@ -27,14 +27,13 @@ import android.widget.TextView; | @@ -27,14 +27,13 @@ import android.widget.TextView; | ||
27 | 27 | ||
28 | 28 | ||
29 | import com.mang.xdy.common.Constants; | 29 | import com.mang.xdy.common.Constants; |
30 | -import com.mang.xdy.core.SPUtil; | 30 | +import com.mang.xdy.utils.SPUtil; |
31 | import com.mang.xdy.demo.R; | 31 | import com.mang.xdy.demo.R; |
32 | import com.mang.xdy.demo.bean.JoinClassSuccessEntity; | 32 | import com.mang.xdy.demo.bean.JoinClassSuccessEntity; |
33 | import com.mang.xdy.demo.bean.Message; | 33 | import com.mang.xdy.demo.bean.Message; |
34 | import com.mang.xdy.demo.fragment.ChatFragment; | 34 | import com.mang.xdy.demo.fragment.ChatFragment; |
35 | import com.mang.xdy.demo.utils.JsonUtil; | 35 | import com.mang.xdy.demo.utils.JsonUtil; |
36 | import com.mang.xdy.demo.widget.chat.UrlUtils; | 36 | import com.mang.xdy.demo.widget.chat.UrlUtils; |
37 | -import com.mang.xdy.utils.XdyLogUtil; | ||
38 | 37 | ||
39 | import org.kymjs.kjframe.KJBitmap; | 38 | import org.kymjs.kjframe.KJBitmap; |
40 | 39 |
@@ -16,14 +16,12 @@ import android.widget.ListView; | @@ -16,14 +16,12 @@ import android.widget.ListView; | ||
16 | 16 | ||
17 | import com.google.gson.Gson; | 17 | import com.google.gson.Gson; |
18 | import com.mang.xdy.common.Constants; | 18 | import com.mang.xdy.common.Constants; |
19 | -import com.mang.xdy.core.SPUtil; | 19 | +import com.mang.xdy.utils.SPUtil; |
20 | import com.mang.xdy.core.XdySdk; | 20 | import com.mang.xdy.core.XdySdk; |
21 | import com.mang.xdy.demo.R; | 21 | import com.mang.xdy.demo.R; |
22 | -import com.mang.xdy.demo.activity.VideoPlayActivity; | ||
23 | import com.mang.xdy.demo.adapter.ChatAdapter; | 22 | import com.mang.xdy.demo.adapter.ChatAdapter; |
24 | import com.mang.xdy.demo.bean.ChatMsgEntity; | 23 | import com.mang.xdy.demo.bean.ChatMsgEntity; |
25 | import com.mang.xdy.demo.bean.Faceicon; | 24 | import com.mang.xdy.demo.bean.Faceicon; |
26 | -import com.mang.xdy.demo.bean.JoinClassBean; | ||
27 | import com.mang.xdy.demo.bean.JoinClassSuccessEntity; | 25 | import com.mang.xdy.demo.bean.JoinClassSuccessEntity; |
28 | import com.mang.xdy.demo.bean.Message; | 26 | import com.mang.xdy.demo.bean.Message; |
29 | import com.mang.xdy.demo.bean.SendChatMsgEntity; | 27 | import com.mang.xdy.demo.bean.SendChatMsgEntity; |
@@ -33,7 +31,6 @@ import com.mang.xdy.demo.widget.chat.OnOperationListener; | @@ -33,7 +31,6 @@ import com.mang.xdy.demo.widget.chat.OnOperationListener; | ||
33 | import com.mang.xdy.demo.widget.emoji.DisplayRules; | 31 | import com.mang.xdy.demo.widget.emoji.DisplayRules; |
34 | import com.mang.xdy.listener.ObserverListener; | 32 | import com.mang.xdy.listener.ObserverListener; |
35 | import com.mang.xdy.utils.XdyLogUtil; | 33 | import com.mang.xdy.utils.XdyLogUtil; |
36 | -import com.mang.xdy.utils.XdyStringUtils; | ||
37 | 34 | ||
38 | import org.greenrobot.eventbus.EventBus; | 35 | import org.greenrobot.eventbus.EventBus; |
39 | import org.greenrobot.eventbus.Subscribe; | 36 | import org.greenrobot.eventbus.Subscribe; |
@@ -43,7 +40,6 @@ import org.kymjs.kjframe.utils.KJLoger; | @@ -43,7 +40,6 @@ import org.kymjs.kjframe.utils.KJLoger; | ||
43 | import org.kymjs.kjframe.utils.StringUtils; | 40 | import org.kymjs.kjframe.utils.StringUtils; |
44 | 41 | ||
45 | import java.io.File; | 42 | import java.io.File; |
46 | -import java.math.MathContext; | ||
47 | import java.util.ArrayList; | 43 | import java.util.ArrayList; |
48 | import java.util.List; | 44 | import java.util.List; |
49 | 45 |
@@ -11,6 +11,8 @@ import com.mang.xdy.demo.R; | @@ -11,6 +11,8 @@ import com.mang.xdy.demo.R; | ||
11 | import com.mang.xdy.demo.dialog.BaseDialog; | 11 | import com.mang.xdy.demo.dialog.BaseDialog; |
12 | import com.mang.xdy.utils.UIUtils; | 12 | import com.mang.xdy.utils.UIUtils; |
13 | 13 | ||
14 | +import org.greenrobot.eventbus.EventBus; | ||
15 | + | ||
14 | import me.yokeyword.fragmentation.SupportFragment; | 16 | import me.yokeyword.fragmentation.SupportFragment; |
15 | 17 | ||
16 | 18 | ||
@@ -72,5 +74,7 @@ public class LoginDialog extends BaseDialog { | @@ -72,5 +74,7 @@ public class LoginDialog extends BaseDialog { | ||
72 | if (fragment != null && fragment.isAdded()) { | 74 | if (fragment != null && fragment.isAdded()) { |
73 | fragment.pop(); | 75 | fragment.pop(); |
74 | } | 76 | } |
77 | + dismiss(); | ||
78 | + EventBus.getDefault().post("home"); | ||
75 | } | 79 | } |
76 | } | 80 | } |
@@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
16 | android:layout_width="match_parent" | 16 | android:layout_width="match_parent" |
17 | android:layout_height="wrap_content" | 17 | android:layout_height="wrap_content" |
18 | android:hint="请输入课堂号" | 18 | android:hint="请输入课堂号" |
19 | + android:inputType="number" | ||
19 | android:text="1332699420"/> | 20 | android:text="1332699420"/> |
20 | <TextView | 21 | <TextView |
21 | android:layout_width="match_parent" | 22 | android:layout_width="match_parent" |
@@ -25,6 +26,7 @@ | @@ -25,6 +26,7 @@ | ||
25 | android:id="@+id/edt_home_role" | 26 | android:id="@+id/edt_home_role" |
26 | android:layout_width="match_parent" | 27 | android:layout_width="match_parent" |
27 | android:layout_height="wrap_content" | 28 | android:layout_height="wrap_content" |
29 | + android:hint="请输入角色" | ||
28 | android:text="normal" | 30 | android:text="normal" |
29 | /> | 31 | /> |
30 | <TextView | 32 | <TextView |
@@ -37,6 +39,7 @@ | @@ -37,6 +39,7 @@ | ||
37 | android:id="@+id/edt_home_serviceIp" | 39 | android:id="@+id/edt_home_serviceIp" |
38 | android:layout_width="match_parent" | 40 | android:layout_width="match_parent" |
39 | android:layout_height="wrap_content" | 41 | android:layout_height="wrap_content" |
42 | + android:hint="请输入服务器地址" | ||
40 | android:text="112.126.80.182:90" | 43 | android:text="112.126.80.182:90" |
41 | /> | 44 | /> |
42 | <TextView | 45 | <TextView |
@@ -48,6 +51,7 @@ | @@ -48,6 +51,7 @@ | ||
48 | android:id="@+id/edt_home_userId" | 51 | android:id="@+id/edt_home_userId" |
49 | android:layout_width="match_parent" | 52 | android:layout_width="match_parent" |
50 | android:layout_height="wrap_content" | 53 | android:layout_height="wrap_content" |
54 | + android:hint="请输入用户id" | ||
51 | android:text="0" | 55 | android:text="0" |
52 | /> | 56 | /> |
53 | <Button | 57 | <Button |
@@ -55,13 +59,22 @@ | @@ -55,13 +59,22 @@ | ||
55 | android:layout_width="match_parent" | 59 | android:layout_width="match_parent" |
56 | android:layout_height="wrap_content" | 60 | android:layout_height="wrap_content" |
57 | android:text="进入课堂" | 61 | android:text="进入课堂" |
62 | + android:textColor="@color/white" | ||
63 | + android:background="@drawable/home_selector_bottom_btn_blue" | ||
64 | + android:layout_marginLeft="15dp" | ||
65 | + android:layout_marginRight="15dp" | ||
58 | 66 | ||
59 | /> | 67 | /> |
60 | <Button | 68 | <Button |
61 | android:id="@+id/btn_home_enter_publisher" | 69 | android:id="@+id/btn_home_enter_publisher" |
62 | android:layout_width="match_parent" | 70 | android:layout_width="match_parent" |
63 | android:layout_height="wrap_content" | 71 | android:layout_height="wrap_content" |
72 | + android:layout_marginTop="15dp" | ||
73 | + android:layout_marginLeft="15dp" | ||
74 | + android:layout_marginRight="15dp" | ||
64 | android:text="录制回放" | 75 | android:text="录制回放" |
76 | + android:textColor="@color/white" | ||
77 | + android:background="@drawable/home_selector_bottom_btn_green" | ||
65 | /> | 78 | /> |
66 | 79 | ||
67 | </LinearLayout> | 80 | </LinearLayout> |
1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
3 | xmlns:tools="http://schemas.android.com/tools" | 3 | xmlns:tools="http://schemas.android.com/tools" |
4 | + xmlns:custom="http://schemas.android.com/apk/res-auto" | ||
4 | android:id="@+id/activity_video_play" | 5 | android:id="@+id/activity_video_play" |
5 | android:layout_width="match_parent" | 6 | android:layout_width="match_parent" |
6 | android:layout_height="match_parent" | 7 | android:layout_height="match_parent" |
@@ -127,7 +128,25 @@ | @@ -127,7 +128,25 @@ | ||
127 | android:id="@+id/sliding_tabs" | 128 | android:id="@+id/sliding_tabs" |
128 | android:layout_width="match_parent" | 129 | android:layout_width="match_parent" |
129 | android:layout_height="wrap_content" | 130 | android:layout_height="wrap_content" |
131 | + android:visibility="gone" | ||
132 | + | ||
130 | /> | 133 | /> |
134 | + <com.flyco.tablayout.SlidingTabLayout | ||
135 | + android:id="@+id/stl_videoPlay_tab" | ||
136 | + android:layout_width="match_parent" | ||
137 | + android:layout_height="@dimen/ui_titlebar_height" | ||
138 | + android:layout_alignParentLeft="true" | ||
139 | + android:layout_alignParentStart="true" | ||
140 | + android:layout_below="@+id/fl_videoview_container" | ||
141 | + android:background="#fafafa" | ||
142 | + custom:tl_indicator_color="@color/home_tab_selected" | ||
143 | + custom:tl_indicator_corner_radius="1.5dp" | ||
144 | + custom:tl_indicator_height="@dimen/ui_DIMEN_5.0PX" | ||
145 | + custom:tl_tab_space_equal="true" | ||
146 | + custom:tl_textSelectColor="@color/home_tab_selected" | ||
147 | + custom:tl_textUnselectColor="@color/home_tab_unselected" | ||
148 | + | ||
149 | + custom:tl_textsize="@dimen/ui_DIMEN_28.0PX"/> | ||
131 | <com.mang.xdy.demo.widget.view.NoScrollViewPager | 150 | <com.mang.xdy.demo.widget.view.NoScrollViewPager |
132 | android:id="@+id/viewpager" | 151 | android:id="@+id/viewpager" |
133 | android:layout_width="match_parent" | 152 | android:layout_width="match_parent" |
@@ -81,14 +81,14 @@ public class Threeivity extends AppCompatActivity implements View.OnClickListene | @@ -81,14 +81,14 @@ public class Threeivity extends AppCompatActivity implements View.OnClickListene | ||
81 | // SmartPlayerNoLayout smartPlayerNoLayout=new SmartPlayerNoLayout(surface, Threeivity.this); | 81 | // SmartPlayerNoLayout smartPlayerNoLayout=new SmartPlayerNoLayout(surface, Threeivity.this); |
82 | // startActivity(new Intent(Threeivity.this,SmartPlayer.class)); | 82 | // startActivity(new Intent(Threeivity.this,SmartPlayer.class)); |
83 | String url= "rtmp://123.56.205.116:6000/live/h5dev_1999957388_980_983041_1491813919";; | 83 | String url= "rtmp://123.56.205.116:6000/live/h5dev_1999957388_980_983041_1491813919";; |
84 | -//// XdyPlayerCore xdyPlayer=new XdyPlayerCore(url,surface,Threeivity.this); | 84 | +//// XdyPlayer xdyPlayer=new XdyPlayer(url,surface,Threeivity.this); |
85 | //// xdyPlayer.playVideo(url,surface); | 85 | //// xdyPlayer.playVideo(url,surface); |
86 | // XdySdk.setAsyncApi("playAudio",url,null,Threeivity.this); | 86 | // XdySdk.setAsyncApi("playAudio",url,null,Threeivity.this); |
87 | // XdySdk.setAsyncApi("playVideo",url,surface,Threeivity.this,new EventHande()); | 87 | // XdySdk.setAsyncApi("playVideo",url,surface,Threeivity.this,new EventHande()); |
88 | xdySdk.api("publishVideo",url,surface,Threeivity.this); | 88 | xdySdk.api("publishVideo",url,surface,Threeivity.this); |
89 | // xdyPlayer.playVideo("",surface); | 89 | // xdyPlayer.playVideo("",surface); |
90 | 90 | ||
91 | -// XdyPublisherCore xdyPublisherCore=new XdyPublisherCore(Threeivity.this); | 91 | +// XdyPublisher xdyPublisherCore=new XdyPublisher(Threeivity.this); |
92 | // xdyPublisherCore.publish("",surface); | 92 | // xdyPublisherCore.publish("",surface); |
93 | } | 93 | } |
94 | }); | 94 | }); |
1 | -package com.mang.xdy.core; | ||
2 | - | ||
3 | -import android.content.Context; | ||
4 | -import android.content.SharedPreferences; | ||
5 | - | ||
6 | -import java.io.ByteArrayOutputStream; | ||
7 | -import java.io.IOException; | ||
8 | -import java.io.InputStream; | ||
9 | - | ||
10 | - | ||
11 | -public class SPUtil { | ||
12 | - private static SharedPreferences mSp; | ||
13 | - | ||
14 | - private static SharedPreferences getSharedPreferences(Context context) { | ||
15 | - if (mSp == null) { | ||
16 | - mSp = context.getSharedPreferences("config", Context.MODE_PRIVATE); | ||
17 | - } | ||
18 | - return mSp; | ||
19 | - } | ||
20 | - | ||
21 | - public static void putBoolean(Context context, String key, boolean value) { | ||
22 | - // SharedPreferences sp = mContext.getSharedPreferences("config", | ||
23 | - // Context.MODE_PRIVATE); | ||
24 | - getSharedPreferences(context).edit().putBoolean(key, value).commit(); | ||
25 | - } | ||
26 | - | ||
27 | - public static boolean getBoolean(Context context, String key, boolean defValue) { | ||
28 | - // SharedPreferences sp = mContext.getSharedPreferences("config", | ||
29 | - // Context.MODE_PRIVATE); | ||
30 | - return getSharedPreferences(context).getBoolean(key, defValue); | ||
31 | - } | ||
32 | - | ||
33 | - public static void putString(Context context, String key, String value) { | ||
34 | - getSharedPreferences(context).edit().putString(key, value).commit(); | ||
35 | - } | ||
36 | - | ||
37 | - public static String getString(Context context, String key, String defValue) { | ||
38 | - return getSharedPreferences(context).getString(key, defValue); | ||
39 | - } | ||
40 | - | ||
41 | - public static void putInt(Context context, String key, int value) { | ||
42 | - getSharedPreferences(context).edit().putInt(key, value).commit(); | ||
43 | - } | ||
44 | - | ||
45 | - public static int getInt(Context context, String key, int defValue) { | ||
46 | - return getSharedPreferences(context).getInt(key, defValue); | ||
47 | - } | ||
48 | - | ||
49 | - /** | ||
50 | - * 移除一个字符串值 | ||
51 | - * | ||
52 | - * @param context | ||
53 | - * @param key | ||
54 | - */ | ||
55 | - public static void removeString(Context context, String key) { | ||
56 | - getSharedPreferences(context).edit().remove(key).commit(); | ||
57 | - } | ||
58 | - | ||
59 | - /** | ||
60 | - * 把流里的内容解析成字符串 | ||
61 | - * | ||
62 | - * @param is | ||
63 | - * @return | ||
64 | - * @throws IOException | ||
65 | - */ | ||
66 | - public static String streamToString(InputStream is) throws IOException { | ||
67 | - ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
68 | - byte[] buffer = new byte[1024]; | ||
69 | - int len = -1; | ||
70 | - while ((len = is.read(buffer)) != -1) { | ||
71 | - baos.write(buffer, 0, len); | ||
72 | - } | ||
73 | - String string = baos.toString(); | ||
74 | - baos.close(); | ||
75 | - is.close(); | ||
76 | - return string; | ||
77 | - } | ||
78 | - public static long getLong(String key,long defValue) { | ||
79 | - return mSp.getLong(key, defValue); | ||
80 | - } | ||
81 | - public static void setLong(Context context, String key, Long value) { | ||
82 | - getSharedPreferences(context).edit().putLong(key, value).commit(); | ||
83 | - } | ||
84 | -} |
@@ -5,19 +5,24 @@ package com.mang.xdy.core; | @@ -5,19 +5,24 @@ package com.mang.xdy.core; | ||
5 | */ | 5 | */ |
6 | 6 | ||
7 | import android.content.Context; | 7 | import android.content.Context; |
8 | +import android.graphics.Bitmap; | ||
8 | import android.os.Build; | 9 | import android.os.Build; |
9 | import android.text.NoCopySpan; | 10 | import android.text.NoCopySpan; |
10 | import android.text.TextUtils; | 11 | import android.text.TextUtils; |
11 | import android.webkit.JavascriptInterface; | 12 | import android.webkit.JavascriptInterface; |
12 | import android.webkit.ValueCallback; | 13 | import android.webkit.ValueCallback; |
13 | import android.webkit.WebChromeClient; | 14 | import android.webkit.WebChromeClient; |
15 | +import android.webkit.WebResourceError; | ||
16 | +import android.webkit.WebResourceRequest; | ||
14 | import android.webkit.WebSettings; | 17 | import android.webkit.WebSettings; |
15 | import android.webkit.WebView; | 18 | import android.webkit.WebView; |
19 | +import android.webkit.WebViewClient; | ||
16 | 20 | ||
21 | +import com.mang.xdy.common.Constants; | ||
17 | import com.mang.xdy.utils.XdyLogUtil; | 22 | import com.mang.xdy.utils.XdyLogUtil; |
23 | +import com.mang.xdy.utils.XdyStringUtils; | ||
18 | 24 | ||
19 | /** | 25 | /** |
20 | - * 需要提供两个参数的接口,一个参数的接口,同时给出回调() | ||
21 | * 数据的异常检测都放在最外层(便于给用户提示),这层默认数据都是完整 | 26 | * 数据的异常检测都放在最外层(便于给用户提示),这层默认数据都是完整 |
22 | * 核心WebView 处理和调用的js | 27 | * 核心WebView 处理和调用的js |
23 | */ | 28 | */ |
@@ -54,7 +59,6 @@ public class XdyJsCore { | @@ -54,7 +59,6 @@ public class XdyJsCore { | ||
54 | if(context==null){ | 59 | if(context==null){ |
55 | return; | 60 | return; |
56 | } | 61 | } |
57 | - //清理Webview缓存数据库 | ||
58 | mXdyJavaScript=new XdyJavaScript(); | 62 | mXdyJavaScript=new XdyJavaScript(); |
59 | mWebView=new WebView(context); | 63 | mWebView=new WebView(context); |
60 | WebSettings webSettings=mWebView.getSettings(); | 64 | WebSettings webSettings=mWebView.getSettings(); |
@@ -69,6 +73,23 @@ public class XdyJsCore { | @@ -69,6 +73,23 @@ public class XdyJsCore { | ||
69 | // XdyLogUtil.e("message:"+message+" lineNumber:"+" sourceId:"+sourceID); | 73 | // XdyLogUtil.e("message:"+message+" lineNumber:"+" sourceId:"+sourceID); |
70 | } | 74 | } |
71 | }); | 75 | }); |
76 | + mWebView.setWebViewClient(new WebViewClient(){ | ||
77 | + @Override | ||
78 | + public void onPageStarted(WebView view, String url, Bitmap favicon) { | ||
79 | + super.onPageStarted(view, url, favicon); | ||
80 | + } | ||
81 | + | ||
82 | + @Override | ||
83 | + public void onPageFinished(WebView view, String url) { | ||
84 | + super.onPageFinished(view, url); | ||
85 | + } | ||
86 | + | ||
87 | + | ||
88 | + @Override | ||
89 | + public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { | ||
90 | + super.onReceivedError(view, errorCode, description, failingUrl); | ||
91 | + } | ||
92 | + }); | ||
72 | mWebView.post(new Runnable() { | 93 | mWebView.post(new Runnable() { |
73 | @Override | 94 | @Override |
74 | public void run() { | 95 | public void run() { |
1 | -package com.mang.xdy.core; | ||
2 | - | ||
3 | -import android.content.Context; | ||
4 | -import android.util.Log; | ||
5 | -import android.view.SurfaceView; | ||
6 | - | ||
7 | -import com.daniulive.smartplayer.SmartPlayerJni; | ||
8 | -import com.eventhandle.SmartEventCallback; | ||
9 | -import com.mang.xdy.utils.XdyLogUtil; | ||
10 | - | ||
11 | -/** | ||
12 | - * Created by abao on 2017/4/5. | ||
13 | - */ | ||
14 | - | ||
15 | -/** | ||
16 | - * 播放视频的方法核心方法(供内部调用,外部继续封装) | ||
17 | - */ | ||
18 | -public class XdyPlayerCore { | ||
19 | - | ||
20 | - private long playerHandle = 0; | ||
21 | - private static final int PORTRAIT = 1; //竖屏 | ||
22 | - private static final int LANDSCAPE = 2; //横屏 | ||
23 | - private static final String TAG = "XdyPlayer"; | ||
24 | - | ||
25 | - private SmartPlayerJni libPlayer = null; | ||
26 | - private Context mContext; | ||
27 | - /*是否正在播放,如果正在播放设置为TRUE,防止多次被实例化,*/ | ||
28 | - private boolean isPlaying=false; | ||
29 | - private static XdyPlayerCore mXdyPlayerCore; | ||
30 | - static { | ||
31 | - System.loadLibrary("SmartPlayer"); | ||
32 | - } | ||
33 | - protected XdyPlayerCore(String rtmpUrl, Context mContext) { | ||
34 | - this.mContext=mContext; | ||
35 | - } | ||
36 | - protected static XdyPlayerCore getXdyPlayerCore(String rtmpUrl, Context mContext){ | ||
37 | - if(mXdyPlayerCore==null){ | ||
38 | - synchronized (XdyPlayerCore.class){ | ||
39 | - if(mXdyPlayerCore==null){ | ||
40 | - mXdyPlayerCore=new XdyPlayerCore(rtmpUrl, mContext); | ||
41 | - } | ||
42 | - } | ||
43 | - } | ||
44 | - return mXdyPlayerCore; | ||
45 | - } | ||
46 | - | ||
47 | - /** | ||
48 | - * 播放视频的的调用的方法 | ||
49 | - * 如果surfaceView 为null则播放Audio | ||
50 | - * @param rtmpUrl | ||
51 | - * @param surfaceView | ||
52 | - */ | ||
53 | - public void playVideo(String rtmpUrl, SurfaceView surfaceView,SmartEventCallback smartEventCallback) { | ||
54 | -// if (isPlaying) { | ||
55 | -// return; | ||
56 | -// } | ||
57 | - if(libPlayer==null) | ||
58 | - libPlayer = new SmartPlayerJni(); | ||
59 | - playerHandle = libPlayer.SmartPlayerInit(mContext); | ||
60 | - if (playerHandle == 0) { | ||
61 | - XdyLogUtil.e(TAG, "视频初始化失败 "); | ||
62 | - return; | ||
63 | - } | ||
64 | - libPlayer.SetSmartPlayerEventCallback(playerHandle, smartEventCallback); | ||
65 | - libPlayer.SmartPlayerSetSurface(playerHandle, surfaceView); | ||
66 | - libPlayer.SmartPlayerSetAudioOutputType(playerHandle, 0); | ||
67 | - libPlayer.SmartPlayerSetBuffer(playerHandle, 200); | ||
68 | - int isPlaySuccessful = libPlayer.SmartPlayerStartPlayback(playerHandle, rtmpUrl); | ||
69 | - if (isPlaySuccessful != 0) { | ||
70 | - XdyLogUtil.e(TAG, "视频播放失败" + rtmpUrl); | ||
71 | - } | ||
72 | -// XdySdk.getXdyInstance().notifyObserver("video_success",""); | ||
73 | - XdyLogUtil.e(TAG, "视频播放成功" + rtmpUrl); | ||
74 | -// isPlaying = true; | ||
75 | - | ||
76 | - } | ||
77 | - | ||
78 | - /** | ||
79 | - * 播放音频 | ||
80 | - * @param rtmpUrl | ||
81 | - * @param smartEventCallback | ||
82 | - */ | ||
83 | - public void playAudio(String rtmpUrl,SmartEventCallback smartEventCallback) { | ||
84 | - if(libPlayer==null){ | ||
85 | - libPlayer = new SmartPlayerJni(); | ||
86 | - } | ||
87 | - //TODO | ||
88 | - if(playerHandle==0) { | ||
89 | - playerHandle = libPlayer.SmartPlayerInit(mContext); | ||
90 | - } | ||
91 | - XdyLogUtil.e(TAG, "playVideoId" + playerHandle); | ||
92 | - if (playerHandle == 0) { | ||
93 | - XdyLogUtil.e(TAG, "音频初始化失败"); | ||
94 | - return; | ||
95 | - } | ||
96 | - libPlayer.SetSmartPlayerEventCallback(playerHandle, smartEventCallback); | ||
97 | - //播放音频 | ||
98 | - libPlayer.SmartPlayerSetSurface(playerHandle, null); | ||
99 | - int isPlaySuccessful = libPlayer.SmartPlayerStartPlayback(playerHandle, rtmpUrl); | ||
100 | - if (isPlaySuccessful != 0) { | ||
101 | - XdyLogUtil.e(TAG, "音频播放失败" + rtmpUrl); | ||
102 | - } | ||
103 | - XdyLogUtil.e(TAG, "音频播放成功" + rtmpUrl); | ||
104 | - } | ||
105 | - class EventHande implements SmartEventCallback { | ||
106 | - @Override | ||
107 | - public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) { | ||
108 | - switch (code) { | ||
109 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED: | ||
110 | - Log.i(TAG, "开始。。"); | ||
111 | - break; | ||
112 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING: | ||
113 | - Log.i(TAG, "连接中。。"); | ||
114 | - break; | ||
115 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED: | ||
116 | - Log.i(TAG, "连接失败。。"); | ||
117 | - break; | ||
118 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED: | ||
119 | - Log.i(TAG, "连接成功。。"); | ||
120 | - break; | ||
121 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED: | ||
122 | - Log.i(TAG, "连接断开。。"); | ||
123 | - break; | ||
124 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP: | ||
125 | - Log.i(TAG, "关闭。。"); | ||
126 | - break; | ||
127 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO: | ||
128 | - Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2); | ||
129 | - break; | ||
130 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED: | ||
131 | - Log.i(TAG, "收不到媒体数据,可能是url错误。。"); | ||
132 | - } | ||
133 | - | ||
134 | - } | ||
135 | - } | ||
136 | - | ||
137 | - /** | ||
138 | - * 结束时调用 | ||
139 | - */ | ||
140 | - protected void onDestroy() | ||
141 | - { | ||
142 | - XdyLogUtil.i(TAG, "Run into destory++"); | ||
143 | - | ||
144 | - if(playerHandle!=0) | ||
145 | - { | ||
146 | - libPlayer.SmartPlayerClose(playerHandle); | ||
147 | - playerHandle = 0; | ||
148 | - } | ||
149 | - } | ||
150 | - | ||
151 | - /** | ||
152 | - * 暂停方法 | ||
153 | - */ | ||
154 | - protected void onPause(){ | ||
155 | - if(playerHandle!=0) | ||
156 | - { | ||
157 | - libPlayer.SmartPlayerClose(playerHandle); | ||
158 | - playerHandle = 0; | ||
159 | - } | ||
160 | - isPlaying = false; | ||
161 | - } | ||
162 | - /** | ||
163 | - * 停止播放,重置正在播放标识 | ||
164 | - */ | ||
165 | - protected void onStopPlay() { | ||
166 | - if(playerHandle!=0) | ||
167 | - { | ||
168 | - libPlayer.SmartPlayerClose(playerHandle); | ||
169 | - playerHandle = 0; | ||
170 | - } | ||
171 | - isPlaying = false; | ||
172 | - } | ||
173 | -} |
1 | -package com.mang.xdy.core; | ||
2 | - | ||
3 | - | ||
4 | -import android.annotation.SuppressLint; | ||
5 | -import android.app.Activity; | ||
6 | -import android.graphics.ImageFormat; | ||
7 | -import android.graphics.PixelFormat; | ||
8 | -import android.hardware.Camera; | ||
9 | -import android.util.Log; | ||
10 | -import android.view.Surface; | ||
11 | -import android.view.SurfaceHolder; | ||
12 | -import android.view.SurfaceView; | ||
13 | - | ||
14 | -import com.daniulive.smartpublisher.SmartPublisherJni; | ||
15 | -import com.eventhandle.SmartEventCallback; | ||
16 | -import com.mang.xdy.utils.XdyLogUtil; | ||
17 | -import com.voiceengine.NTAudioRecord; | ||
18 | - | ||
19 | -import java.io.IOException; | ||
20 | -import java.util.List; | ||
21 | - | ||
22 | -/** | ||
23 | - * Created by abao on 2017/4/6. | ||
24 | - */ | ||
25 | -@SuppressWarnings("deprecation") | ||
26 | -public class XdyPublisherCore implements SurfaceHolder.Callback, Camera.PreviewCallback { | ||
27 | - private SurfaceView mSurfaceView; | ||
28 | - private SurfaceHolder pubSurfaceViewHolder; | ||
29 | - Activity mActivity; | ||
30 | - private SmartPublisherJni xdyPublisher; | ||
31 | - private Camera.AutoFocusCallback myAutoFocusCallback = null; | ||
32 | - NTAudioRecord audioRecord_ = null; | ||
33 | - private static final int BACK = 2; | ||
34 | - private static final int FRONT = 1; //前置摄像头标记 | ||
35 | - private int currentCameraType = BACK; //当前打开的摄像头标记 | ||
36 | - private Camera mCamera = null; | ||
37 | - private boolean mPreviewRunning = false; | ||
38 | - private int curCameraIndex = -1; | ||
39 | - private int frameCount = 0; | ||
40 | - private static String TAG="XdyPublisher"; | ||
41 | - private static final int PORTRAIT = 1; //竖屏 | ||
42 | - private static final int LANDSCAPE = 2; //横屏 | ||
43 | - private int currentOrigentation = PORTRAIT; | ||
44 | - //默认都推送 0不推送 1推送 | ||
45 | - protected int audio_opt = 1; | ||
46 | - protected int video_opt = 1; | ||
47 | - int videoWidth = 640; | ||
48 | - private int videoHight = 480; | ||
49 | - /*是否推流的标志,true 开始推送,false不推送*/ | ||
50 | - private boolean isStart = false; | ||
51 | - /*是否支持硬编码 默认不支持*/ | ||
52 | - private boolean is_hardware_encoder = false; | ||
53 | - | ||
54 | - static { | ||
55 | - System.loadLibrary("SmartPublisher"); | ||
56 | - } | ||
57 | - | ||
58 | - public XdyPublisherCore(int audio_opt,int video_opt,Activity mActivity) { | ||
59 | - this.audio_opt=audio_opt; | ||
60 | - this.video_opt=video_opt; | ||
61 | - this.mActivity = mActivity; | ||
62 | - } | ||
63 | - /** | ||
64 | - * 开始推流(视频) | ||
65 | - * | ||
66 | - * @param rtmpUrls | ||
67 | - */ | ||
68 | - public void publisher(String rtmpUrls, SurfaceView pubSurfaceView,SmartEventCallback smartEventCallback) { | ||
69 | -// if(isStart){ | ||
70 | -// return; | ||
71 | -// } | ||
72 | - mPreviewRunning = false; | ||
73 | - this.mSurfaceView=pubSurfaceView; | ||
74 | - if (xdyPublisher == null) { | ||
75 | - xdyPublisher = new SmartPublisherJni(); | ||
76 | - } | ||
77 | - isStart=true; | ||
78 | - if(pubSurfaceViewHolder==null) { | ||
79 | - pubSurfaceViewHolder = mSurfaceView.getHolder(); | ||
80 | - pubSurfaceViewHolder.addCallback(this); | ||
81 | - pubSurfaceViewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); | ||
82 | - } | ||
83 | - Log.i(TAG, "surfaceCreated.."); | ||
84 | - try { | ||
85 | - currentCameraType = FRONT; | ||
86 | - | ||
87 | - if (mCamera == null) { | ||
88 | - mCamera = openCamera(currentCameraType); | ||
89 | - mCamera.stopPreview(); | ||
90 | - initCamera(pubSurfaceViewHolder); | ||
91 | - } | ||
92 | - } catch (Exception e) { | ||
93 | - e.printStackTrace(); | ||
94 | - Log.e(TAG, "surfaceCreated: 异常了"+e.getMessage()); | ||
95 | - } | ||
96 | - int i = xdyPublisher.SmartPublisherInit(mActivity, audio_opt,video_opt, videoWidth, videoHight); | ||
97 | - XdyLogUtil.e(TAG, ": " + i); | ||
98 | - xdyPublisher.SetSmartPublisherEventCallback(new EventHande()); | ||
99 | - XdyLogUtil.e(TAG,"url:"+rtmpUrls); | ||
100 | - if (xdyPublisher.SmartPublisherSetURL(rtmpUrls) != 0) { | ||
101 | - XdyLogUtil.e(TAG, "Failed to set publish stream URL.."); | ||
102 | - } | ||
103 | - int isStarted = xdyPublisher.SmartPublisherStart(); // 0 成功 | ||
104 | - if (isStarted != 0) { | ||
105 | - XdyLogUtil.e(TAG, "Failed to publish stream.."); | ||
106 | - } else { | ||
107 | - XdyLogUtil.e(TAG, "publish successful"); | ||
108 | -// isStart = true; | ||
109 | - } | ||
110 | - CheckInitAudioRecorder(); | ||
111 | - } | ||
112 | - | ||
113 | - /** | ||
114 | - * 开始推流(只有音频) | ||
115 | - * | ||
116 | - * @param rtmpUrl | ||
117 | - */ | ||
118 | - public void publisherAudio(String rtmpUrl,SmartEventCallback smartEventCallback) { | ||
119 | -// if(isStart){ | ||
120 | -// return; | ||
121 | -// } | ||
122 | - if (xdyPublisher == null) { | ||
123 | - xdyPublisher = new SmartPublisherJni(); | ||
124 | - } | ||
125 | - isStart=true; | ||
126 | - XdyLogUtil.e(TAG, "surfaceCreated.."); | ||
127 | - | ||
128 | - int i = xdyPublisher.SmartPublisherInit(mActivity, audio_opt,video_opt, videoWidth, videoHight); | ||
129 | - if(i!=0){ | ||
130 | - XdyLogUtil.e(TAG, "SmartPublisherInit:初始化返回值是0成功: " + i); | ||
131 | - return; | ||
132 | - } | ||
133 | - | ||
134 | - xdyPublisher.SetSmartPublisherEventCallback(smartEventCallback); | ||
135 | - if (xdyPublisher.SmartPublisherSetURL(rtmpUrl) != 0) { | ||
136 | - XdyLogUtil.e(TAG, "Failed to set publish stream URL.."); | ||
137 | - } | ||
138 | - | ||
139 | - if (0 != xdyPublisher.SmartPublisherSetRecorder(0)) { | ||
140 | - XdyLogUtil.e(TAG, "SmartPublisherSetRecoder failed."); | ||
141 | - return; | ||
142 | - } | ||
143 | - int isStarted = xdyPublisher.SmartPublisherStart(); // 0 成功 | ||
144 | - if (isStarted != 0) { | ||
145 | - Log.e(TAG, "Failed to publish stream.."); | ||
146 | - } else { | ||
147 | - Log.e(TAG, "publish successful"); | ||
148 | -// isStart = true; | ||
149 | - } | ||
150 | - CheckInitAudioRecorder(); | ||
151 | - } | ||
152 | - void CheckInitAudioRecorder() { | ||
153 | - if (audioRecord_ == null) { | ||
154 | - audioRecord_ = new NTAudioRecord(mActivity, 1); | ||
155 | - } | ||
156 | - | ||
157 | - if (audioRecord_ != null) { | ||
158 | - Log.e(TAG, "onCreate, call executeAudioRecordMethod.."); | ||
159 | - audioRecord_.executeAudioRecordMethod(); | ||
160 | - } | ||
161 | - } | ||
162 | - | ||
163 | - @SuppressLint("NewApi") | ||
164 | - private Camera openCamera(int type) { | ||
165 | - int frontIndex = -1; | ||
166 | - int backIndex = -1; | ||
167 | - int cameraCount = Camera.getNumberOfCameras(); | ||
168 | - Log.i(TAG, "cameraCount: " + cameraCount); | ||
169 | - | ||
170 | - Camera.CameraInfo info = new Camera.CameraInfo(); | ||
171 | - for (int cameraIndex = 0; cameraIndex < cameraCount; cameraIndex++) { | ||
172 | - Camera.getCameraInfo(cameraIndex, info); | ||
173 | - | ||
174 | - if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { | ||
175 | - frontIndex = cameraIndex; | ||
176 | - } else if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { | ||
177 | - backIndex = cameraIndex; | ||
178 | - } | ||
179 | - } | ||
180 | - | ||
181 | - currentCameraType = type; | ||
182 | - if (type == FRONT && frontIndex != -1) { | ||
183 | - curCameraIndex = frontIndex; | ||
184 | - return Camera.open(frontIndex); | ||
185 | - } else if (type == BACK && backIndex != -1) { | ||
186 | - curCameraIndex = backIndex; | ||
187 | - return Camera.open(backIndex); | ||
188 | - } | ||
189 | - return null; | ||
190 | - } | ||
191 | - private void initCamera(SurfaceHolder holder) { | ||
192 | - Log.i(TAG, "initCamera.."); | ||
193 | - | ||
194 | - if (mPreviewRunning) { | ||
195 | - if(mCamera!=null) | ||
196 | - mCamera.stopPreview(); | ||
197 | - } | ||
198 | - | ||
199 | - Camera.Parameters parameters; | ||
200 | - try { | ||
201 | - parameters = mCamera.getParameters(); | ||
202 | - } catch (Exception e) { | ||
203 | - // TODO Auto-generated catch block | ||
204 | - e.printStackTrace(); | ||
205 | - return; | ||
206 | - } | ||
207 | - | ||
208 | - parameters.setPreviewSize(videoWidth, videoHight); | ||
209 | - parameters.setPictureFormat(PixelFormat.JPEG); | ||
210 | - parameters.setPreviewFormat(PixelFormat.YCbCr_420_SP); | ||
211 | - setCameraDisplayOrientation(mActivity, curCameraIndex, mCamera); | ||
212 | - mCamera.setParameters(parameters); | ||
213 | - int bufferSize = (((videoWidth | 0xf) + 1) * videoHight * ImageFormat.getBitsPerPixel(parameters.getPreviewFormat())) / 8; | ||
214 | - mCamera.addCallbackBuffer(new byte[bufferSize]); | ||
215 | - | ||
216 | - mCamera.setPreviewCallbackWithBuffer(this); | ||
217 | - try { | ||
218 | - mCamera.setPreviewDisplay(holder); | ||
219 | - } catch (Exception ex) { | ||
220 | - // TODO Auto-generated catch block | ||
221 | - if (null != mCamera) { | ||
222 | - mCamera.release(); | ||
223 | - mCamera = null; | ||
224 | - } | ||
225 | - ex.printStackTrace(); | ||
226 | - } | ||
227 | - mCamera.startPreview(); | ||
228 | - mCamera.autoFocus(myAutoFocusCallback); | ||
229 | - mPreviewRunning = true; | ||
230 | - } | ||
231 | - | ||
232 | - | ||
233 | - @Override | ||
234 | - public void surfaceCreated(SurfaceHolder holder) { | ||
235 | - XdyLogUtil.e(TAG,"holder Create"); | ||
236 | - | ||
237 | - } | ||
238 | - | ||
239 | - @Override | ||
240 | - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { | ||
241 | - initCamera(holder); | ||
242 | - } | ||
243 | - | ||
244 | - @Override | ||
245 | - public void surfaceDestroyed(SurfaceHolder holder) { | ||
246 | - | ||
247 | - } | ||
248 | - @Override | ||
249 | - public void onPreviewFrame(byte[] data, Camera camera) { | ||
250 | - frameCount++; | ||
251 | - if (frameCount % 3000 == 0) { | ||
252 | - XdyLogUtil.i("OnPre", "gc+"); | ||
253 | - System.gc(); | ||
254 | - XdyLogUtil.i("OnPre", "gc-"); | ||
255 | - } | ||
256 | - | ||
257 | - if (data == null) { | ||
258 | - Camera.Parameters params = camera.getParameters(); | ||
259 | - Camera.Size size = params.getPreviewSize(); | ||
260 | - int bufferSize = (((size.width | 0x1f) + 1) * size.height * ImageFormat.getBitsPerPixel(params.getPreviewFormat())) / 8; | ||
261 | - camera.addCallbackBuffer(new byte[bufferSize]); | ||
262 | - } else { | ||
263 | - if (isStart) { | ||
264 | - xdyPublisher.SmartPublisherOnCaptureVideoData(data, data.length, currentCameraType, currentOrigentation); | ||
265 | - } | ||
266 | - camera.addCallbackBuffer(data); | ||
267 | - } | ||
268 | - | ||
269 | - } | ||
270 | - | ||
271 | - //Check if it has back camera | ||
272 | - private int findBackCamera() { | ||
273 | - int cameraCount = 0; | ||
274 | - Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); | ||
275 | - cameraCount = Camera.getNumberOfCameras(); | ||
276 | - | ||
277 | - for (int camIdx = 0; camIdx < cameraCount; camIdx++) { | ||
278 | - Camera.getCameraInfo(camIdx, cameraInfo); | ||
279 | - if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { | ||
280 | - return camIdx; | ||
281 | - } | ||
282 | - } | ||
283 | - return -1; | ||
284 | - } | ||
285 | - | ||
286 | - //Check if it has front camera | ||
287 | - private int findFrontCamera() { | ||
288 | - int cameraCount = 0; | ||
289 | - Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); | ||
290 | - cameraCount = Camera.getNumberOfCameras(); | ||
291 | - | ||
292 | - for (int camIdx = 0; camIdx < cameraCount; camIdx++) { | ||
293 | - Camera.getCameraInfo(camIdx, cameraInfo); | ||
294 | - if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { | ||
295 | - return camIdx; | ||
296 | - } | ||
297 | - } | ||
298 | - return -1; | ||
299 | - } | ||
300 | - private void switchCamera() throws IOException { | ||
301 | - mCamera.setPreviewCallback(null); | ||
302 | - mCamera.stopPreview(); | ||
303 | - mCamera.release(); | ||
304 | - if (currentCameraType == FRONT) { | ||
305 | - mCamera = openCamera(BACK); | ||
306 | - } else if (currentCameraType == BACK) { | ||
307 | - mCamera = openCamera(FRONT); | ||
308 | - } | ||
309 | - | ||
310 | - initCamera(pubSurfaceViewHolder); | ||
311 | - } | ||
312 | - private void SetCameraFPS(Camera.Parameters parameters) { | ||
313 | - if (parameters == null) | ||
314 | - return; | ||
315 | - | ||
316 | - int[] findRange = null; | ||
317 | - | ||
318 | - int defFPS = 20 * 1000; | ||
319 | - | ||
320 | - List<int[]> fpsList = parameters.getSupportedPreviewFpsRange(); | ||
321 | - if (fpsList != null && fpsList.size() > 0) { | ||
322 | - for (int i = 0; i < fpsList.size(); ++i) { | ||
323 | - int[] range = fpsList.get(i); | ||
324 | - if (range != null | ||
325 | - && Camera.Parameters.PREVIEW_FPS_MIN_INDEX < range.length | ||
326 | - && Camera.Parameters.PREVIEW_FPS_MAX_INDEX < range.length) { | ||
327 | - XdyLogUtil.i(TAG, "Camera index:" + i + " support min fps:" + range[Camera.Parameters.PREVIEW_FPS_MIN_INDEX]); | ||
328 | - | ||
329 | - XdyLogUtil.i(TAG, "Camera index:" + i + " support max fps:" + range[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); | ||
330 | - | ||
331 | - if (findRange == null) { | ||
332 | - if (defFPS <= range[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]) { | ||
333 | - findRange = range; | ||
334 | - | ||
335 | - XdyLogUtil.i(TAG, "Camera found appropriate fps, min fps:" + range[Camera.Parameters.PREVIEW_FPS_MIN_INDEX] | ||
336 | - + " ,max fps:" + range[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); | ||
337 | - } | ||
338 | - } | ||
339 | - } | ||
340 | - } | ||
341 | - } | ||
342 | - | ||
343 | - if (findRange != null) { | ||
344 | - parameters.setPreviewFpsRange(findRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], findRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); | ||
345 | - } | ||
346 | - } | ||
347 | - | ||
348 | - class EventHande implements SmartEventCallback { | ||
349 | - @Override | ||
350 | - public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) { | ||
351 | - switch (code) { | ||
352 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED: | ||
353 | - XdyLogUtil.i(TAG, "开始。。"); | ||
354 | - break; | ||
355 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING: | ||
356 | - XdyLogUtil.i(TAG, "连接中。。"); | ||
357 | - break; | ||
358 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED: | ||
359 | - XdyLogUtil.i(TAG, "连接失败。。"); | ||
360 | - break; | ||
361 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED: | ||
362 | - XdyLogUtil.i(TAG, "连接成功。。"); | ||
363 | - //TODO | ||
364 | - break; | ||
365 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED: | ||
366 | - XdyLogUtil.i(TAG, "连接断开。。"); | ||
367 | - break; | ||
368 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP: | ||
369 | - XdyLogUtil.i(TAG, "关闭。。"); | ||
370 | - break; | ||
371 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO: | ||
372 | - XdyLogUtil.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2); | ||
373 | - break; | ||
374 | - case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED: | ||
375 | - XdyLogUtil.i(TAG, "收不到媒体数据,可能是url错误。。"); | ||
376 | - } | ||
377 | - | ||
378 | - } | ||
379 | - } | ||
380 | - | ||
381 | - private void setCameraDisplayOrientation(Activity activity, int cameraId, android.hardware.Camera camera) { | ||
382 | - android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); | ||
383 | - android.hardware.Camera.getCameraInfo(cameraId, info); | ||
384 | - int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); | ||
385 | - int degrees = 0; | ||
386 | - switch (rotation) { | ||
387 | - case Surface.ROTATION_0: | ||
388 | - degrees = 0; | ||
389 | - break; | ||
390 | - case Surface.ROTATION_90: | ||
391 | - degrees = 90; | ||
392 | - break; | ||
393 | - case Surface.ROTATION_180: | ||
394 | - degrees = 180; | ||
395 | - break; | ||
396 | - case Surface.ROTATION_270: | ||
397 | - degrees = 270; | ||
398 | - break; | ||
399 | - } | ||
400 | - int result; | ||
401 | - if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { | ||
402 | - result = (info.orientation + degrees) % 360; | ||
403 | - result = (360 - result) % 360; | ||
404 | - } else { | ||
405 | - // back-facing | ||
406 | - result = (info.orientation - degrees + 360) % 360; | ||
407 | - } | ||
408 | - | ||
409 | - XdyLogUtil.i(TAG, "curDegree: " + result); | ||
410 | - | ||
411 | - camera.setDisplayOrientation(result); | ||
412 | - } | ||
413 | - | ||
414 | - /** | ||
415 | - * 停止推流 | ||
416 | - */ | ||
417 | - protected void onStopPublisher() { | ||
418 | - if (audioRecord_ != null) { | ||
419 | - XdyLogUtil.i(TAG, "surfaceDestroyed, call StopRecording.."); | ||
420 | - audioRecord_.StopRecording(); | ||
421 | - audioRecord_ = null; | ||
422 | - } | ||
423 | - if (xdyPublisher != null) { | ||
424 | - xdyPublisher.SmartPublisherStop(); | ||
425 | - } | ||
426 | - if(mCamera!=null){ | ||
427 | - mCamera.release();//释放相机资源 | ||
428 | - mCamera=null; | ||
429 | - } | ||
430 | - XdyLogUtil.e("audio","执行"); | ||
431 | - isStart=false; | ||
432 | - } | ||
433 | - | ||
434 | - /** | ||
435 | - * onPause 方法调用,不释放相机资源 | ||
436 | - */ | ||
437 | - protected void onPausePublisher(){ | ||
438 | - isStart=false; | ||
439 | - if (audioRecord_ != null) { | ||
440 | - XdyLogUtil.i(TAG, "surfaceDestroyed, call StopRecording.."); | ||
441 | - audioRecord_.StopRecording(); | ||
442 | - audioRecord_ = null; | ||
443 | - } | ||
444 | - if (xdyPublisher != null) { | ||
445 | - xdyPublisher.SmartPublisherStop(); | ||
446 | - } | ||
447 | - if(mCamera!=null) { | ||
448 | - mCamera.stopPreview(); | ||
449 | - } | ||
450 | - | ||
451 | - } | ||
452 | - public void onResumePublisher(){ | ||
453 | - isStart=true; | ||
454 | - } | ||
455 | - | ||
456 | - private int setHardwareEncoderKbps(int width, int height) | ||
457 | - { | ||
458 | - int hwEncoderKpbs = 0; | ||
459 | - | ||
460 | - switch(width) { | ||
461 | - case 176: | ||
462 | - hwEncoderKpbs = 300; | ||
463 | - break; | ||
464 | - case 320: | ||
465 | - hwEncoderKpbs = 500; | ||
466 | - break; | ||
467 | - case 640: | ||
468 | - hwEncoderKpbs = 1000; | ||
469 | - break; | ||
470 | - case 1280: | ||
471 | - hwEncoderKpbs = 1700; | ||
472 | - break; | ||
473 | - default: | ||
474 | - hwEncoderKpbs = 1000; | ||
475 | - } | ||
476 | - | ||
477 | - return hwEncoderKpbs; | ||
478 | - } | ||
479 | -} |
@@ -21,6 +21,8 @@ import com.mang.xdy.common.Constants; | @@ -21,6 +21,8 @@ import com.mang.xdy.common.Constants; | ||
21 | import com.mang.xdy.listener.ObserverListener; | 21 | import com.mang.xdy.listener.ObserverListener; |
22 | import com.mang.xdy.listener.SubjectListener; | 22 | import com.mang.xdy.listener.SubjectListener; |
23 | import com.mang.xdy.message.MsgManage; | 23 | import com.mang.xdy.message.MsgManage; |
24 | +import com.mang.xdy.play.XdyPlayer; | ||
25 | +import com.mang.xdy.play.XdyPublisher; | ||
24 | import com.mang.xdy.utils.JsonUtil; | 26 | import com.mang.xdy.utils.JsonUtil; |
25 | import com.mang.xdy.utils.NetWorkUtils; | 27 | import com.mang.xdy.utils.NetWorkUtils; |
26 | import com.mang.xdy.utils.PlayerUtils; | 28 | import com.mang.xdy.utils.PlayerUtils; |
@@ -46,11 +48,11 @@ public class XdySdk implements SubjectListener{ | @@ -46,11 +48,11 @@ public class XdySdk implements SubjectListener{ | ||
46 | /** | 48 | /** |
47 | * 用户初始化,还是调用各种方法,都需要统一的对外给出监听事件 | 49 | * 用户初始化,还是调用各种方法,都需要统一的对外给出监听事件 |
48 | */ | 50 | */ |
49 | - private static XdyJsCore mXdyJsCore; | 51 | + private static XdyJsCore mXdyJsCore; |
50 | private static XdySdk mXdySdk; | 52 | private static XdySdk mXdySdk; |
51 | - private static Context mContext; | ||
52 | - private XdyPlayerCore mXdyPlayerCore; | ||
53 | - private XdyPublisherCore mXdyPublisherCore; | 53 | + private static Context mContext; |
54 | + private XdyPlayer mXdyPlayer; | ||
55 | + private XdyPublisher mXdyPublisher; | ||
54 | /*消息管理*/ | 56 | /*消息管理*/ |
55 | private static MsgManage mMsgManage; | 57 | private static MsgManage mMsgManage; |
56 | 58 | ||
@@ -62,7 +64,7 @@ public class XdySdk implements SubjectListener{ | @@ -62,7 +64,7 @@ public class XdySdk implements SubjectListener{ | ||
62 | //TODO 拿不到同步的数据先保留信息(必须释放,否者内存泄漏) | 64 | //TODO 拿不到同步的数据先保留信息(必须释放,否者内存泄漏) |
63 | private SurfaceView mSurfaceView_Publish; | 65 | private SurfaceView mSurfaceView_Publish; |
64 | private Activity mActivity; | 66 | private Activity mActivity; |
65 | - /*是否正在推流,mcu自动断开的时候使用,推流成功后才表示正在使用*/ | 67 | + /*是否正在推流,mcu自动断开,onPause使用的时候使用,推流成功后才表示正在使用*/ |
66 | private boolean isPublisher =false; | 68 | private boolean isPublisher =false; |
67 | // /*Audio 推送中,resume需要使用*/ | 69 | // /*Audio 推送中,resume需要使用*/ |
68 | private boolean isPublisherAudio=false; | 70 | private boolean isPublisherAudio=false; |
@@ -75,7 +77,7 @@ public class XdySdk implements SubjectListener{ | @@ -75,7 +77,7 @@ public class XdySdk implements SubjectListener{ | ||
75 | /*推流地址*/ | 77 | /*推流地址*/ |
76 | private String publish_url=""; | 78 | private String publish_url=""; |
77 | /*保存nodeid ,自己的唯一标识*/ | 79 | /*保存nodeid ,自己的唯一标识*/ |
78 | - private int nodeId=0; | 80 | + private int mNodeId =0; |
79 | 81 | ||
80 | @Override | 82 | @Override |
81 | public void add(ObserverListener observerListener) { | 83 | public void add(ObserverListener observerListener) { |
@@ -97,7 +99,8 @@ public class XdySdk implements SubjectListener{ | @@ -97,7 +99,8 @@ public class XdySdk implements SubjectListener{ | ||
97 | } | 99 | } |
98 | } | 100 | } |
99 | } | 101 | } |
100 | - private XdySdk(){} | 102 | + private XdySdk(){ |
103 | + } | ||
101 | 104 | ||
102 | private static Handler handler=new Handler(){ | 105 | private static Handler handler=new Handler(){ |
103 | @Override | 106 | @Override |
@@ -149,6 +152,9 @@ public class XdySdk implements SubjectListener{ | @@ -149,6 +152,9 @@ public class XdySdk implements SubjectListener{ | ||
149 | onPlayDestroy(); | 152 | onPlayDestroy(); |
150 | break; | 153 | break; |
151 | } | 154 | } |
155 | + if(!isRecordPlayBack &&!judegeNetOK()){ | ||
156 | + return; | ||
157 | + } | ||
152 | handler.post(new Runnable() { | 158 | handler.post(new Runnable() { |
153 | @Override | 159 | @Override |
154 | public void run() { | 160 | public void run() { |
@@ -169,6 +175,9 @@ public class XdySdk implements SubjectListener{ | @@ -169,6 +175,9 @@ public class XdySdk implements SubjectListener{ | ||
169 | */ | 175 | */ |
170 | public void api(String type,String mediaId, SurfaceView surfaceView, Activity activity) { | 176 | public void api(String type,String mediaId, SurfaceView surfaceView, Activity activity) { |
171 | judgeString(type); | 177 | judgeString(type); |
178 | + if(!isRecordPlayBack &&!judegeNetOK()){ | ||
179 | + return; | ||
180 | + } | ||
172 | switch (type) { | 181 | switch (type) { |
173 | case Constants.PLAY_AUDIO: | 182 | case Constants.PLAY_AUDIO: |
174 | //判断mediaId (仅播放需要)通过取得value 如果为空的话表示输入的数据有误 | 183 | //判断mediaId (仅播放需要)通过取得value 如果为空的话表示输入的数据有误 |
@@ -186,12 +195,12 @@ public class XdySdk implements SubjectListener{ | @@ -186,12 +195,12 @@ public class XdySdk implements SubjectListener{ | ||
186 | //如果是回放给出。m3u8的id用户 用户需要自己获取play_url_audio=audioPlayBean.getReplay(); | 195 | //如果是回放给出。m3u8的id用户 用户需要自己获取play_url_audio=audioPlayBean.getReplay(); |
187 | }else{ | 196 | }else{ |
188 | play_url_audio=audioPlayBean.getRtmpUrl() ; | 197 | play_url_audio=audioPlayBean.getRtmpUrl() ; |
189 | - if(mXdyPlayerCore==null) { | ||
190 | - mXdyPlayerCore = XdyPlayerCore.getXdyPlayerCore(play_url_audio, activity); | 198 | + if(mXdyPlayer ==null) { |
199 | + mXdyPlayer = XdyPlayer.getXdyPlayerCore(play_url_audio, activity); | ||
191 | }else{ | 200 | }else{ |
192 | - mXdyPlayerCore.onStopPlay(); | 201 | + mXdyPlayer.onStopPlay(); |
193 | } | 202 | } |
194 | - mXdyPlayerCore.playAudio(play_url_audio, new EventHande_Play()); | 203 | + mXdyPlayer.playAudio(play_url_audio, new EventHande_Play()); |
195 | } | 204 | } |
196 | 205 | ||
197 | }else{ | 206 | }else{ |
@@ -215,13 +224,13 @@ public class XdySdk implements SubjectListener{ | @@ -215,13 +224,13 @@ public class XdySdk implements SubjectListener{ | ||
215 | // play_url_video=videoPlayBean.getReplay(); | 224 | // play_url_video=videoPlayBean.getReplay(); |
216 | }else{ | 225 | }else{ |
217 | play_url_video=videoPlayBean.getRtmpUrl(); | 226 | play_url_video=videoPlayBean.getRtmpUrl(); |
218 | - if(mXdyPlayerCore==null) { | ||
219 | - mXdyPlayerCore = XdyPlayerCore.getXdyPlayerCore(play_url_video, activity); | 227 | + if(mXdyPlayer ==null) { |
228 | + mXdyPlayer = XdyPlayer.getXdyPlayerCore(play_url_video, activity); | ||
220 | }else{ | 229 | }else{ |
221 | //重复播放时候 | 230 | //重复播放时候 |
222 | - mXdyPlayerCore.onStopPlay(); | 231 | + mXdyPlayer.onStopPlay(); |
223 | } | 232 | } |
224 | - mXdyPlayerCore.playVideo(play_url_video, surfaceView,new EventHande_Play()); | 233 | + mXdyPlayer.playVideo(play_url_video, surfaceView,new EventHande_Play()); |
225 | } | 234 | } |
226 | 235 | ||
227 | }else{ | 236 | }else{ |
@@ -243,7 +252,6 @@ public class XdySdk implements SubjectListener{ | @@ -243,7 +252,6 @@ public class XdySdk implements SubjectListener{ | ||
243 | case Constants.PUBLISH_AUDIO: | 252 | case Constants.PUBLISH_AUDIO: |
244 | //只推送音频 | 253 | //只推送音频 |
245 | getPublishPathAudio(); | 254 | getPublishPathAudio(); |
246 | -// mSurfaceView=surfaceView; | ||
247 | mActivity=activity; | 255 | mActivity=activity; |
248 | break; | 256 | break; |
249 | 257 | ||
@@ -261,21 +269,17 @@ public class XdySdk implements SubjectListener{ | @@ -261,21 +269,17 @@ public class XdySdk implements SubjectListener{ | ||
261 | XdyLogUtil.e(TAG,Constants.ERROR_TYPE_NULL); | 269 | XdyLogUtil.e(TAG,Constants.ERROR_TYPE_NULL); |
262 | } | 270 | } |
263 | } | 271 | } |
264 | - /*判断是否是合法的url*/ | ||
265 | - protected void judgeUrl(String url){ | ||
266 | - if (url == null) | ||
267 | - return; | ||
268 | - | ||
269 | - // rtmp:// | ||
270 | - if (url.length() < 8) { | ||
271 | - Log.e(TAG, "Input publish url error:" + url); | ||
272 | - return; | ||
273 | - } | ||
274 | - | ||
275 | - if (!url.startsWith("rtmp://")) { | ||
276 | - Log.e(TAG, "Input publish url error:" + url); | ||
277 | - return; | 272 | + /*判断网路是否正常*/ |
273 | + private boolean judegeNetOK(){ | ||
274 | + if( !NetWorkUtils.isNetworkConnected(mContext)){ | ||
275 | + String errorJson="{\n" + | ||
276 | + " \"code\": 20000,\n" + | ||
277 | + " \"reson\": \"无网络连接,请检查网络\"\n" + | ||
278 | + "}"; | ||
279 | + notifyObserver(Constants.ERROR_CODE, errorJson); | ||
280 | + return false; | ||
278 | } | 281 | } |
282 | + return true; | ||
279 | } | 283 | } |
280 | 284 | ||
281 | public static XdySdk getXdyInstance(){ | 285 | public static XdySdk getXdyInstance(){ |
@@ -306,7 +310,7 @@ public class XdySdk implements SubjectListener{ | @@ -306,7 +310,7 @@ public class XdySdk implements SubjectListener{ | ||
306 | try { | 310 | try { |
307 | jsonObject = new JSONObject(response); | 311 | jsonObject = new JSONObject(response); |
308 | isRecordPlayBack = jsonObject.optBoolean("isRecordPlayBack"); | 312 | isRecordPlayBack = jsonObject.optBoolean("isRecordPlayBack"); |
309 | - nodeId=jsonObject.optInt("nodeId"); | 313 | + mNodeId =jsonObject.optInt("mNodeId"); |
310 | } catch (JSONException e) { | 314 | } catch (JSONException e) { |
311 | e.printStackTrace(); | 315 | e.printStackTrace(); |
312 | } | 316 | } |
@@ -333,16 +337,16 @@ public class XdySdk implements SubjectListener{ | @@ -333,16 +337,16 @@ public class XdySdk implements SubjectListener{ | ||
333 | //TODo 给出提示 | 337 | //TODo 给出提示 |
334 | throw new IllegalArgumentException(Constants.ERROR_TYPE_ACTIVITY); | 338 | throw new IllegalArgumentException(Constants.ERROR_TYPE_ACTIVITY); |
335 | } | 339 | } |
336 | - if (mXdyPublisherCore == null) { | ||
337 | - mXdyPublisherCore = new XdyPublisherCore(1, 1, mActivity); | 340 | + if (mXdyPublisher == null) { |
341 | + mXdyPublisher = new XdyPublisher(1, 1, mActivity); | ||
338 | }else{ | 342 | }else{ |
339 | //todo 如果不为空的话是已经播放过,得清理上次的 | 343 | //todo 如果不为空的话是已经播放过,得清理上次的 |
340 | - mXdyPlayerCore.onPause(); | 344 | +// mXdyPlayer.onPause(); |
341 | } | 345 | } |
342 | publish_url=video_url; | 346 | publish_url=video_url; |
343 | isPublisher =true; | 347 | isPublisher =true; |
344 | isPublisherAudio=false; | 348 | isPublisherAudio=false; |
345 | - mXdyPublisherCore.publisher(video_url,mSurfaceView_Publish, new EventHande_Publish()); | 349 | + mXdyPublisher.publisher(video_url,mSurfaceView_Publish, new EventHande_Publish()); |
346 | // PlayerUtils.setPublishSendSuccessVideo(aCache.getAsString(Constants.GET_VIDEO_PUBLISH_PATH)); | 350 | // PlayerUtils.setPublishSendSuccessVideo(aCache.getAsString(Constants.GET_VIDEO_PUBLISH_PATH)); |
347 | //// TODO: 2017/4/13 大牛连接成功回调没有监听到 暂时在这告知后台,(后续加上网路判断,摄像头判断) | 351 | //// TODO: 2017/4/13 大牛连接成功回调没有监听到 暂时在这告知后台,(后续加上网路判断,摄像头判断) |
348 | setPublishSendSuccessVideo(video_url); | 352 | setPublishSendSuccessVideo(video_url); |
@@ -379,13 +383,13 @@ public class XdySdk implements SubjectListener{ | @@ -379,13 +383,13 @@ public class XdySdk implements SubjectListener{ | ||
379 | XdyLogUtil.e(TAG,"activity is null"); | 383 | XdyLogUtil.e(TAG,"activity is null"); |
380 | return; | 384 | return; |
381 | } | 385 | } |
382 | - if(mXdyPublisherCore==null) { | ||
383 | - mXdyPublisherCore = new XdyPublisherCore(1, 0, mActivity); | 386 | + if(mXdyPublisher ==null) { |
387 | + mXdyPublisher = new XdyPublisher(1, 0, mActivity); | ||
384 | }else { | 388 | }else { |
385 | //todo 如果不为空的话是已经播放过,得清理上次的 | 389 | //todo 如果不为空的话是已经播放过,得清理上次的 |
386 | - mXdyPlayerCore.onPause(); | 390 | +// mXdyPlayer.onPause(); |
387 | } | 391 | } |
388 | - mXdyPublisherCore.publisherAudio(audio_url,new EventHande_Publish()); | 392 | + mXdyPublisher.publisherAudio(audio_url,new EventHande_Publish()); |
389 | publish_url=audio_url; | 393 | publish_url=audio_url; |
390 | isPublisher =true; | 394 | isPublisher =true; |
391 | isPublisherAudio=true; | 395 | isPublisherAudio=true; |
@@ -441,7 +445,7 @@ public class XdySdk implements SubjectListener{ | @@ -441,7 +445,7 @@ public class XdySdk implements SubjectListener{ | ||
441 | VideoPlayBean videoPlayBean= JsonUtil.parseJsonToBean(video,VideoPlayBean.class); | 445 | VideoPlayBean videoPlayBean= JsonUtil.parseJsonToBean(video,VideoPlayBean.class); |
442 | if(videoPlayBean!=null) { | 446 | if(videoPlayBean!=null) { |
443 | // if(videoPlayBean.getMediaId()!=videoPlayBean.getFromNodeId()) { | 447 | // if(videoPlayBean.getMediaId()!=videoPlayBean.getFromNodeId()) { |
444 | - if(nodeId!=videoPlayBean.getFromNodeId()) { | 448 | + if(mNodeId !=videoPlayBean.getFromNodeId()) { |
445 | //过滤自己推送的video | 449 | //过滤自己推送的video |
446 | aCache.put(videoPlayBean.getMediaId() + "", video); | 450 | aCache.put(videoPlayBean.getMediaId() + "", video); |
447 | handleListener(type, videoPlayBean.getMediaId() + ""); | 451 | handleListener(type, videoPlayBean.getMediaId() + ""); |
@@ -455,7 +459,7 @@ public class XdySdk implements SubjectListener{ | @@ -455,7 +459,7 @@ public class XdySdk implements SubjectListener{ | ||
455 | AudioPlayBean audioPlayBean=JsonUtil.parseJsonToBean(audio,AudioPlayBean.class); | 459 | AudioPlayBean audioPlayBean=JsonUtil.parseJsonToBean(audio,AudioPlayBean.class); |
456 | if(audioPlayBean!=null){ | 460 | if(audioPlayBean!=null){ |
457 | // if(audioPlayBean.getMediaId()!=audioPlayBean.getFromNodeId()) { | 461 | // if(audioPlayBean.getMediaId()!=audioPlayBean.getFromNodeId()) { |
458 | - if(nodeId!=audioPlayBean.getFromNodeId()) { | 462 | + if(mNodeId !=audioPlayBean.getFromNodeId()) { |
459 | aCache.put(audioPlayBean.getMediaId() + "", audio); | 463 | aCache.put(audioPlayBean.getMediaId() + "", audio); |
460 | handleListener(type, audioPlayBean.getMediaId() + ""); | 464 | handleListener(type, audioPlayBean.getMediaId() + ""); |
461 | } | 465 | } |
@@ -521,9 +525,9 @@ public class XdySdk implements SubjectListener{ | @@ -521,9 +525,9 @@ public class XdySdk implements SubjectListener{ | ||
521 | */ | 525 | */ |
522 | public boolean onPlayStop(String id){ | 526 | public boolean onPlayStop(String id){ |
523 | if(currentPlayId.equals(id)) { | 527 | if(currentPlayId.equals(id)) { |
524 | - if (mXdyPlayerCore != null) { | ||
525 | - mXdyPlayerCore.onStopPlay(); | ||
526 | -// mXdyPlayerCore = null; | 528 | + if (mXdyPlayer != null) { |
529 | + mXdyPlayer.onStopPlay(); | ||
530 | +// mXdyPlayer = null; | ||
527 | 531 | ||
528 | } | 532 | } |
529 | return true; | 533 | return true; |
@@ -534,8 +538,8 @@ public class XdySdk implements SubjectListener{ | @@ -534,8 +538,8 @@ public class XdySdk implements SubjectListener{ | ||
534 | * 退出时清除信息(重置js监听) | 538 | * 退出时清除信息(重置js监听) |
535 | */ | 539 | */ |
536 | public void removeAll(){ | 540 | public void removeAll(){ |
537 | - if(mXdyPlayerCore!=null) { | ||
538 | - mXdyPlayerCore.onPause(); | 541 | + if(mXdyPlayer !=null) { |
542 | + mXdyPlayer.onPause(); | ||
539 | } | 543 | } |
540 | if(mXdyJsCore!=null&&!isRecordPlayBack) { | 544 | if(mXdyJsCore!=null&&!isRecordPlayBack) { |
541 | mXdyJsCore.init(mContext); | 545 | mXdyJsCore.init(mContext); |
@@ -547,9 +551,9 @@ public class XdySdk implements SubjectListener{ | @@ -547,9 +551,9 @@ public class XdySdk implements SubjectListener{ | ||
547 | * 结束时调用 | 551 | * 结束时调用 |
548 | */ | 552 | */ |
549 | public void onPlayDestroy(){ | 553 | public void onPlayDestroy(){ |
550 | - if (mXdyPlayerCore != null) { | ||
551 | - mXdyPlayerCore.onStopPlay(); | ||
552 | - mXdyPlayerCore = null; | 554 | + if (mXdyPlayer != null) { |
555 | + mXdyPlayer.onStopPlay(); | ||
556 | + mXdyPlayer = null; | ||
553 | } | 557 | } |
554 | 558 | ||
555 | 559 | ||
@@ -560,9 +564,9 @@ public class XdySdk implements SubjectListener{ | @@ -560,9 +564,9 @@ public class XdySdk implements SubjectListener{ | ||
560 | * @deprecated daniu sdk handle best | 564 | * @deprecated daniu sdk handle best |
561 | */ | 565 | */ |
562 | public void onPublisherStop(){ | 566 | public void onPublisherStop(){ |
563 | - if(mXdyPublisherCore!=null){ | ||
564 | - mXdyPublisherCore.onStopPublisher(); | ||
565 | - mXdyPublisherCore=null; | 567 | + if(mXdyPublisher !=null){ |
568 | + mXdyPublisher.onStopPublisher(); | ||
569 | + mXdyPublisher =null; | ||
566 | } | 570 | } |
567 | //如果正在推流,msurfaceView ,mActivity不清空 | 571 | //如果正在推流,msurfaceView ,mActivity不清空 |
568 | if(!isPublisher) { | 572 | if(!isPublisher) { |
@@ -580,10 +584,11 @@ public class XdySdk implements SubjectListener{ | @@ -580,10 +584,11 @@ public class XdySdk implements SubjectListener{ | ||
580 | 584 | ||
581 | /** | 585 | /** |
582 | * onPause 方法时走的周期 | 586 | * onPause 方法时走的周期 |
587 | + * 推送视频暂停调用,单独提出,不与play合并考虑到有后台继续推送的情况 | ||
583 | */ | 588 | */ |
584 | public void onPublisherPause(){ | 589 | public void onPublisherPause(){ |
585 | - if(mXdyPublisherCore!=null){ | ||
586 | - mXdyPublisherCore.onPausePublisher(); | 590 | + if(mXdyPublisher !=null){ |
591 | + mXdyPublisher.onPausePublisher(); | ||
587 | } | 592 | } |
588 | } | 593 | } |
589 | 594 | ||
@@ -598,13 +603,13 @@ public class XdySdk implements SubjectListener{ | @@ -598,13 +603,13 @@ public class XdySdk implements SubjectListener{ | ||
598 | if(!isPublisher){ | 603 | if(!isPublisher){ |
599 | return; | 604 | return; |
600 | } | 605 | } |
601 | - if(mXdyPublisherCore!=null) { | ||
602 | - mXdyPublisherCore.onResumePublisher(); | 606 | + if(mXdyPublisher !=null) { |
607 | + mXdyPublisher.onResumePublisher(); | ||
603 | if (!TextUtils.isEmpty(publish_url)) { | 608 | if (!TextUtils.isEmpty(publish_url)) { |
604 | if(!isPublisherAudio){ | 609 | if(!isPublisherAudio){ |
605 | - mXdyPublisherCore.publisher(publish_url, mSurfaceView_Publish, new EventHande_Publish()); | 610 | + mXdyPublisher.publisher(publish_url, mSurfaceView_Publish, new EventHande_Publish()); |
606 | }else{ | 611 | }else{ |
607 | - mXdyPublisherCore.publisherAudio(publish_url,new EventHande_Publish()); | 612 | + mXdyPublisher.publisherAudio(publish_url,new EventHande_Publish()); |
608 | } | 613 | } |
609 | 614 | ||
610 | } | 615 | } |
@@ -38,7 +38,7 @@ public class XdyStringUtils { | @@ -38,7 +38,7 @@ public class XdyStringUtils { | ||
38 | } | 38 | } |
39 | return resString; | 39 | return resString; |
40 | } | 40 | } |
41 | - | 41 | + /*判断url*/ |
42 | public static void judgeUrl(String url){ | 42 | public static void judgeUrl(String url){ |
43 | if (url == null) | 43 | if (url == null) |
44 | return; | 44 | return; |
-
请 注册 或 登录 后发表评论