android web local APP,where to place local video files for android webview html5 hybrid app

博主在将含视频的HTML页面加载到Android WebView时,视频无法播放,尝试将视频文件放在asset和raw文件夹均无效。有人给出解决方案,将视频文件放RAW文件夹,在default.html文件中用特定代码访问,还需在AndroidManifest文件添加相关行,同时介绍了全屏播放的处理方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题

I am loading html page from asset folder to android webview, the html pages has video. Other images are loaded clearly but video is not loaded i mean not plays in app. Where to place the local video file? I tested by placing video files in asset folder and raw folder, but not plays video.

webView.loadUrl("file:///android_asset/index.html"); // load html file

video.src="file:///android_res/raw/test.mp4"; // load video file from raw folder

and

video.src="file:///android_asset/test.mp4"; // load video file from assets folder

Please help me, thanks in advance.

回答1:

I placed video files in RAW folder and access video file in default.html file by following code:

video.src ="android.resource://ProjectPackageAame/raw/test";

video.type = "video/mp4";

video.load();

video.play();

It playes video like i want. Also added following line in AndroidManifest file.

android:hardwareAccelerated="true"

For playing video in full screen mode used showCustomView & hideCustomView method of WebChromeClient. What i have done is kept one Framelayout(customContainer) in my main.xml, and adding view received in showCustomView here, and removing it in onHide. Also hiding/showing webview accordingly.

来源:https://stackoverflow.com/questions/17020270/where-to-place-local-video-files-for-android-webview-html5-hybrid-app

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值