vconnex_camera 0.1.3
vconnex_camera: ^0.1.3 copied to clipboard
Vconnex Camera
example/lib/main.dart
import 'dart:io';
import 'dart:typed_data';
import 'package:gallery_saver/gallery_saver.dart';
import 'package:path_provider/path_provider.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:vconnex_camera/VCNCameraPlaybackViewWidget.dart';
import 'package:vconnex_camera/camera_controller.dart';
import 'package:vconnex_camera/vcn_camera_view_widget.dart';
import 'package:vconnex_camera/vconnex_camera.dart';
import 'package:permission_handler/permission_handler.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
late CameraController _cameraController;
late CameraController _cameraPlaybackController;
@override
void initState() {
super.initState();
initPlatformState();
VconnexCamera.setCameraCallback(_handleMessages);
}
Future<dynamic> _handleMessages(MethodCall call) async {
switch (call.method) {
case 'startAddDevice':
Map map = call.arguments as Map;
print(map);
}
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion =
await VconnexCamera.platformVersion ?? 'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Padding(
padding: EdgeInsets.all(20),
child: Column(
children: [
// VCNCameraViewWidget(callback: (controller) {
// _cameraController = controller;
// }, height: 200,
// width: 320,),
VCNCameraPlaybackViewWidget(width: 320,height: 200,callback: (controller) {
_cameraPlaybackController = controller;
},
),
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Login with auth"),
onPressed: () async {
Map<String, dynamic> args = Map();
args['authCode'] = 'eyJhbGciOiJIUzI1NiJ9.eyJvIjp7InByb3ZpZGVyIjoicGhvbmUiLCJwcm92aWRlclVzZXJJZCI6IjAzNDgyMzY1ODAifSwiaWF0IjoxNjY2Njk3MjA0LCJleHAiOjE2NjkyODkyMDR9.NcKhJ-jECpqd7NGOQhq3Uy2Hf18Hj6NdmA8a7fI4Kvw';
// args['authCode'] = 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIwMzQ4MjM2NTgwIiwidXNlcklkIjoiMTAwMCIsImxhbmd1YWdlIjoxLCJvc3N5dGVtIjoxLCJkZXZpY2VUb2tlbiI6ImFiYyIsInBhc3N3b3JkIjoiJDJhJDEwJGRha2xPcG5sVkF2TW94WXJESk5wS3VrVDZ3NkxFem5JMGhnRjRNdTdpQkM1d2hsbXllbXFHIiwidG9rZW4iOiJleUpoYkdjaU9pSklVelV4TWlKOS5leUp6ZFdJaU9pSXdNelE0TWpNMk5UZ3dJaXdpYzJOdmNHVnpJanBiSW14cGMzUmZjR1Z5YldsemMybHZiaUlzSW1SbGRHRnBiRjl3WlhKdGFYTnphVzl1SWl3aWJHbHpkRjl5YjJ4bElpd2laR1YwWVdsc1gzSnZiR1VpTENKc2FYTjBYMjFoYm1GblpXMWxiblJqYjI1bWFXZDFjbUYwYVc5dUlpd2liR2x6ZEY5eVpYQnZjblFpTENKa1pYUmhhV3hmY21Wd2IzSjBJaXdpYkdsemRGOWtaWFpwWTJWd2IzSjBabTlzYVc5dFlXNWhaMlZ0Wlc1MElpd2liR2x6ZEY5allYUmxaMjl5ZVcxaGJtRm5aVzFsYm5Sa1pYWnBZMlYwZVhCbElpd2liR2x6ZEY5amRYTjBiMjFsY21GalkyOTFiblFpTENKa1pYUmhhV3hmWTNWemRHOXRaWEpoWTJOdmRXNTBJbDBzSW5WelpYSkpaQ0k2SWpFd01EQWlMQ0psYm1GaWJHVmtJanAwY25WbExDSndZWE56ZDI5eVpDSTZJaVF5WVNReE1DUmtZV3RzVDNCdWJGWkJkazF2ZUZseVJFcE9jRXQxYTFRMmR6Wk1SWHB1U1RCb1owWTBUWFUzYVVKRE5YZG9iRzE1WlcxeFJ5SXNJbXhoYm1kMVlXZGxJam94TENKdmMzTjVkR1Z0SWpveExDSmtaWFpwWTJWVWIydGxiaUk2SW1GaVl5SXNJbkJ5YjNacFpHVnlJam9pY0dodmJtVWlMQ0pzWlhabGJDSTZNeXdpYVhOeklqb2ljMjFoY25Sb2IyMWxJaXdpYVdGMElqb3hOalkxTlRRMk5ETTVMQ0psZUhBaU9qRTJOamd4TXpnME16bDkuNUdTZFJGOGlKRmFEdEQ2R2RZczJaX0JZYTFLZm5PUlhvQjNWTERicDYwOE9EVEY2VVBTcm1WOGhvb2lKbHFvTzVtSVZmXzNoZnBkUjBFTHF6OWlhSHciLCJwcm92aWRlciI6InBob25lIiwiaXNzIjoic21hcnRob21lIiwianRpIjoiNDdjYzg4NmUtZTFhOS00NDEzLWI3YzEtZTg5NmU4ZjZkOTY1IiwiaWF0IjoxNjY1NTQ2NDM5LCJleHAiOjE2NzA3MzA0Mzl9.onR4hnjuhXR1PZEtml8D_7kPTms1fRVS2CQrI73xK2mUQKZ34YSs01yc1PhZTVV_Lv6X_CVfw9XDi0p0KDhWmw';
bool? isLoginSuccess = await VconnexCamera.loginWithAuthCode(args);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Refresh Token"),
onPressed: () async {
VconnexCamera.refreshToken();
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Logout"),
onPressed: () async {
VconnexCamera.logout();
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Request List Device"),
onPressed: () async {
Map? devices = await VconnexCamera.requestUserDeviceList();
if (devices != null) {
// _selectedCamera = devices.first;
}
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Set Parameter Device"),
onPressed: () async {
VconnexCamera.setDeviceParameter(productKey: 'a1BxN4TY5nN', linkType: 6, enableToken: true, regionNode: 0);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Add Camera"),
onPressed: () async {
if (await Permission.locationWhenInUse.serviceStatus.isEnabled) {
}
else {
}
Map<Permission, PermissionStatus> statuses = await [
Permission.location,
].request();
Map? infos = await VconnexCamera.startAddDevice(ssid: 'VCONNEX', pass: '0913456789', timeout: 240);
print("add camera result:");
print(infos);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Unbind Device"),
onPressed: () async {
VconnexCamera.unbindDevice(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000');
},
),
),
Row(
children: [
Padding(
padding: const EdgeInsets.all(4.0),
child: TextButton(
child: Text("Play"),
onPressed: () async {
// if (_selectedCamera != null) {
_cameraController.playCamera(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000');
// }
},
),
),
Padding(
padding: const EdgeInsets.all(4.0),
child: TextButton(
child: Text("stop"),
onPressed: () async {
_cameraController.stopCamera();
},
),
),
Padding(
padding: const EdgeInsets.all(4.0),
child: TextButton(
child: Text("Pause"),
onPressed: () async {
_cameraController.pauseCamera();
},
),
),
Padding(
padding: const EdgeInsets.all(4.0),
child: TextButton(
child: Text("Restore"),
onPressed: () async {
// _cameraController.restoreCamera();
},
),
),
],
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Playback from RFCard"),
onPressed: () async {
// if (_selectedCamera != null) {
// _cameraController.playbackFromTFCard(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', vodStartTime: 1663200000, vodEndTime: 1663286399, seekTime: 49080);
_cameraPlaybackController.playCameraByLocalRecordTime(iotId: 'vyrpCPlpvVSRZXbjRDAE000000', vodStartTime: 1663200000, vodEndTime: 1663286399, seekTime: 2, recordType: 0);
// }
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("seek To"),
onPressed: () async {
// if (_selectedCamera != null) {
// _cameraController.playbackFromTFCard(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', vodStartTime: 1663200000, vodEndTime: 1663286399, seekTime: 49080);
_cameraPlaybackController.seekTo(8);
// }
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("setVideo scaling Mode"),
onPressed: () async {
// if (_selectedCamera != null) {
// _cameraController.playbackFromTFCard(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', vodStartTime: 1663200000, vodEndTime: 1663286399, seekTime: 49080);
_cameraPlaybackController.setVideoScalingMode(1);
// }
},
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Padding(
padding: const EdgeInsets.all(2.0),
child: TextButton(
child: Text("Left"),
onPressed: () async {
// VconnexCamera.startPTZ(iotId: 'UF0mFdBYqwehGavXRaj7000000', actionType: 0, speed: 1);
VconnexCamera.stepPTZControl(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', actionType: 0, step: 5);
},
),
),
Padding(
padding: const EdgeInsets.all(2.0),
child: TextButton(
child: Text("Right"),
onPressed: () async {
// VconnexCamera.startPTZ(iotId: 'UF0mFdBYqwehGavXRaj7000000', actionType: 1, speed: 1);
VconnexCamera.stepPTZControl(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', actionType: 1, step: 5);
},
),
),
Padding(
padding: const EdgeInsets.all(2.0),
child: TextButton(
child: Text("UP"),
onPressed: () async {
// VconnexCamera.startPTZ(iotId: 'UF0mFdBYqwehGavXRaj7000000', actionType: 2, speed: 2);
VconnexCamera.stepPTZControl(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', actionType: 2, step: 5);
},
),
),
Padding(
padding: const EdgeInsets.all(2.0),
child: TextButton(
child: Text("Down"),
onPressed: () async {
// VconnexCamera.startPTZ(iotId: 'UF0mFdBYqwehGavXRaj7000000', actionType: 2, speed: 2);
VconnexCamera.stepPTZControl(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', actionType: 3, step: 5);
},
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Zoom in"),
onPressed: () async {
// VconnexCamera.startPTZ(iotId: 'UF0mFdBYqwehGavXRaj7000000', actionType: 9, speed: 2);
VconnexCamera.stepPTZControl(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', actionType: 9, step: 5);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Zoom out"),
onPressed: () async {
// VconnexCamera.startPTZ(iotId: 'UF0mFdBYqwehGavXRaj7000000', actionType: 8, speed: 2);
VconnexCamera.stepPTZControl(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', actionType: 8, step: 5);
},
),
),
],
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Stop PTZ"),
onPressed: () async {
VconnexCamera.stepPTZControl(iotId: 'UF0mFdBYqwehGavXRaj7000000', actionType: 4, step: 5);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Get Snapshot"),
onPressed: () async {
Uint8List list = await _cameraController.getVideoSnapshot();
File file = await File.fromRawPath(list);
Directory appDocDir = await getApplicationSupportDirectory();
final File newImage = await file.copy('${appDocDir.path}/image1.png');
print('file image size: ${await newImage.length()}');
await GallerySaver.saveImage('${appDocDir.path}/image1.png');
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Set Mute"),
onPressed: () async {
_cameraController.setMute(mute: false);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Set Voice Change Type"),
onPressed: () async {
_cameraController.setVoiceChangeType(type: 1);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Set Play Speed"),
onPressed: () async {
_cameraController.setPlaySpeed(speed: 8000);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("start Record Video"),
onPressed: () async {
Directory appDocDir = await getApplicationSupportDirectory();
String appDocPath = appDocDir.path + '/sampleVideo.mp4';
_cameraController.startRecordVideo(filePath: appDocPath);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Stop Record Video"),
onPressed: () async {
_cameraController.stopRecordVideo();
Directory appDocDir = await getApplicationSupportDirectory();
String appDocPath = appDocDir.path + '/sampleVideo.mp4';
File file = await File(appDocPath);
print('file size: ${await file.length()}');
await GallerySaver.saveVideo(file.path);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("set Display Buffer"),
onPressed: () async {
_cameraController.setDisplayBuffer(buffer: 10);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Set Intercom Encode Param"),
onPressed: () async {
_cameraController.setIntercomEncodeParam(sampleRate: 8000, channel: 1, bitPerSample: 16, format: 1);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Open Voice Intercom"),
onPressed: () async {
_cameraController.openVoiceIntercom(mode: 1, iotId: "Qzn5LXAlgR3NZ4ZEpExn000000");
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Stop Voice Intercom"),
onPressed: () async {
_cameraController.stopVoiceIntercom();
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Get Device Info"),
onPressed: () async {
VconnexCamera.getDeviceInfo(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000');
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Set Record Mode"),
onPressed: () async {
VconnexCamera.setStorageRecordMode(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', mode: 2);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("get camera property"),
onPressed: () async {
VconnexCamera.getpropertiesCamera(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000');
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Set daynight Mode"),
onPressed: () async {
VconnexCamera.setDayNightMode(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', mode: 0);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Set Stream Video Quality"),
onPressed: () async {
VconnexCamera.setStreamVideoQuality(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', quality: 2);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Get Record List"),
onPressed: () async {
VconnexCamera.getQueryRecordList(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', beginTime: 1663200000, endTime: 1663286399, type: 99, querySize: 128);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Enable Montion Dectect"),
onPressed: () async {
VconnexCamera.setMotionDetectAlarmSwitch(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000',montionDetectEnable: 1);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Enable Human Dectect"),
onPressed: () async {
VconnexCamera.humanDetectAlarmSwitch(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000',humanDetectEnable: 1);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Enable Area Dectect"),
onPressed: () async {
VconnexCamera.areaDetectAlarmSwitch(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000',areaDetectEnable: 1);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Enable Intrusion Dectect"),
onPressed: () async {
VconnexCamera.intrusionDetectSwitch(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000',intrusionDetectEnable: 1);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Enable Face Recognition"),
onPressed: () async {
VconnexCamera.faceRecognitionSwitch(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000',faceRecognitionEnable: 1);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Enable License Plate Recognition"),
onPressed: () async {
VconnexCamera.licensePlateRecognitionSwitch(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000',licensePlateRecognitionEnable: 1);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Auto Tracking Recognition"),
onPressed: () async {
VconnexCamera.autoTrackingSwitch(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000',autoTrackingEnable: 1);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Set Alarm Notify Plan"),
onPressed: () async {
VconnexCamera.setAlarmNotifyPlan(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', beginTime: 1, endTime: 86300, dayOfWeek: [0,1,2,3,4,5,6]);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text(" Sub Stream Video Quality"),
onPressed: () async {
VconnexCamera.setSubStreamVideoQuality(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', quality: 1);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("HSR Detect Sensitivity"),
onPressed: () async {
VconnexCamera.setHSRDetectSensitivity(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', hSRDetectSensitivity: 1);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Motion Detect Sensitivity"),
onPressed: () async {
VconnexCamera.setMotionDetectSensitivity(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000', motionDetectSensitivity: 1);
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
child: Text("Format Storage Medium"),
onPressed: () async {
VconnexCamera.formatStorageMedium(iotId: 'Qzn5LXAlgR3NZ4ZEpExn000000');
},
),
),
],
),
),
),
],
),
),
),
);
}
}