xgplayer icon indicating copy to clipboard operation
xgplayer copied to clipboard

hls 怎么添加自定义请求头headers

Open pytomtoto opened this issue 2 years ago • 1 comments

您使用的西瓜播放器版本是多少? What version of xgplayer are you using?

<script src="https://unpkg.byted-static.com/xgplayer/2.31.2/browser/index.js" charset="utf-8"></script>
    <script src="https://unpkg.byted-static.com/xgplayer-hls.js/2.2.2/browser/index.js" charset="utf-8"></script>
        <script>  
            let url = getQueryVariable('src');  
            let player = new HlsJsPlayer({  
                 "id": "mse",  
                 "url": url,  
                 "playsinline": true,  
				 // "useHls": true,
                 // "width":"100%",  
                 // "height":"255px", 
				    "hlsOpts": {
					  licenseXhrSetup: function (xhr, url) {
					    xhr.withCredentials = true; // do send cookies
					    if (!xhr.readyState) {
					      // Call open to change the method (default is POST) or modify the url
					      xhr.open('GET', url, true);
					      // Append headers after opening
					      xhr.setRequestHeader('Content-Type', 'application/octet-stream');
						  xhr.setRequestHeader('x-request-id', 'E8F31D53-CA0D-BACE-8E61-B79ADC055BAE');
					    }
					  },
				     xhrSetup: function(xhr, url) {
						xhr.setRequestHeader('x-request-id', 'E8F31D53-CA0D-BACE-8E61-B79ADC055BAE');
				     },
					 fetchSetup: function(context, initParams) {
					 	context.headers =  {'x-request-id': 'E8F31D53-CA0D-BACE-8E61-B79ADC055BAE'};
						return new Request(context.url, initParams);
					 },
					   pLoader: function (config) {
					     let loader = new HlsJsPlayer.DefaultConfig.loader(config);
					     this.abort = () => loader.abort();
					     this.destroy = () => loader.destroy();
					     this.load = (context, config, callbacks) => {
							 context.headers = {'x-request-id': 'E8F31D53-CA0D-BACE-8E61-B79ADC055BAE'};
					       let { type, url } = context;
					 
					       if (type === 'manifest') {
					         console.log(`Manifest ${url} will be loaded.`);
					       }
					 
					       loader.load(context, config, callbacks);
					     };
					   },
				    }, 
				 "fluid": true,
                 "autoplay": true,  
                 "whitelist": [''],  
				 "playbackRate": [0.5, 0.75, 1, 1.5, 2],
				 "rotateFullscreen": true,
				 "videoInit": true,
             });  

您使用的操作系统和浏览器分别是? What OS and browser are you using? uniapp android 10

如何复现问题? What did you do? 尝试使用xg hls.js 配置hlsOpts 用于实现请求url添加headers,可能用法不对,或需要使用其他方式?

您期望的播放器正常行为是? What did you expect to happen? 请求视频url 携带请求ID x-request-id

实际播放器的表现是? What actually happened?

 我有在请求头中发现 Range: bytes=0-
但是没找到x-request-id: xxx-xxx

可填写您所在的公司和相关产品业务,方便我们提供更好的技术支持 You can write your company and product which uses xgplayer, for helping us provide better technical support.

pytomtoto avatar Jul 09 '22 04:07 pytomtoto

可能是CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS 这个限制 如果服务端没有允许这个请求头 客户端就加不上去?

pytomtoto avatar Jul 09 '22 05:07 pytomtoto

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Feb 03 '23 07:02 github-actions[bot]

This issue has been automatically closed after a period of inactivity. If it is still present in the latest release, please create a new issue with up-to-date information. Thank you!

github-actions[bot] avatar Mar 06 '23 00:03 github-actions[bot]