Skip to content

Commit 007fa0a

Browse files
committed
feat: 使用flv.js在浏览器播放直播流
1 parent 6106c0b commit 007fa0a

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

resource/static/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script src="https://cdn.bootcdn.net/ajax/libs/flv.js/1.5.0/flv.min.js"></script>
2+
<video id="videoElement"></video>
3+
<script>
4+
window.onload=function(){
5+
if (flvjs.isSupported()) {
6+
var videoElement = document.getElementById('videoElement');
7+
videoElement.controls=true
8+
videoElement.muted=true
9+
videoElement.width="640"
10+
videoElement.height="480"
11+
videoElement.autoplay=true
12+
13+
var flvPlayer = flvjs.createPlayer({
14+
type: 'flv',
15+
url: 'http://localhost:8080/liziqiu'
16+
});
17+
flvPlayer.attachMediaElement(videoElement);
18+
flvPlayer.load();
19+
}
20+
}
21+
</script>

src/http_flv.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ async fn accept(mut stream: TcpStream) -> anyhow::Result<()> {
3939
Connection: close\r\n\
4040
Transfer-Encoding: chunked\r\n\
4141
Cache-Control: no-cache\r\n\
42+
Access-Control-Allow-Origin: *\r\n\
4243
\r\n\
4344
";
4445
stream.write_all(header.as_bytes()).await?;

src/protocol/flv.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl AsRef<[u8]> for FlvTag {
8383
}
8484

8585
/// 后台保存FLV文件
86+
#[allow(unused)]
8687
pub fn save_flv_background(stream_name: &str, peer_addr: String) {
8788
if let Some(eventbus) = eventbus_map().get(stream_name) {
8889
let flv_rx = eventbus.register_receiver();

0 commit comments

Comments
 (0)