Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Add initial audio codec support #1623

Open
KunXi-Fox opened this issue Jan 3, 2025 · 2 comments
Open

[Feature Request] Add initial audio codec support #1623

KunXi-Fox opened this issue Jan 3, 2025 · 2 comments

Comments

@KunXi-Fox
Copy link

Context

Currently rx-player use the first audio codec as default audio codec:

function getFirstDeclaredMimeType(adaptation: IAdaptation): string {
const representations = adaptation.representations.filter(
(r) => r.isPlayable() !== false,
);
if (representations.length === 0) {
const noRepErr = new MediaError(
"NO_PLAYABLE_REPRESENTATION",
"No Representation in the chosen " + adaptation.type + " Adaptation can be played",
{ tracks: [toTaggedTrack(adaptation)] },
);
throw noRepErr;
}
return representations[0].getMimeTypeString();
}

If I want to use another audio codec based on user preferences, I need to manually call setAudioTrack method. This is works at most of cases except the device that not support seamless audio codec switch, which means every audio codec changes will lead to a reload.

Solution

Provide a initialAudioCodec option and change getFirstDeclaredMimeType method to based on initialAudioCodec, if no initialAudioCodec specified, then fallback to first available audio codec.

@peaBerberian
Copy link
Collaborator

Hi @KunXi-Fox,

Normally you can set the audio track based on codecs before the RxPlayer has made any choice (and thus not have a reload) by reacting to the newAvailablePeriods event. For example:

player.addEventListener("newAvailablePeriods", (periods) => {
  for (const period of periods) {
    const audioTracks = player.getAvailableAudioTracks(period.id);
    
    // use external logic to select the wanted audio track based on the codec
    const chosenAudioTrack = chooseAudioTrack(audioTracks);

    if (chosenAudioTrack) {
      player.setAudioTrack({
        periodId: period.id,
        trackId: chosenAudioTrack.id,
      });
    }
  }
});

https://developers.canal-plus.com/rx-player/doc/api/Track_Selection/setAudioTrack.html#setting-the-audio-track-as-soon-as-possible
https://developers.canal-plus.com/rx-player/doc/api/Player_Events.html#newavailableperiods

At what point do you update the audio track? If it's e.g. at the "LOADED" state it may be late because the RxPlayer already has loaded audio data (from the previous track).

@KunXi-Fox
Copy link
Author

Yeah, just as you said, I set the initial audio codec at LOADED state. I'll try set it when first newAvailablePeriods event fired and see if it solve the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants