Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问怎么在线看直播内容? #216

Open
suiuko opened this issue Sep 12, 2022 · 2 comments
Open

请问怎么在线看直播内容? #216

suiuko opened this issue Sep 12, 2022 · 2 comments

Comments

@suiuko
Copy link

suiuko commented Sep 12, 2022

我电脑端访问网址后,直接自动下载视频了,无法在线看,

@826641360
Copy link

flv.js

@x1uc
Copy link

x1uc commented Dec 29, 2024

如果你熟悉Vue/Node&JS,你可以这样。

依赖

  "dependencies": {
    "hls.js": "^1.5.18",
    "vue": "^3.4.21",
    "vue-video-player": "^6.0.0"
  }

Vue JS Code

<template>
    <div class="video-container">
        <video ref="videoPlayer" class="video-js" controls preload="auto" width="640" height="360">
        </video>
    </div>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import Hls from 'hls.js'

const videoPlayer = ref(null)
const props = defineProps({
    src: {
        type: String,
        required: true
    }
})

onMounted(() => {
    if (Hls.isSupported()) {
        const hls = new Hls()
        hls.loadSource(props.src)
        hls.attachMedia(videoPlayer.value)
    }
    // 对于原生支持 HLS 的浏览器(如 Safari)
    else if (videoPlayer.value.canPlayType('application/vnd.apple.mpegurl')) {
        videoPlayer.value.src = props.src
    }
})
</script>

<style scoped>
.video-container {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
}
</style>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants