コード例 #1
0
        public async Task <string> StopVideo()
        {
            // Stop recording
            // ->{"msg_id":514,"token":1}
            // <-{"rval":0,"msg_id":514,"param":"/tmp/fuse_d/DCIM/100MEDIA/SJCM0003.mp4"}
            // <-{ "msg_id": 7, "type": "video_record_complete" ,"param":"/tmp/fuse_d/DCIM/100MEDIA/SJCM0003.mp4"}

            UserStopVideoMessage      UsrMsg   = new UserStopVideoMessage(_token);
            UserStopVideoMessageCodec UsrCodec = new UserStopVideoMessageCodec();

            // Send the message
            string MsgSent = await UsrCodec.Encode(UsrMsg);

            if (await Send(MsgSent))
            {
                // Receive the echo message
                string MsgReceived = await _CameraSocket.Receive();

                CamParamMessageCodec CamEchoCodec = new CamParamMessageCodec();
                CamParamMessage      CamEchoMsg   = await CamEchoCodec.Decode(MsgReceived);

                if (CamEchoMsg.msg_id != UsrMsg.msg_id)
                {
                    return(null);
                }

                //Receive the video completed message
                MsgReceived = await _CameraSocket.Receive();

                CamCaptureDoneMessageCodec CptrDoneCodec = new CamCaptureDoneMessageCodec();
                CamCaptureDoneMessage      CptrDoneMsg   = await CptrDoneCodec.Decode(MsgReceived);

                // Check if msg_id and type are the expected
                if (CptrDoneMsg.msg_id != CamCaptureDoneMessage.msg_id_expected && !CptrDoneMsg.type.Equals(CamCaptureDoneMessage.video_expected))
                {
                    return(null);
                }

                _recording = false;
                // Return the location of the taken photo
                return(GetMediaLocation(CptrDoneMsg.param));
            }
            return(null);
        }
コード例 #2
0
        public async Task <string> TakePhoto()
        {
            // Take Photo
            // ->{"msg_id":769,"token":1}
            // <-{"rval":0,"msg_id":769}
            // <-{ "msg_id": 7, "type": "start_photo_capture" }
            // <-{ "msg_id": 7, "type": "photo_taken" ,"param":"/tmp/fuse_d/DCIM/100MEDIA/SJCM0004.jpg"}
            // <-{ "msg_id": 7, "type": "photo_taken" ,"param":"/tmp/fuse_d/DCIM/100MEDIA/SJCM0004.jpg"}

            UserTakePhotoMessage      UsrMsg      = new UserTakePhotoMessage(_token);
            UserTakePhotoMessageCodec UsrMsgCodec = new UserTakePhotoMessageCodec();
            // Send the message
            string MsgSent = await UsrMsgCodec.Encode(UsrMsg);

            if (await Send(MsgSent))
            {
                // If sent, get the first response message
                string MsgReceived = await _CameraSocket.Receive();

                CameraMessageCodec CamEchoCodec = new CameraMessageCodec();
                CameraMessage      CamEchoMsg   = await CamEchoCodec.Decode(MsgReceived);

                if (CamEchoMsg.msg_id != UsrMsg.msg_id)
                {
                    return(null);
                }

                //Receive the start_photo_capture message
                MsgReceived = null;
                MsgReceived = await _CameraSocket.Receive();

                CamStartCaptureMessageCodec CamCodec = new CamStartCaptureMessageCodec();
                CamStartCaptureMessage      CamMsg   = await CamCodec.Decode(MsgReceived);

                // Check if photo capture is started
                if (CamMsg.msg_id != CamStartCaptureMessage.msg_id_expected && !CamMsg.type.Equals(CamStartCaptureMessage.photo_expected))
                {
                    return(null);
                }

                //Receive the Photo name
                MsgReceived = null;
                MsgReceived = await _CameraSocket.Receive();

                CamCaptureDoneMessageCodec CptrDoneCodec = new CamCaptureDoneMessageCodec();
                CamCaptureDoneMessage      CptrDoneMsg   = await CptrDoneCodec.Decode(MsgReceived);

                // Check if msg_id and type are the expected
                if (CptrDoneMsg.msg_id != CamCaptureDoneMessage.msg_id_expected && !CptrDoneMsg.type.Equals(CamCaptureDoneMessage.photo_expected))
                {
                    return(null);
                }

                //Receive the Photo name again
                MsgReceived = null;
                MsgReceived = await _CameraSocket.Receive();

                CptrDoneCodec = new CamCaptureDoneMessageCodec();
                CptrDoneMsg   = await CptrDoneCodec.Decode(MsgReceived);

                // Check if msg_id and type are the expected
                if (CptrDoneMsg.msg_id != CamCaptureDoneMessage.msg_id_expected && !CptrDoneMsg.type.Equals(CamCaptureDoneMessage.photo_expected))
                {
                    return(null);
                }

                // Return the location of the taken photo
                return(GetMediaLocation(CptrDoneMsg.param));
            }
            // If there is a problem
            return(null);
        }