Multiple Audio Renditions

To access these features, Upgrade Now

Overview

Using the JW Player HLS provider, if an M3U8 manifest provides multiple audio tracks, we will automatically choose an audio track to play alongside the video. JW Player also provides an interface for viewers to toggle between the alternate audio tracks. The audio will switch as soon as it is loaded, with as little buffering as possible.

The labels for these options are based on the M3U8 file, using the NAME attribute. The NAME is specified as being a human-readable description. Here is an M3U8 manifest that illustrates this:

  #EXTM3U
  #Audio renditions
   #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="English", DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="en", URI="main/english-audio.m3u8"
   #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="Deutsch",DEFAULT=NO,AUTOSELECT=YES,LANGUAGE="de", URI="main/german-audio.m3u8"
   #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="Commentary",DEFAULT=NO,AUTOSELECT=NO,URI="commentary/audio-only.m3u8"
 
 #Video qualities
   #EXT-X-STREAM-INF:BANDWIDTH=1280000,CODECS="...",AUDIO="aac"
   low/video-only.m3u8
   #EXT-X-STREAM-INF:BANDWIDTH=2560000,CODECS="...",AUDIO="aac"
   mid/video-only.m3u8
   #EXT-X-STREAM-INF:BANDWIDTH=7680000,CODECS="...",AUDIO="aac"
   hi/video-only.m3u8
   #EXT-X-STREAM-INF:BANDWIDTH=65000,CODECS="mp4a.40.5",AUDIO="aac"
   main/english-audio.m3u8

Servers like Wowza Media Server, Microsoft Azure, and Unified Streaming Platform all support rendering of playlists with alternate audio out of the box.

Default Track Selection

JW Player looks at DEFAULT and LANGUAGE to determine which audio track to start up the stream with. If there is a language code matching the system setting language, the JW Player will automatically choose that track. Otherwise it reverts to the DEFAULT track. If no default is specified, the first audio track in the manifest will be used.

Audio Tracks API

These API calls are used to listen to or update the audio track if multiple audio tracks of a video are provided.

getAudioTracks()
Returns an array with audio tracks from the player. Each track is an object that contains a label property.
getCurrentAudioTrack()
Returns the index of the currently active audio track.
setCurrentAudioTrack(index)
Change the audio track to the provided index. The index must be within the list provided by getAudioTracks.
on('audioTracks', function(event){});
Fired when the list of available audio tracks is updated. Happens e.g. shortly after a playlist item starts playing. Event attributes:
  • levels (Array): the full array with new quality levels.
on('audioTrackChange', function(event){});
Fired when the active audio track is changed. Happens in repsponse to e.g. a user clicking the audio tracks menu or a script calling setCurrentAudioTrack. Event attributes:
  • currentTrack (Number): index of the new quality level in the getAudioTracks() array.

Example HLS Stream with Alternate Audio

Here is an example of a stream that contains a Spanish, English, and directors commentary audio tracks.

Sample Embed code

As always, ensure you have uploaded a copy of JW Player and included the script in the <head> of your page, together with your player key. See the Basic Video Embed article for more info. Next, place the following embed code at the location you want the player to appear:

<div id="myElement"></div>

<script>
var playerInstance = jwplayer("myElement");
playerInstance.setup({
	image: "/uploads/myPoster.jpg",
	file: "/uploads/myManifest.m3u8",
});
</script>

To see a demo of HLS v4 Audio Tracks, visit our developer site

Note that both the M3U8 manifests and the TS fragments of an HLS stream are subject to cross-domain security restrictions and therefore won't automatically load from another domain than the player. See Crossdomain File Loading for more info.
 

See Using Apple HLS Streaming for more info.

Did you find this article helpful?

Please log in to rate this article.