video.js
video.js copied to clipboard
audioTracks() returns an empty array for a video file with one audio track
Description
Hello, Team!
When calling the player.audioTracks()
function on a video file (https://vjs.zencdn.net/v/oceans.mp4) with 1 audio track (according to MediaInfo), the function returns an empty array:
audioTracksNotWorking
Am I missing something?
Reduced test case
https://codepen.io/omcsesz/pen/PoROyyb?editors=1111
Steps to reproduce
- Open the page with video.js in it, where the source is set to https://vjs.zencdn.net/v/oceans.mp4
- Open developer console
- The audioTracks() function returns an empty array
Errors
No response
What version of Video.js are you using?
7.20.1
Video.js plugins used.
No response
What browser(s) including version(s) does this occur with?
Firefox 103.0
What OS(es) and version(s) does this occur with?
Windows 10
Hey! We've detected some video files in a comment on this issue. If you'd like to permanently archive these videos and tie them to this project, a maintainer of the project can reply to this issue with the following commands:
- for https://vjs.zencdn.net/v/oceans.mp4: say
@video-archivist-bot save 4Ek4xj
I think I found the root cause: this function is only supported in IE: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/audioTracks
Yes, for MP4 it depends on the browser's native playback. audioTracks()
is more useful with HLS and DASH, as Safari (native HLS) and http-streaming, our playback engine for MSE browsers both implement audio tracks.
So, is there a way to use audioTracks()
outside IE? Or is there another method for retrieving the audio tracks of a video file?
What are you trying to do?
Also, worth noting that you're printing the audioTracks too early before the player is ready. If you swap it to do it on player ready, I can see that Safari does return an audio track.
var player = videojs('my_video', {}, () => {
console.log("audioTracks.length : ", player.audioTracks().length);
});
Unfortunately, other browsers don't currently expose audio tracks for mp4s.
What are you trying to do?
I'm trying to create a JS code that can be used to list the audio tracks, and then possibly change the currently played one.
Cool, then you'll need to handle when the list is empty. It's also worth noting that Video.js will create a list for you if there is more than one item in the audio tracks list (see https://videojs-http-streaming.netlify.app/ for an example (the headphones icon)).
Cool, then you'll need to handle when the list is empty. It's also worth noting that Video.js will create a list for you if there is more than one item in the audio tracks list (see https://videojs-http-streaming.netlify.app/ for an example (the headphones icon)).
Does this app work for mp4 files as well?
Yeah, that test page passes the source to Video.js, which then it figures out how to play it.
Yeah, that test page passes the source to Video.js, which then it figures out how to play it.
When I pass https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8 to the app, the headphones icon appears, and works correctly, but when I pass https://vjs.zencdn.net/v/oceans.mp4, it does not. Is this the correct behavior?
Hey! We've detected some video files in a comment on this issue. If you'd like to permanently archive these videos and tie them to this project, a maintainer of the project can reply to this issue with the following commands:
- for https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8: say
@video-archivist-bot save REVWdj
- for https://vjs.zencdn.net/v/oceans.mp4: say
@video-archivist-bot save rwoJMj
Yes, that is the correct behavior. Since, chrome doesn't support audio tracks for mp4s. In Safari, we won't show it because there's only a single track.
Yes, that is the correct behavior. Since, chrome doesn't support audio tracks for mp4s. In Safari, we won't show it because there's only a single track.
So, if I understand correctly, there is no way to make audio track selection with video.js for an MP4 file work in Chrome, or Firefox?
Yes, that's correct. MP4s are played back by the browser, and they currently do not expose audio tracks.