栉风
栉风
  • 发布:2023-08-02 14:58
  • 更新:2023-08-02 14:58
  • 阅读:307

如何使用uni.createInnerAudioContext()配合hls.js播放m3u8音频流?

分类:uni-app

this.audio_dp = uni.createInnerAudioContext()
const hls = new Hls()
hls.loadSource('直播音频.m3u8')
hls.attachMedia(this.audio_dp)
hls.on(Hls.Events.MANIFEST_PARSED, () => {
console.log('can-play')
this.audio_dp.play()
})

原生H5里使用audio标签是可以配合hls.js播放m3u8直播音频流的

原生:

<script src="https://cdn.bootcdn.net/ajax/libs/hls.js/1.4.0/hls.js"></script>  
<audio id="audio" autoplay src=""></audio>  
<button onclick="play()">播放</button>  
<script>  
    const audio = document.getElementById('audio')  
    window.onload = () => {  
        console.log('hls', Hls, Hls.Events)  
        const hls = new Hls()  
        hls.loadSource('直播音频.m3u8')  
        hls.attachMedia(audio)  
        hls.on(Hls.Events.MANIFEST_PARSED, () => {  
            console.log('can-play')  
            // audio.play()  
        })  
    }  

    function play() {  
        audio.play()  
    }     
</script>
2023-08-02 14:58 负责人:无 分享
已邀请:

要回复问题请先登录注册