Skip to content
This SDK only works with devices released within the past 3 years. We regularly optimize and update the SDK to ensure compatibility and performance. We do not guarantee compatibility or provide technical support for devices older than 3 years.

# Preview

Process for real-time preview and live sound on/off

## Interface Overview

interface Name | Functional Description
--- | ---
`NET_SDK_LivePlay` | Live preview
`NET_SDK_OpenSound` | Sound to turn on live preview
`NET_SDK_Volume` | Adjust the volume of the live preview
`NET_SDK_CloseSound` | Turn off live preview sound
`NET_SDK_StopLivePlay` | Close Live Preview

Note

For detailed parameters of the interface, see the interface definition section.

## Process Description

    ---
    title: Preview
    ---

    flowchart TD
        A(Device SDK initialization <br><strong>NET_SDK_Init</strong>)
        B(User registers device <br><strong>NET_SDK_Login</strong> or <br><strong>NET_SDK_LoginEx</strong>)

        subgraph SS [Sound control]
            S0(Open sound <br><strong>NET_SDK_OpenSound</strong>)
            S1(Adjust volume <br><strong>NET_SDK_Volume</strong>)
            S2(Close sound <br><strong>NET_SDK_CloseSound</strong>)
            S0 --> S1 --> S2
        end
        style SS fill:#e7b13387,stroke:#f66,stroke-width:2px,stroke-dasharray: 5
        C(Stop preview <br><strong>NET_SDK_StopLivePlay</strong>)
        E(Log out of device <br><strong>NET_SDK_Logout</strong>)
        F(Release SDK resources <br><strong>NET_SDK_Cleanup</strong>)

        A --> B --> SS --> C --> E --> F

Note

The modules in the dashed box are: Control of the preview live sound in exclusive sound card mode, including turning on the sound, adjusting the volume, and turning off the sound

## Sample Code

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    #include <iostream>
    #include <string>
    #include "stdafx.h"
    #include "DVR_NET_SDK.h"

    using namespace std;

    void LivePlay()
    {
        // Initial
        NET_SDK_Init();
        // Device information
        const std::string device_ip = "10.80.1.177";
        const DWORD decice_port = 6036;
        const std::string username = "admin";
        const std::string password = "123456";
        //  Login
        NET_SDK_DEVICEINFO device_info = {0};
        int userid = NET_SDK_Login(const_cast<char *>(device_ip.c_str()), decice_port, const_cast<char *>(username.c_str()), const_cast<char *>(password.c_str()), &device_info);

        if (userid > 0)
        {
            cout << "Login successfully: " << userid << endl;
        }
        else
        {
            cout << "Failed to login: " << userid << endl;
            return;
        }

        // Open live display
        NET_SDK_CLIENTINFO lpClientInfo = {0};
        AllocConsole();
        lpClientInfo.hPlayWnd = GetConsoleWindow();
        lpClientInfo.lChannel = 0;
        lpClientInfo.streamType = NET_SDK_MAIN_STREAM;
        lpClientInfo.bNoDecode = 0;
        LONG lhandle = NET_SDK_LivePlay(userid, &lpClientInfo, NULL, NULL);

        if (lhandle == -1)
        {
            DWORD err1 = NET_SDK_GetLastError();
            cout << "Failed to preview! error code: " << err1 << endl;
            return;
        }

        cout << "Preview successful!" << endl;
        // Waiting for live display
        Sleep(1000);
        // Open sound
        BOOL open = NET_SDK_OpenSound(lhandle);

        if (open == true)
        {
            cout << "Sound opened successfully!" << endl;
        }
        else
        {
            cout << "Failed to open the sound!" << endl;
        }

        // Close sound
        BOOL close = NET_SDK_OpenSound(lhandle);

        if (close == true)
        {
            cout << "Sound closed successfully!" << endl;
        }
        else
        {
            cout << "Failed to close the sound!" << endl;
        }

        // Stop live display
        NET_SDK_StopLivePlay(lhandle);
        // Logout
        NET_SDK_Logout(userid);
        // Clean up the data
        NET_SDK_Cleanup();
    }

## Relevant Instructions

- The sample code contains only the switch sound in the preview state, and does not contain an example of adjusting the volume

- Net_SDK_LivePlay returns -1 for failures, other values for handle parameters

Error Code