P2P直播模块(pgLibLiveMulti)安卓端编程注意事项。
1.锁屏后如果被系统清理内存了应用也就没有了.
您需要在应用销毁回调里面手动videoStop,并且Clean掉实例。这样做是防止下次登录时可能登录时间太久,因为服务器有退避机制。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
@Override protected void onDestroy() { LiveLogout(); super.onDestroy(); } private void LiveLogout() { LiveDisconnect(); if (m_Wnd != null) { m_View.removeView(m_Wnd); pgLibLiveMultiView.Release(m_Wnd); m_View = null; m_Wnd = null; m_Live.Clean(); } } |
2.如果程序没被系统清理强制退出.
在退出到后台时直接disConnect,videoStart。到前台时如果播放端还在线就直接Connect 并videostart,如果播放端不在线了就等待重新上线。此时如果想要马上登录上线,需要手动m_Live.Clean 并 重新调用初始化函数登录 ,登录成功后再打开视频。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
public int count = 0; @Override protected void onResume() { if (count == 0) { //Log.v(TAG, "切到前台"); Toast.makeText(MainActivity.this, "切到前台", Toast.LENGTH_SHORT).show(); if (m_bLogin) { m_Live.Connect(m_sDevID); m_Live.VideoStart(m_sDevID, 0, "", m_Wnd); } else { String sInfo = "因为后台放置太久导致掉线,请等待播放端重新上线"; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); } } count++; super.onResume(); } @Override protected void onPause() { count--; if (count == 0) { Toast.makeText(MainActivity.this, "切到后台", Toast.LENGTH_SHORT).show(); m_Live.VideoStop(m_sDevID, 0); m_Live.Disconnect(m_sDevID); } super.onPause(); } |
3. m_bLogin标志位设置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
private boolean m_bLogin = false; private pgLibLive.OnEventListener m_OnEvent = new pgLibLive.OnEventListener() { @Override public void event(String sAct, String sData, String sRender) { // TODO Auto-generated method stub if (sAct.equals("VideoStatus")) { // Video status report } else if (sAct.equals("Notify")) { // Receive the notify from capture side String sInfo = "Receive notify: data=" + sData; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); } else if (sAct.equals("RenderJoin")) { // A render join String sInfo = "Render join: render=" + sRender; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); } else if (sAct.equals("RenderLeave")) { // A render leave String sInfo = "Render leave: render=" + sRender; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); } else if (sAct.equals("Message")) { // Receive the message from render or capture String sInfo = "Receive msg: data=" + sData + ", render=" + sRender; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); } else if (sAct.equals("Login")) { // Login reply if (sData.equals("0")) { String sInfo = "Login success"; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); m_bLogin = true; } else { String sInfo = "Login failed, error=" + sData; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); m_bLogin = false; } } else if (sAct.equals("Logout")) { // Logout String sInfo = "Logout"; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); m_bLogin = false; } else if (sAct.equals("Connect")) { // Connect to capture String sInfo = "Connect to capture"; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); } else if (sAct.equals("Disconnect")) { // Disconnect from capture String sInfo = "Disconnect from capture"; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); } else if (sAct.equals("Reject")) { String sInfo = "Reject by capture"; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); m_bLogin = false; } else if (sAct.equals("Offline")) { // The capture is offline. String sInfo = "Capture offline"; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); m_bLogin = false; } else if (sAct.equals("LanScanResult")) { // Lan scan result. String sInfo = "Lan scan result: " + sData; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); m_sTransferInfo.setText(sData); } else if (sAct.equals("ForwardAllocReply")) { String sInfo = "Forward alloc relpy: error=" + sData; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); } else if (sAct.equals("ForwardFreeReply")) { String sInfo = "Forward free relpy: error=" + sData; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); } else if (sAct.equals("VideoCamera")) { String sInfo = "The picture is save to: " + sData; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); } else if (sAct.equals("FileAccept")) { String sInfo = "File accept: " + sData; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); } else if (sAct.equals("FileReject")) { FileReject(); } else if (sAct.equals("FileAbort")) { // 取消 上传或 下载 FileAbort(); } else if (sAct.equals("FileFinish")) {// 文件传输完毕 FileFinish(); } else if (sAct.equals("FileProgress")) { FileProgress(sData); } else if (sAct.equals("SvrNotify")) { String sInfo = "Receive server notify: " + sData; Toast.makeText(MainActivity.this, sInfo, Toast.LENGTH_SHORT).show(); } Log.d("pgLiveRender", "OnEvent: Act=" + sAct + ", Data=" + sData + ", Render=" + sRender); } }; |