seagazer / ccplayer

A media player for OpenHarmony.
Apache License 2.0
9 stars 0 forks source link

某些限制在电脑浏览器播放的视频地址 播放不了 请问需要设置什么吗 #4

Closed 756230883 closed 1 month ago

756230883 commented 3 months ago

http://tv-vod.nbs.cn/vod_storage/vol1/2024/06/06/66615d8489137/66615d848913767849.mp4

756230883 commented 3 months ago

比如上面这个地址 是做了不能在电脑浏览器播放的限制 在手机微信上可以正常播 使用android的视频播放器也可以正常播 请问是需要配置什么吗

seagazer commented 3 months ago

比如上面这个地址 是做了不能在电脑浏览器播放的限制 在手机微信上可以正常播 使用android的视频播放器也可以正常播 请问是需要配置什么吗

你这个问题属于服务端拒绝访问,使用android浏览器也可以播放,但是把浏览模式改为PC模式后就一样不能播了。ohos的网络媒体播放使用的请求库是curl,设备标识User-Agent为 GStreamer curlhttpsrc libcurl/8.4.0。 1717683830515 收到http请求403错误后,媒体引擎开始组织并抛出错误: 08-05 17:07:03.887 670 5396 W C02b2b/curlhttpsrc: (403), URL: http://tv-vod.nbs.cn/vod_storage/vol1/2024/06/06/66615d8489137/66615d848913767849.mp4, Redirect to: (NULL) 08-05 17:07:03.888 670 5396 W C02b2b/basesrc: {gst_base_src_loop():3182} [gst::source:14E728] warning: Internal data stream error. 08-05 17:07:03.888 670 5396 W C02b2b/basesrc: {gst_base_src_loop():3182} [gst::source:14E728] warning: streaming stopped, reason error (-5) 08-05 17:07:03.889 670 5396 W C02b2b/typefind: {gst_type_find_element_chain_do_typefinding():1132} [gst::typefindelement2:E9E060] error: Stream doesn't contain enough data. 08-05 17:07:03.889 670 5396 W C02b2b/typefind: {gst_type_find_element_chain_do_typefinding():1132} [gst::typefindelement2:E9E060] error: Can't typefind stream 08-05 17:07:03.890 670 5390 E C02b2b/GstMsgConvDefault: {ConvertErrorMessage():101} [ERROR] Forbidden

08-05 17:07:03.890 670 5390 E C02b2b/GstMsgConvDefault: , ../../third_party/gstreamer/gstplugins_bad/ext/curl/gstcurlhttpsrc.c(1491): gst_curl_http_src_handle_response (): /GstPlayBin:playbin/GstURIDecodeBin:uridecodebin3/GstCurlHttpSrc:source: 08-05 17:07:03.890 670 5390 E C02b2b/GstMsgConvDefault: Forbidden

08-05 17:07:03.890 670 5390 E C02b2b/GstMsgConvDefault: (403), URL: http://tv-vod.nbs.cn/vod_storage/vol1/2024/06/06/66615d8489137/66615d848913767849.mp4, Redirect to: (NULL) 08-05 17:07:03.890 670 5390 E C02b2b/GstMsgConvDefault: {ResourceErrorParse():85} domain: GST_RESOURCE_ERROR 08-05 17:07:03.891 670 5390 E C02b2b/PlayBinCtrlerBase: {ReportMessage():1802} error happend, error code: 331350558 08-05 17:07:03.891 670 5390 D C02b2b/PlayBinCtrlerBase: {ReportMessage():1812} report msg, type: 0 08-05 17:07:03.892 670 5390 W C02b2b/GstMsgConvDefault: {ConvertWarningMessage():128} [WARNING] Internal data stream error., ../../third_party/gstreamer/gstreamer/libs/gst/base/gstbasesrc.c(3182): gst_base_src_loop (): /GstPlayBin:playbin/GstURIDecodeBin:uridecodebin3/GstCurlHttpSrc:source: 08-05 17:07:03.892 670 5390 W C02b2b/GstMsgConvDefault: streaming stopped, reason error (-5) 08-05 17:07:03.892 670 5389 E C02b2b/PlayerEngineGstImpl: {HandleErrorMessage():195} error happended, cancel inprocessing job

如上面的日志,请求时,服务端直接拒绝返回403,应该是服务端会根据user-agent来进行访问控制,因此某些设备就无法播放视频资源。应该是服务端当前没有对OpenHarmony这操作系统和类设备适配,当前ohos也没有能够在媒体播放器去设置修改user-agent的能力。 如果实在要播放这类url的视频,这里提供一种临时方案:先使用http库将网络媒体文件下载到本地,再使用本地文件的fd进行播放。

756230883 commented 3 months ago

你好 说的是访问 这种视频地址 http请求头中Referer需要置为空 请问有什么方法可以做到吗

seagazer commented 3 months ago

你好 说的是访问 这种视频地址 http请求头中Referer需要置为空 请问有什么方法可以做到吗

目前原生媒体播放对应用层开放的接口能力中不支持修改请求参数,所以纯应用层当前没法修改网络视频的请求头,需要定制框架暴露napi接口。你可以去社区提issue,让官方看下是否有计划增加该能力哈

756230883 commented 3 months ago

收到 谢谢作者

756230883 commented 3 months ago

作者你好 华为官方回复说 是api12增加了对 userAgent和header修改的能力 3d872070f01ec01144211e2465a5180 4672c2c4c9a6900660de924a3384485 咱们这边能否进行适配呢 感谢作者

756230883 commented 3 months ago

鸿蒙 avlpayer createMediaSourceWithUrl 接口支持传入 header,当前支持参数 User-Agent、Referer、Cookie https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-media-V5#ZH-CN_TOPIC_0000001884918706__mediacreatemediasourcewithurl12 链接地址需要授权 您看下能打开吗

seagazer commented 3 months ago

鸿蒙 avlpayer createMediaSourceWithUrl 接口支持传入 header,当前支持参数 User-Agent、Referer、Cookie https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-media-V5#ZH-CN_TOPIC_0000001884918706__mediacreatemediasourcewithurl12 链接地址需要授权 您看下能打开吗 next的api12对应oh版本应该是5.0了,都是处于beta阶段,release预计要四季度左右,当前我这边没有申请next预览版开发资源,主要是以oh为主。不过oh5.0或者next全量放开后,本库肯定会做适配的。晚点有空我看下oh5.0beta1是否有这接口,有的话我回去验证下

756230883 commented 3 months ago

嗯嗯 好的 谢谢作者

seagazer commented 3 months ago

嗯嗯 好的 谢谢作者

你好,目前新增了dev-5.0分支对5.0新的接口能力进行适配,MediaSourceFactory.createUrl方法新增了header和strategy参数,经验证可以播放你上面的url了。但是5.0当前为beta1版本,xcomponent有bug,ohos在起播后需要触发一次界面刷新xcomponent才能显示出画面。由于是beta版本,系统存在不少bug,所以当前并不计划发布版本,本库5.0的版本待OpenHarmony 5.0release正式发布后同步发布,当前可以把代码拉下来自己打包本地har进行依赖使用。

756230883 commented 3 months ago

收到 我们来验证一下 谢谢作者