对接熊迈SDK工作记录之实时视频和云录像功能集成

通过对demo和接口说明的初步了解我们可以清楚的知道,想要实现TV端的多屏监控和云录像查看,其实只要拿到自己的设备信息,然后调用相应的方法进行播放即可了。

首先看这里,官方已给我们提供了一个类似VideoView的FunVideoView类。

再看看这里,播放实时视频的方法,这就简单了,直接在demo中search一下MediaRealPlay(int hUser, String devId, int nChnIndex, int nStreamType, Object hWnd, int nSeq)这个方法就更加直接了。

下面贴一段官方公开的方法,也就是FunVideoView中播放实时视频和云录像视频和本地视频的方法。看这里MediaRealPlay()、MediaNetRecordPlayByTime()、MediaNetRecordPlay()依次为实时、云录像和本地的播放方法。

private void openVideo() {
		if (!mInited || null == mVideoUrl || mPlayStat != STAT_PLAYING
				|| null == mSufaceView) {
			return;
		}

		mFishEyeFrame = null;

		mIsPrepared = false;
		mPlayPosition = 0;

		String playPath = getPlayPath(mVideoUrl);
		if (mVideoUrl.startsWith("real://")) {
			if (!mIsPlaying) {
				// 播放实时视频
				mPlayerHandler = FunSDK.MediaRealPlay(getUserId(), playPath,
						mChannel, mStreamType.getTypeId(), mSufaceView, 0);

				// 本来注释的,打开By 吴
				FunSDK.SetIntAttr(mPlayerHandler,
						EFUN_ATTR.EOA_SET_MEDIA_DATA_USER, getUserId());
				FunSDK.MediaSetFluency(mPlayerHandler,
						SDKCONST.EDECODE_TYPE.EDECODE_REAL_TIME_STREAM6, 0);
				// 设置流畅度(实时<-->流畅)
			}
			mIsPlaying = true;
		} else if (mVideoUrl.startsWith("time://")) {
			if (!mIsPlaying) {
				// 播放录像
				int fromTime = -1;
				int toTime = -1;
				if (playPath.contains("-")) {
					String[] tmStrs = playPath.split("-");
					fromTime = Integer.parseInt(tmStrs[0]);
					toTime = Integer.parseInt(tmStrs[1]);
				} else {
					fromTime = Integer.parseInt(playPath);
				}

				Date fromDate = new Date((long) fromTime * 1000);
				H264_DVR_FINDINFO fileInfo = new H264_DVR_FINDINFO();

				fileInfo.st_0_nChannelN0 = mChannel;
				fileInfo.st_2_startTime.st_0_dwYear = fromDate.getYear() + 1900;
				fileInfo.st_2_startTime.st_1_dwMonth = fromDate.getMonth() + 1;
				fileInfo.st_2_startTime.st_2_dwDay = fromDate.getDate();
				fileInfo.st_2_startTime.st_3_dwHour = fromDate.getHours();
				fileInfo.st_2_startTime.st_4_dwMinute = fromDate.getMinutes();
				fileInfo.st_2_startTime.st_5_dwSecond = fromDate.getSeconds();
				if (toTime > 0 && toTime > fromTime) {
					Date toDate = new Date((long) toTime * 1000);

					fileInfo.st_3_endTime.st_0_dwYear = toDate.getYear() + 1900;
					fileInfo.st_3_endTime.st_1_dwMonth = toDate.getMonth() + 1;
					fileInfo.st_3_endTime.st_2_dwDay = toDate.getDate();
					fileInfo.st_3_endTime.st_3_dwHour = toDate.getHours();
					fileInfo.st_3_endTime.st_4_dwMinute = toDate.getMinutes();
					fileInfo.st_3_endTime.st_5_dwSecond = toDate.getSeconds();
				} else {
					fileInfo.st_3_endTime.st_0_dwYear = fromDate.getYear() + 1900;
					fileInfo.st_3_endTime.st_1_dwMonth = fromDate.getMonth() + 1;
					fileInfo.st_3_endTime.st_2_dwDay = fromDate.getDate();
					fileInfo.st_3_endTime.st_3_dwHour = 23;
					fileInfo.st_3_endTime.st_4_dwMinute = 59;
					fileInfo.st_3_endTime.st_5_dwSecond = 59;
				}
				fileInfo.st_6_StreamType = mStreamType.getTypeId();

				mPlayerHandler = FunSDK.MediaNetRecordPlayByTime(getUserId(),
						mDeviceSn, G.ObjToBytes(fileInfo), mSufaceView, 0);
			}
			mIsPlaying = true;
		} else if (mVideoUrl.startsWith("file://")) {
			if (!mIsPlaying) {
				mPlayerHandler = FunSDK.MediaNetRecordPlay(getUserId(),
						mDeviceSn, G.ObjToBytes(mVideoFile), mSufaceView, 0);
			}
			mIsPlaying = true;
		}
	}

到这里为止就可以实现我想要的功能了,接下来剩下的就是多屏的问题了,其实也不难,是你太悲观。看看demo就会发现,其实直接new一个gridview来加载多个FunVideoView就可以了。

    // 初始化播放窗口 9个
	GridCameraChannelsPreviewsAdapter cadapter = new GridCameraChannelsPreviewsAdapter(this, 9);
	gridview.setAdapter(cadapter);
    //播放视频
    @SuppressLint("ClickableViewAccessibility")
	public void playrealvideo() {
		for (int i = 0; i < 10; i++) {
			View v = gridview.findViewWithTag(i);
			if (null != v) {
				funVideoView = (FunVideoView) v
						.findViewById(R.id.funVideoView1);
				// funVideoView.getLayoutParams().height = getWindowManager()
				// .getDefaultDisplay().getHeight() / 4 + 10;
				textStart = (TextView) v.findViewById(R.id.textVideoStat1);
			}
			funVideoView.setOnErrorListener(this);
			funVideoView.setOnInfoListener(this);
			funVideoView.setOnTouchListener(new OnItemViewTouchListener(i));
			funvideovlist.add(funVideoView);
			textvlist.add(textStart);
			// 显示状态: 正在打开视频...
			textStart.setText(R.string.media_player_opening);
			textStart.setVisibility(View.VISIBLE);

			// cadapter.notifyDataSetInvalidated();
			if (i < 4) {//我只有4个摄像头,不判断在低版本下会报错
				if (mFunDevice.isRemote) {
					funVideoView.setRealDevice(mFunDevice.getDevSn(), i);
				} else {
					String deviceIp = FunSupport.getInstance()
							.getDeviceWifiManager().getGatewayIp();
					funVideoView.setRealDevice(deviceIp, i);
				}
			}
		}
	}

熊迈sdk还是实现了很多实用而又不华丽的功能了,详情请参见熊买SDK,OK下班了,说的比较笼统,有什么不懂的可以直接联系官方业务人员,当然只要我知道的也是可以全力解答哈,记住我,我叫玉念聿辉 玉念聿辉 玉念聿辉

THE END 谢谢查看

编辑:吴明辉

没有更多推荐了,返回首页