dart 如何发送变焦命令到IP摄像机Flutter?

nnvyjq4y  于 5个月前  发布在  Flutter
关注(0)|答案(1)|浏览(59)

尝试使用easy_onvif库使用Flutter控制IP摄像机,但我无法让摄像机缩放。我尝试使用库提供的zoomIn函数,但没有成功。有人知道如何让摄像机执行缩放命令吗?下面是我用来与摄像机通信的代码:

setZoom() async {
    final onvif = await Onvif.connect(
        host: "192.168.1.18:8999", username: "", password: "");

    var profiles = await onvif.media.getProfiles();
    var profileToken = await profiles.first.token;

    var ptzCommand = await onvif.ptz;
    print("zoom+");
    await ptzCommand.zoomIn(profileToken);
    print("zoom++");
}

字符串
--SOS:许多连接发送命令或流的flutter库都被弃用了,这使得我很难找到flutter问题的答案,主要是作为一个初学者。

nnt7mjpx

nnt7mjpx1#

ONVIF connect和token命令可能需要很长时间。而且,缩放真的可以忽略不计。Zoom命令需要放在长按回调中。
以下是对我有效的方法:
1.首先连接摄像机。使用日志/打印语句确认它工作正常,没有任何问题
1.获取令牌。这偶尔需要很长时间才能完成,因此添加日志以确认)
1.然后调用zoom命令
P.S. -根据延迟,您可以看到屏幕缩放有显着延迟。
代码如下:

class OnVIFService {
  OnVIFService();

  Onvif onvif;
  String token;

  Future<void> connect({@required String ip}) async {
    onvif = await Onvif.connect(
      host: ip,
      username: 'admin', // replace with your username
      password: '123456', // replace with your password
    );

    log('OnVIFService: connected to $ip');
  }

  Future<void> getToken() async {
    final profiles = await onvif.media.getProfiles();
    final profile = profiles.first;
    token = profile.token;

    log('OnVIFService: got token $token');
  }

  Future<void> moveLeft() async {
    await onvif.ptz.moveLeft(token);
  }

  Future<void> moveRight() async {
    await onvif.ptz.moveRight(token);
  }

  Future<void> moveUp() async {
    await onvif.ptz.moveUp(token);
  }

  Future<void> moveDown() async {
    await onvif.ptz.moveDown(token);
  }

  Future<void> stop() async {
    await onvif.ptz.stop(token);
  }

  Future<void> zoomIn() async {
    await onvif.ptz.zoomIn(token);
  }

  Future<void> zoomOut() async {
    await onvif.ptz.zoomOut(token);
  }
}

字符串

相关问题