海康威視遠端監控-Android端Demo
阿新 • • 發佈:2019-02-06
- public class VideoShowActivity extends Activity {
- /** SurfaceView物件,用來顯示視訊 */
- private SjrsSurfaceView nowSjrsSurfaceView;
- /** 視訊向上 */
- private Button btUp;
- /** 視訊向下 */
- private Button btDown;
- /** 視訊向左 */
- private Button btLeft;
- /** 視訊向右 */
- private Button btRigth;
- /** 視訊上左 */
- private Button btUpLeft;
- /** 視訊上右 */
- private Button btUpRigth;
- /** 視訊下左 */
- private Button btDownLeft;
- /** 視訊下右 */
- private Button btDownRigth;
- /** button點選事件*/
- private ButtonListener btnListener;
- /** 例項化網路庫SDK*/
- private SjrsSurfaceView mSurface;
- /** 監控點資訊類 */
- private MonitorCameraInfo cameraInfo;
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- findView();
- setListener();
- init();
- }
- /**
- * 元件配置
- */
- private void findView() {
- // TODO Auto-generated method stub
- nowSjrsSurfaceView = (SjrsSurfaceView) findViewById(R.id.video);
- btUp = (Button) findViewById(R.id.bt_up);
- btDown = (Button) findViewById(R.id.bt_down);
- btLeft = (Button) findViewById(R.id.bt_left);
- btRigth = (Button) findViewById(R.id.bt_rigth);
- btUpLeft = (Button) findViewById(R.id.bt_up_left);
- btUpRigth = (Button) findViewById(R.id.bt_up_rigth);
- btDownLeft = (Button) findViewById(R.id.bt_down_left);
- btDownRigth = (Button) findViewById(R.id.bt_down_rigth);
- btnListener = new ButtonListener();
- }
- /**
- * 監聽設定
- */
- private void setListener() {
- // TODO Auto-generated method stub
- btUp.setOnClickListener(btnListener);
- btDown.setOnClickListener(btnListener);
- btLeft.setOnClickListener(btnListener);
- btRigth.setOnClickListener(btnListener);
- btUp.setOnTouchListener(btnListener);
- btDown.setOnTouchListener(btnListener);
- btLeft.setOnTouchListener(btnListener);
- btRigth.setOnTouchListener(btnListener);
- btUpLeft.setOnClickListener(btnListener);
- btUpRigth.setOnClickListener(btnListener);
- btDownLeft.setOnClickListener(btnListener);
- btDownRigth.setOnClickListener(btnListener);
- btUpLeft.setOnTouchListener(btnListener);
- btUpRigth.setOnTouchListener(btnListener);
- btDownLeft.setOnTouchListener(btnListener);
- btDownRigth.setOnTouchListener(btnListener);
- }
- /**
- * 頁面初始化
- */
- private void init() {
- // TODO Auto-generated method stub
- mSurface = new SjrsSurfaceView(VideoShowActivity.this);
- }
- /**
- * 顯示
- */
- protected void onResume() {
- super.onResume();
- // 如果沒有在播放的話
- if (!nowSjrsSurfaceView.playFlag) {
- // 監控點資訊類
- cameraInfo = new MonitorCameraInfo();
- //224.186.114.116
- cameraInfo.serverip = "192.168.1.206";
- cameraInfo.serverport = 8000;
- cameraInfo.username = "admin";
- cameraInfo.userpwd = "12345";
- cameraInfo.channel = 2;
- cameraInfo.describe = "測試點";
- nowSjrsSurfaceView.setMonitorInfo(cameraInfo);
- // 開始實時預覽
- nowSjrsSurfaceView.startPlay();
- }
- }
- /**
- * 暫停
- */
- protected void onPause() {
- super.onPause();
- if (nowSjrsSurfaceView.playFlag) {
- nowSjrsSurfaceView.stopPlay(); // 停止實時預覽
- }
- }
- /**
- * 方向按鍵監聽
- * 注意:此處的通道號引數 實質為:2 但必須指定為:1(主通道)才可以做控制
- */
- public class ButtonListener implements OnTouchListener,OnClickListener {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- switch (v.getId()) {
- case R.id.bt_up:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,21,0);
- System.out.println("向上");
- break;
- case R.id.bt_down:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,22,0);
- System.out.println("向下");
- break;
- case R.id.bt_left:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,23,0);
- System.out.println("向左");
- break;
- case R.id.bt_rigth:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,24,0);
- System.out.println("向右");
- break;
- case R.id.bt_up_left:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,25,0);
- System.out.println("上左");
- break;
- case R.id.bt_up_rigth:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,26,0);
- System.out.println("上右");
- break;
- case R.id.bt_down_left:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,27,0);
- System.out.println("下左");
- break;
- case R.id.bt_down_rigth:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,28,0);
- System.out.println("下右");
- break;
- /*case R.id.bt_amplification:
- boolean iss = mSurface.SjrsSurface().NET_DVR_PTZControlWithSpeed(cameraInfo.playNum,15,0,3);
- System.out.println("異常:"+mSurface.SjrsSurface().NET_DVR_GetLastError());
- System.out.println("焦距放大"+iss);
- break;
- case R.id.bt_shrink:
- boolean is = mSurface.SjrsSurface().NET_DVR_PTZControlWithSpeed(cameraInfo.playNum,16,0,3);
- System.out.println("焦距縮小"+is);
- break;*/
- default:
- break;
- }
- return false;
- }
- @Override
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.bt_up:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,21,1);
- System.out.println("結束向上移動");
- break;
- case R.id.bt_down:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,22,1);
- System.out.println("結束向下移動");
- break;
- case R.id.bt_left:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,23,1);
- System.out.println("結束向左移動");
- break;
- case R.id.bt_rigth:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,24,1);
- System.out.println("結束向右移動");
- break;
- case R.id.bt_up_left:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,25,1);
- System.out.println("結束上左移動");
- break;
- case R.id.bt_up_rigth:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,26,1);
- System.out.println("結束上右移動");
- break;
- case R.id.bt_down_left:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,27,1);
- System.out.println("結束下左移動");
- break;
- case R.id.bt_down_rigth:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(cameraInfo.userId,1,28,1);
- System.out.println("結束下右移動");
- break;
- /*case R.id.bt_amplification:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(0,1,13,1);
- System.out.println("結束焦距放大");
- break;
- case R.id.bt_shrink:
- mSurface.SjrsSurface().NET_DVR_PTZControl_Other(0,1,14,1);
- System.out.println("結束焦距縮小");
- break;*/
- default:
- break;
- }
- }
- }
- }