1
zhanghua
2024-09-26 c775c6953d9759e70f08acbfa8f6d7490aaae3d1
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
package com.netsdk.demo.customize.surfaceEventDemo.module;
 
import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.ToolKits;
import com.sun.jna.Pointer;
 
/**
 * 通用预览接口
 *
 * @author 47040
 * @since Created in 2021/3/25 19:49
 */
public class RealPlayModule {
 
    private static final NetSDKLib NetSdk = NetSDKLib.NETSDK_INSTANCE;
 
    // 开始预览
    public NetSDKLib.LLong realPlay(NetSDKLib.LLong m_hLoginHandle, int channel, int playType, Pointer pWinHandle) {
 
        NetSDKLib.LLong m_hPlayHandle = NetSdk.CLIENT_RealPlayEx(m_hLoginHandle, channel, pWinHandle, playType);
 
        if (m_hPlayHandle.longValue() == 0) {
            System.err.println("开始实时预览失败,错误码" + String.format("[0x%x]", NetSdk.CLIENT_GetLastError()));
        } else {
            System.out.println("Success to start RealPlay");
        }
        return m_hPlayHandle;
    }
 
    // 结束预览
    public boolean stopPlay(NetSDKLib.LLong m_hPlayHandle) {
        System.out.println("Stopping RealPlay...");
        if (m_hPlayHandle.longValue() == 0) {
            System.err.println("Stop RealPlay failed. Please make sure the RealPlay Handle is valid!");
            return false;
        }
 
        boolean ret = NetSdk.CLIENT_StopRealPlayEx(m_hPlayHandle);
        if (!ret) {
            System.err.println("StopRealPlay Failed: " + ToolKits.getErrorCode());
        } else {
            System.out.println("StopRealPlay Succeed!");
            m_hPlayHandle.setValue(0);
        }
        return ret;
    }
 
}