关于Unity视频资源打包AssetBundle在安卓平台上无法正常播放的问题及解决方案

article/2025/11/4 5:34:13

首先了解一下Unity在进行AssetBundle打包时的几种构建方式:

  • BuildAssetBundleOptions.None:默认构建AssetBundle的方式。使用LZMA算法压缩,此算法压缩包小,但是加载时间长,而且使用之前必须要整体解压。解压以后,这个包又会使用LZ4算法重新压缩,这样这种包就不要对其整体解压了。(也就是第一次解压很慢,之后就变快了。
  • BuildAssetBundleOptions.UncompressedAssetBundle:不压缩数据,包大,但是加载很快。
  • BuildAssetBundleOptions.ChunkBaseCompression:使用LZ4算法压缩,压缩率没有LZMA高,但是加载资源不必整体解压。

而在安卓手机上加载AssetBundle中的视频资源时的报错就是由于unity在打包AssetBundle时对视频资源进行了压缩。

AndroidVideoMedia::OpenExtractor could not translate archive:/CAB-78qwdyh8739dh8uf02332dd686137/CAB-5b4cd5489dv87h2s93r7de1548fr7.resource to local file. Make sure file exists, is on disk (not in memory) and not compressed.
AndroidVideoMedia: Error opening extractor: -10004

解决方案一:对视频资源打包时不进行压缩,采用

BuildPipeline.BuildAssetBundles(…, BuildAssetBundleOptions. UncompressedAssetBundle,.. );

假如视频资源较大会导致游戏热更时需要下载的资源包体积也较大。

解决方案二:视频资源放服务器,在游戏中用代码动态下载视频到本地播放。

 

UIPlayVideo.lua.txt
local Parent = require("Manager/XYObj")
local CLASSNAME = "UIPlayVideo"
local CurObj = class(CLASSNAME,Parent)
local UiLayerConf = require "Manager/UiLayerConf"
local LoadVideoTool = require "Tool/LoadVideoTool"function CurObj:ctor(CLASSNAME,CSharpObj)CurObj.super.ctor(self,CLASSNAME,CSharpObj)self.m_bUiLayerType = UiLayerConf.ui_type_dlg
end--初始化
function CurObj:OnInit()btnClose.onClick:AddListener(function ()self:playVideoFun(videoConst.stop)ObjMgr:CloseUI("UIPlayVideo")end)
end--每次展示执行一次
function CurObj:OnShow()print("播放界面展示---")self:playVideoFun(videoConst.play)btnClose.gameObject:SetActive(false)self:invoke(function ()btnClose.gameObject:SetActive(true)end , 5)self:invoke(function ()ObjMgr:CloseUI("UIPlayVideo")end , 23)
endfunction CurObj:playVideoFun(state)if state == videoConst.play thenlocal url = "video_url_temp"objVideoCom.url = urllocal succCallback = function(args)objVideoCom.url = argsobjVideoCom:Play()endlocal failCallback = function(...)ObjMgr:ShowTips("播放失败")endLoadVideoTool:LoadVideoUrl(url,succCallback,failCallback)elseobjVideoCom:Stop()end
endvideoConst = {play = 1,stop = 2
}

LoadVideoTool.lua.txt
local LoadVideoTool={}
local cs_coroutine = require "XLua/Common/cs_coroutine"
local crypt = require "crypt"
local UnityWebRequest =	CS.UnityEngine.Networking.UnityWebRequest
local File=CS.System.IO.Filelocal FuncEncodeURI
local FuncGetPlatformPath
local pathfunction LoadVideoTool:LoadVideoUrl(url,succCallback,failCallback)if not url or url == "" thenprint("error:输入的URL错误!")LoadFailCall(failCallback)returnendif not path thenpath = FuncGetPlatformPath()endlocal urlEncode = FuncEncodeURI(url)urlEncode  = path .. "/" .. urlEncode..".mp4"if File.Exists(urlEncode) then-- 从本地加载--print("----------本地加载------------",url,urlEncode)if succCallback thensuccCallback(urlEncode)endelse --按网址下载--print("----------网上加载------------")cs_coroutine.start(function  ()local webRequest = UnityWebRequest.Get(url)webRequest.method = UnityWebRequest.kHttpVerbGETcoroutine.yield(webRequest:SendWebRequest())if (not webRequest.isNetworkError and webRequest.responseCode == 200) thenFile.WriteAllBytes(urlEncode,webRequest.downloadHandler.data)if succCallback thensuccCallback(urlEncode)endelseprint("errorVideo : ",webRequest.error)LoadFailCall(failCallback)endend)end
end-- 加载失败设置
LoadFailCall = function(failCallback)if failCallback thenfailCallback()end
end--- 根据平台 获取 路径
FuncGetPlatformPath = function()return CS.UnityEngine.Application.temporaryCachePath
end--- 网址中的特殊字符转换
FuncEncodeURI = function (s)return crypt.base64encode(s)
endreturn LoadVideoTool


http://chatgpt.dhexx.cn/article/GENq7oVt.shtml

相关文章

4004

404这个数字,也许是你在浏览网页的时候会经常碰到的数字,一旦看到它In微处理器是现代计算机的核心。它们是可编程的,意味着它们可以被执行给定的编程指令,并返回执行结果。 在它们被发明之前, 完成同样的工作需要许多个…

uniapp连接蓝牙相关问题

设备蓝牙连接成功, 获取不到设备蓝牙服务列表? 这种情况一般会接收到uniapp的错误码(10004), 我们可以前往uniapp官网API模块查看错误码信息,查看后可以得知错误码10004是没有找到指定服务. 我们可以详细看下获取所有服务的api -----uni.getBLEDeviceServices(OBJECT) 示例…

1002

描述 Description   在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧。在桥上有一些石子,青蛙很讨厌踩在这些石子上。由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数轴上的一串整…

编号10004 dba(p5-p7)

工作职责: 1、对数据库进行容量规划、架构设计,提高业务高可用性和容灾能力; 2、负责数据库相关工作的整体规划,提供决策建议; 3、维护数据库稳定运行,持续发现和解决潜在的问题; 4、负责数据库的性能优化,使用新技术和新架构满足…

UVa 10004 - Bicoloring

10004 - Bicoloring32340 42.67% 8939 86.93% 题目链接: http://uva.onlinejudge.org/index.php?optioncom_onlinejudge&Itemid8&category105 题目类型:搜索 题目: In 1976 the Four Color Map Theorem" was proven with the…

SemanticException [Error 10004]: line 14:13 Invalid table alias or column reference ‘a‘: .....

原查询如下: with table1 as (SELECT a.mid, a.summary_time as summary_time FROM hst_dwd.dwd_member_consume_info a, hst_dwd.dwd_business_info b WHERE a.business_id b.business_id AND a.market_id 218 AND b.type_id 4 ) select…

SemanticException [Error 10004]: Line 1:30 Invalid table alias or column reference ‘customers_state‘

项目场景: hive sql 语句 执行报错 问题描述: SemanticException [Error 10004]: Line 1:30 Invalid table alias or column reference ‘customers_state’: (possible column names are: customer_id, customer_fname, customer_lname, customer_em…

hive sql报错:SQL 错误 [10004] [42000]: Error while compiling statement: FAILED: SemanticException [Error

SQL 错误 [10004] [42000]: Error while compiling statement: FAILED: SemanticException [Error 10004]: Line 64:0 Invalid table alias or column reference ‘T4’: (possible column names are: order_id, order_status, update_time, charge_id, charge_status, station…

【JavaScript】清空数组的三种方式

方式1,splice var ary [1,2,3,4]; ary.splice(0,ary.length); console.log(ary); // 输出 [],空数组,即被清空了方式2,length赋值为0 这种方式很有意思,其它语言如Java,其数组的length是只读的&#xff…

js-清空array数组

三种实现方式 1.splice:删除元素并添加新元素,直接对数组进行修改,返回含有被删除元素的数组。 arrayObject.splice(index,howmany,element1,…,elementX) index:必选,规定从何处添加/删除元素。 howmany:…

Vue中实现清空数组和清空el-table

场景 要实现的效果是 那么就要用到怎样将这个el-table清空,即在vue中怎样将数组清空。 注: 博客:https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书、教程推送与免费下载。 实现 首先将这个el-tab…

JavaScript清空数组的三种方法

1、用“length”清除 用length方法可以很轻松地清空数组,代码示例: var arr [1,2,3]; console.log(arr); arr.length 0; console.log(arr); 结果如下: 2、用“splice”清除 splice() 方法向/从数组中添加/删除项目,然后返回…

JavaScript中清空数组最有效的三种方法

文章目录 1、用“length”清除2、用“splice”清除3、用“[]”清除 1、用“length”清除 用length方法可以很轻松地清空数组,代码示例: var arr [1,2,3]; 1 console.log(arr); arr.length 0; console.log(arr); 123结果如下: 2、用“spli…

MVEL快速入门—MVEL属性和文字讲解(二)

相关文章 🔥 MVEL快速入门—MVEL基础语法讲解(一) 以下为今日内容: 属性信息 MVEL的属性信息保持了其他bean一般通常使用的形式,略有区别的是,MVEL为访问属性、静态信息、Map等提供了统一的访问形式 Bea…

MVEL快速入门—MVEL基础语法讲解(一)

概述 MVEL是从英文翻译而来的,MVFLEX表达式语言是Java平台的动态/静态混合类型的运行时可嵌入表达式语言。该项目最初是作为应用程序框架的实用语言开始的,现在已完全独立开发。MVEL通常用于通过XML文件或注释等配置将基本逻辑公开给最终用户和程序员。它…

MVEL快速入门—MVEL流程控制和高级功能(三)

之前文章 MVEL快速入门—MVEL基础语法讲解(一) MVEL快速入门—MVEL属性和文字讲解(二) 流程控制 实际上MVEL的表达形式不仅仅局限于简单的表达式,他还支持流程控制。使我们能够执行高级的脚本。 if - then - else M…

int 类型和double类型数值转换

类型自动转换规则: 参与运算(算数运算和赋值运算)操作数和结果类型必须一致, 不一致时启动隐式转换: 两种类型兼容:int 和double兼容(都是数字类型) 目标类型大于原类型 Int 类型取值…

double转int精度丢失问题

先来看一下精度丢失的现象&#xff1a; #include <iostream> #include <cmath> using namespace std;int main() {double a 74.46;int b a * 100;cout << "a: " << a << " b: " << b <<endl;return 0; }结果…

double转换成int java,Java将double转换为int

本文概述 我们可以使用类型转换在Java中将double转换为int。要将double数据类型转换为int, 我们需要执行类型转换。 Java中的类型转换通过类型转换运算符(数据类型)执行。 在这里, 我们将学习如何将double基本类型转换为int以及将Double对象转换为int。 Java double to int示例…