Playing m3u8 Files with HTML Video Tag

后端 未结 6 735
-上瘾入骨i
-上瘾入骨i 2020-12-01 00:30

I am trying to use HTTP Live Streaming (HLS) to stream video to my computers and my iPhone. After reading through the Apple \'HTTP Live Streaming Overview\' as well as \'Be

6条回答
  •  萌比男神i
    2020-12-01 01:08

    Adding to ben.bourdin answer, you can at least in any HTML based application, check if the browser supports HLS in its video element:

    Let´s assume that your video element ID is "myVideo", then through javascript you can use the "canPlayType" function (http://www.w3schools.com/tags/av_met_canplaytype.asp)

    var videoElement = document.getElementById("myVideo");
    if(videoElement.canPlayType('application/vnd.apple.mpegurl') === "probably" || videoElement.canPlayType('application/vnd.apple.mpegurl') === "maybe"){
        //Actions like playing the .m3u8 content
    }
    else{
        //Actions like playing another video type
    }
    

    The canPlayType function, returns:

    "" when there is no support for the specified audio/video type

    "maybe" when the browser might support the specified audio/video type

    "probably" when it most likely supports the specified audio/video type (you can use just this value in the validation to be more sure that your browser supports the specified type)

    Hope this help :)

    Best regards!

提交回复
热议问题