griffith
griffith copied to clipboard
视频是m3u8格式的,一定要自动播放才能正常显示视频,如果是设置autoplay为false,点击播放按钮,播放容器是黑屏的
视频是m3u8格式的,一定要自动播放才能正常显示视频,如果是设置autoplay为false,点击播放按钮,播放容器是黑屏的
设置为autoplay为true,为正常的 `import React, { Component } from 'react'; import Player from 'griffith';
class LiveM3u8 extends Component { state = {};
testEvent = e => { console.log(e, 'testEvent'); }
render()
{
const { id, title, cover, src } = this.props;
const sources = {
auto: {
format: src.indexOf('m3u8') > -1 ? 'm3u8' : 'mp4',
play_url: src,
},
};
const props = {
id,
title,
standalone: true,
cover,
initialObjectFit: 'cover',
sources,
shouldObserveResize: true,
disablePictureInPicture: true,
autoplay: (src.indexOf('m3u8') > -1),
hiddenPlayButton: false,
hiddenTimeline: false,
hiddenTime: false,
onEvent: this.testEvent,
};
return (
<Player {...props} />
)
} }
export default LiveM3u8; `
考,我也是这个毛病,请问怎么解决的?
| 原生支持 HLS | 有 autoplay | 无 autoplay | |
|---|---|---|---|
| Chrome | N | Y | N* |
| Safari | Y | Y* | Y* |
| Firefox | N | Y | Y |
Safari 能播放但额外存在 loading 提示卡住的问题
Chrome 无 autoplay 加载:
- 改用
autoStartLoad: true参数提供给 hls,播放正常 - 手动调用
hls.startLoad(),然后再点击「播放」,播放正常 - 直接点击「播放」,提示 GET blob:url net::ERR_FILE_NOT_FOUND (内部仍然调用了
hls.startLoad(),但结果不对)
NOTE: 与 hls 版本无关(升级到 1.x 仍然存在 )