Modify the title of the audio track in videojs while utilizing HLS technology

Currently, I am implementing video.js with both DASH and HLS depending on the platform that accesses the website. The issue I am encountering is that the audio track labels in the manifest files are not being properly displayed. To address this problem, I planned to adjust them using the code snippet below:

    const audioTrackList = this.player.audioTracks();
    
    for (let i = 0; i < audioTrackList.length; i++) {
      const element = audioTrackList[i];
      
      switch (this.get3LetterLangCode(element.language)) {
        case 'hun':
          element.label = this._translate.instant('Hungarian');
          break;
        case 'slk':
          element.label = this._translate.instant('Slovakian');
          break;
        case 'ron':
          element.label = this._translate.instant('Romanian');
          break;
        case 'bul':
          element.label = this._translate.instant('Bulgarian');
          break;
        case 'cze':
          element.label = this._translate.instant('Czech');
          break;
        case 'eng':
          element.label = this._translate.instant('English');
          break;
        default:
          break;
      }
    }

While this solution works correctly when using DASH, a problem arises when utilizing HLS as I encounter the error message:

Attempted to assign to readonly property

How can I make changes to the audio track label when working with HLS?

Answer №1

If you're looking for a solution that is compatible with both Dash and HLS, here's one that works seamlessly:

this.player.on('loadeddata', () => {
    let languageNames = new Intl.DisplayNames([],{type: 'language'});

    const audioTrackList = this.player.audioTracks();
    
    for (let i = 0; i < audioTrackList.length; i++) {
      const element = audioTrackList[i];
      element.label = languageNames.of(element.language)
    }
}) 

Answer №2

I encountered the issue of trying to modify a readonly property and found a workaround.

Although not the most elegant solution, it does get the job done.

const audioTrackList = this.player.audioTracks();
for (let i = 0; i < audioTrackList.length; i++) {
    let track = audioTrackList[0];
    this.player.audioTracks().removeTrack(track);
    const newTrack = new videojs.default.AudioTrack({...track, label: track.language, kind: 'main'});
    this.player.audioTracks().addTrack(newTrack as any);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

items within an unordered list that can be collapsed

Answer: Nikhil was on the right track with his solution, but I had to make some modifications. Specifically, I needed to create and initialize an empty array to display the details properly. Here's the updated code: if (this.name.toLowerCase() == va ...

Error: Unable to inject HttpClient dependency. Angular 5

I recently switched to using the Angular template in Visual Studio 2017 and decided to update to Angular 5.2. However, I encountered an error while trying to make a http call from the service class. The error message I received is: https://i.sstatic.net/p ...

Is it possible to add additional text to an input field without modifying its existing value?

I have a numerical input field labeled "days" that I want to add the text " days" to without altering the actual numerical value displayed. <input type="number" class="days" (keyup)="valueChanged($event)"/> Users should only be able to edit the num ...

A more efficient way to specify children types in Typescript React is by directly specifying the type in the function instead

What is the reason behind this: interface UserSidebarProps { children? : React.ReactNode } function UserSidebar({children}: UserSidebarProps) { return ( <div> {children} </div> ) } Why doesn't this work? function User ...

Can we confidently disregard React's caution regarding using the useState hook conditionally if only the parameter changes based on a condition?

In my React app, I am working on creating a calendar date selection function component to assign days to schedules. My goal is to pre-populate the calendar with existing data so users can modify it as needed. Here is what I have implemented so far: const ...

Initiate the input change event manually

Struggling with creating a custom counter input component where the input value is controlled by custom increment/decrement buttons. Desired output: https://i.sstatic.net/oYl1g.png Content projection will be used to expose the input for form usage and a ...

Looking to arrange an object by the value of a nested object in Typescript/Angular?

I'm currently developing an Angular 9 application focused on covid-19 cases, and I need to arrange my objects by the value of nested objects. Here is the dataset that I want to organize alphabetically based on the 'state' field values: stat ...

Leveraging environment variables in template documents

Can you incorporate environment variables into template files successfully? Currently, I am experimenting with the following syntax: <img class="preview-image" src="{{environment.assets + item.image}}" /> However, this approach leads to the follow ...

Create a unique TypeScript constant to be mocked in each Jest test

Having difficulty mocking a constant with Jest on a per test basis. Currently, my mock is "static" and cannot be customized for each test individually. Code: // allowList.ts export const ALLOW_LIST = { '1234': true }; // listUtil.ts import { ...

Handling events in React using TypeScript

Currently diving into the world of React with Typescript and encountered a challenge involving event handling using the onClick property. I have a react component displaying a list of items from an array, and I aim to log the clicked item in the console. I ...

Beautiful parentheses for Typescript constructors

I'm working on a project where I've installed prettier. However, I've noticed that it always reformats the code snippet below: constructor(public url: string) { } It changes it to: constructor(public url: string) {} Is there any way to sto ...

Locate the closest point among a set of coordinates to a specified point

I have a situation where I have an object that contains latitude and longitude attributes. My goal is to find the closest match in an array of similar objects by considering both latitude and longitude. obj = {latitude: 55.87, longitude: 4.20} [ { & ...

Using TypeScript: creating functions without defining an interface

Can function props be used without an interface? I have a function with the following properties: from - HTML Element to - HTML Element coords - Array [2, 2] export const adjustElements = ({ from, to, coords }) => { let to_rect = to.getBoundingC ...

What steps can I take to improve this code and prevent the error "Property 'patient' does not exist on type 'Request<ParamsDictionary>'" from occurring?

I'm having some issues with my code. I am attempting to use passport authenticate in order to save patient information that is specific to the token generated for each individual. router.get("/current", passport.authenticate("jwt", { session: false }) ...

Quick method to alter theme and store it - Ionic

How can I modify the appearance of an element by changing its color and font size when a user clicks a button? <h1> Hello Stackoverflow </h1> <button (click)="changeTheme()">Change Theme</button> What is the best approach to chang ...

Vue warning: Issue in rendering: "TypeError: Circular structure being converted to JSON"

After successfully creating a Single File Component in Vue without any compilation errors, I faced an issue when trying to view the component through its route link. Instead of the expected page, I encountered a stack trace printed in the Chrome browser us ...

TypeScript mistakenly infers the incorrect type for AbstractControl when used with a generic type_declaration

My InnerComponent requires a FormArray as input, and in order to access the type of the controls within the array, I have introduced a type parameter called ControlValue. The input is declared to be of type FormArray<AbstractControl<ControlValue>& ...

I am encountering an issue where the nested loop in Angular TypeScript is failing to return

I am facing an issue with my nested loop inside a function. The problem is that it is only returning the default value of false, instead of the value calculated within the loop. Can someone please point out what I might be doing incorrectly? Provided belo ...

Struggling to extract the hours and minutes from a date in IONIC: encountering an error stating that getHours is not a recognized

I encountered an issue while trying to extract the hours and minutes from a date in Ionic. Below is the code snippet from my .html file : <ion-datetime displayFormat="HH:mm" [(ngModel)]='timeEntered1' picker-format="h:mm"></ion-date ...

Leverage the power of npm to utilize various javascript libraries for

I seem to be a bit confused here. Currently, I have the following code snippets: import * as angular from 'angular'; import 'ts-angular-jsonapi'; Interestingly, no errors are being returned with this setup. But as soon as I try this: ...