video.js icon indicating copy to clipboard operation
video.js copied to clipboard

audioTracks() returns an empty array for a video file with one audio track

Open Omcsesz opened this issue 2 years ago • 14 comments

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

  1. Open the page with video.js in it, where the source is set to https://vjs.zencdn.net/v/oceans.mp4
  2. Open developer console
  3. 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

Omcsesz avatar Jul 29 '22 14:07 Omcsesz

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

video-archivist-bot avatar Jul 29 '22 14:07 video-archivist-bot

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

Omcsesz avatar Aug 01 '22 09:08 Omcsesz

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.

mister-ben avatar Aug 01 '22 12:08 mister-ben

So, is there a way to use audioTracks() outside IE? Or is there another method for retrieving the audio tracks of a video file?

Omcsesz avatar Aug 01 '22 13:08 Omcsesz

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.

gkatsev avatar Aug 01 '22 16:08 gkatsev

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.

Omcsesz avatar Aug 01 '22 18:08 Omcsesz

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)).

gkatsev avatar Aug 01 '22 18:08 gkatsev

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?

Omcsesz avatar Aug 02 '22 07:08 Omcsesz

Yeah, that test page passes the source to Video.js, which then it figures out how to play it.

gkatsev avatar Aug 02 '22 14:08 gkatsev

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?

Omcsesz avatar Aug 03 '22 09:08 Omcsesz

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

video-archivist-bot avatar Aug 03 '22 09:08 video-archivist-bot

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.

gkatsev avatar Aug 03 '22 15:08 gkatsev

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?

Omcsesz avatar Aug 03 '22 16:08 Omcsesz

Yes, that's correct. MP4s are played back by the browser, and they currently do not expose audio tracks.

gkatsev avatar Aug 03 '22 16:08 gkatsev