HTML5 video: How to test for HLS playing capability? (video.canPlayType)

I have video which is delivered over HLS. Now I’d like to test in JavaScript if the device actually can play HLS video in HTML5.

Usually in Javascript I did something like
However I can’t figure out which ‘type’ is the right one for HLS.

Apple’s Safari HTML5 Audio and Video Guide seems to suggest “” (“Listing 1-7 Falling back to a plug-in for IE”)

<video controls>
    <source src="" type="">
    <source src="ProgressiveDowload.mp4" type="video/mp4">

but canPlayType("") return an empty string even on iOS devices which can play actual HLS streams perfectly fine.

Is there any way to check for playback capabilities without ‘external knowledge’ (e.g. “check for iOS user agent and assume it can play hls”)?

I know I can specify multiple sources in a element and the browser will use the first playable source. However in my case I need feed a single URL to JW Player which I can’t modify. So somehow I need to find the “best playable URL” from a set of video encodings. (An open source JS library which handles source selection would be a nice workaround though.)

I haven’t tested this across the board, but it looks like you should be testing for the full HLS mimetype application/ instead of just just

application/x-mpegURL and audio/mpegurl are also suitable mimetypes for the HLS m3u8 file. audio/x-mpegurl is also listed as an acceptable mimetype according to Apple, but it doesn’t appear to be mentioned in the actual HLS draft spec.

In Safari on iOS and OS X,


returns maybe. I’m not sure if there are any other browsers that support HLS — Android doesn’t seem to like this syntax (despite some assertions I’ve seen to the contrary), and I believe that it may be due to the fact that the actual video playback is delegated to an external application, rather than the browser itself.

Read More:   Angularjs bootstrap dropdown not working



The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Similar Posts