unity通过rtsp协议实现云台的实时连接(二)

问题:unity3D使用UMP插件,打包后无法获取视频

原因:

  • ump插件会自动获取 VLC库,如果当前电脑没有安装VLC就会使用ump插件中的VLC库 ,但此时获取的方式为绝对路径,所以换电脑播放就找不到绝对路径下的VLC库了 会黑屏。
  • ump播放视频 是基于 VLC库的播放 因为当前电脑上没有这库 所以运行黑屏。

解决方案:

方法一:

    电脑安装VLC
https://ftp.stu.edu.tw/others/VideoLAN/vlc/3.0.6/win64/vlc-3.0.6-win64.exe

方法二:

  1. 修改脚本 NativeInterop中ReadLocalRegKey方法
  2. 然后 打包后把插件中Win / x86_64文件拷贝到xxx_Data/Plugins下面去
public static string ReadLocalRegKey(string keyPath, string valueName)
        {
            var platform = UMPSettings.RuntimePlatform;
            var value = string.Empty;
            if (platform == UMPSettings.Platforms.Win)
            {
                var localMachine = new UIntPtr(0x80000002u);
                var readKeyRights = 131097;
                var hKey = UIntPtr.Zero;
                //如果当前电脑上 安装了vlc 就用安装的VLC 路径下的dll 
                if (WindowsInterop.RegOpenKeyEx(localMachine, keyPath, 0, readKeyRights, out hKey) == 0)
                {
                    uint type;
                    uint size = 1024;
                    var keyBuffer = new StringBuilder((int)size);

                    if (WindowsInterop.RegQueryValueEx(hKey, valueName, 0, out type, keyBuffer, ref size) == 0)
                        value = keyBuffer.ToString();
                    else
                        Debug.LogWarning(string.Format("[ReadLocalRegKey] Can't read local reg key value: '{0}'", valueName));

                    WindowsInterop.RegCloseKey(hKey);
                }
                else //当前当前电脑 没有安装 VLC 就去data文件下找
                {
                    value = Application.dataPath + "/Plugins/x86_64/";
                }
                //else
                //    Debug.LogWarning(string.Format("[ReadLocalRegKey] Can't open local reg key: '{0}'", keyPath));
            }
            return value;
        }

注意:

  • 使用此方法优点:兼容性强。
  • 使用此方法缺点:每次打包后需要手动复制文件。

方法三

1.检查打包目录xxxx_data/Plugins是否与下图目录一样,如果一样执行2
在这里插入图片描述

2.打开UMPPostBuilds.cs脚本修改 BuildWindowsPlayer64 这个方法

public static void BuildWindowsPlayer64(string path, UMPSettings settings)
    {
        string buildPath = Path.GetDirectoryName(path);
        string dataPath = buildPath + "/" + Path.GetFileNameWithoutExtension(path) + "_Data";
 
        if (!string.IsNullOrEmpty(buildPath))
        {
            if (!settings.UseExternalLibs)
            {
                CopyPlugins(settings.AssetPath + "/Plugins/Win/x86_64/plugins/", dataPath + "/Plugins/plugins/");
                string[] files = Directory.GetFiles(dataPath + "/Plugins/x86_64/");
                foreach (string str in files)
                {
                    string file = Path.GetFileName(str);
                    Debug.LogError(file);
                    File.Copy(str, dataPath + "/Plugins/" + file);
                }
                Directory.Delete(dataPath + "/Plugins/x86_64/", true);
            }
            else
            {
                if (File.Exists(dataPath + "/Plugins/" + UMPSettings.LIB_VLC_NAME + ".dll"))
                    File.Delete(dataPath + "/Plugins/" + UMPSettings.LIB_VLC_NAME + ".dll");
 
                if (File.Exists(dataPath + "/Plugins/" + UMPSettings.LIB_VLC_CORE_NAME + ".dll"))
                    File.Delete(dataPath + "/Plugins/" + UMPSettings.LIB_VLC_CORE_NAME + ".dll");
            }
        }
        Debug.Log("Standalone Windows (x86_x64) build is completed: " + path);
    }

注意:

  • 使用此方法优点:打包后一步到位,无需手动复制文件
  • 使用此方法缺点:当工程中使用其他插件涉及到 x86_64 文件夹时候,会导致其他插件无法使用

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值