Incorporate MUX Player (Video) into Angular versions 14 or 15

Mux offers a video API service with its own player: MUX Player

I am interested in integrating this npm package specifically into a component in Angular 14/15. The JavaScript should only be loaded when this particular component is rendered.

Integration

There are two ways to utilize the Mux service:

  1. By directly importing the script using
    <script src="https://unpkg.com/@mux/mux-player"></script>
    in the HTML (which can be done in angular's index.html file), but this loads the script for all users which is not ideal.
  2. Using the npm Package @mux/mux-player

Usage

Add the following code to an HTML component where the script or npm package has been imported:

<mux-player
stream-type="on-demand"
playback-id="FuJSYrK0014ec2LPnm11bzC2MAySAQPqA"
metadata-video-title="Tea and Cookies"
metadata-user-id="user-24601"
/>

Make sure to include

schemas: [CUSTOM_ELEMENTS_SCHEMA]
in the module (or standalone component) as well.

Challenge

Angular can have difficulty with untyped packages. It seems that this package uses TypeScript, however, when I import the npm package, I encounter numerous errors. Essentially, Angular removes it during tree-shaking because I'm not using the imported class in the component's TypeScript. As a result, upon loading, I see:

Cannot find module '../../../types/mux' or its corresponding type declarations
and
Property 'error' in type 'MuxVideoElement' is not assignable to the same property in base type 'CustomVideoElement<HTMLVideoElement>'. Type 'MediaError' is missing the following properties from type 'MediaError': MEDIA_ERR_ABORTED, MEDIA_ERR_DECODE, MEDIA_ERR_NETWORK, MEDIA_ERR_SRC_NOT_SUPPORTED
, among others.

Attempts

  1. To validate that the <script> import functions properly with the HTML code, I included the script in the index.html, resulting in the elimination of errors and successful loading of the player.

  2. I attempted importing the npm package with

    import MuxPlayerElement from "@mux/mux-player";
    and adding
    declare module "@mux/mux-player";
    to the typings.d.ts.

  3. Imported the package into the component and tried declaring the @ViewChild template ref as a MuxPlayerElement to bypass any tree-shaking.

An Angular demo mentions "This player? It's an open book." at , but this led to the error

Only void and foreign elements can be self closed "mux-player"
. A simple solution is closing the tag with </mux-player> instead of .../>

Answer №1

Exciting News!

New update from Mux regarding angular support in version 1.9.0

Check out the details here!

Here are the steps to implement:

  1. npm install @mux/mux-player
  2. Add
    schemas: [CUSTOM_ELEMENTS_SCHEMA]
    to your module or standalone component
  3. Import "@mux/mux-player" to your target component imports
  4. Use as instructed with
    <mux-player ...></mux-player>

Celebrate this accomplishment! 🎉

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

Testing for expressjs 4 using Mocha revealed unexpected behavior when attempting to spy on a function called within a promise. Despite setting up the

I have encountered a situation with some test cases structured like this: it('does stuff', function(done) { somePromise.then(function () { expect(someSpy).to.have.been.called done() }) }) When the assertion in a test case fails, it ...

Enhance Leaflet Marker functionality using Typescript

I am currently tackling a project that involves using Typescript and Leaflet. Traditionally, to extend the leaflet marker in JavaScript, it is done like this: L.Marker.Foo = L.Marker.extend({...}); But when I attempt to do this in Typescript, I encounter ...

The Angularfire library encountered an issue when trying to access the 'push' property of a null object

I am currently in the process of creating a new object in the database for an assessment. Right now, I have hardcoded it to test its functionality, but ultimately, it will be dynamic based on user input from the view. However, I am encountering an error th ...

Utilize a class method within the .map function in ReactJS

In my ReactJS file below: import React, { Component } from "react"; import Topic from "./Topic"; import $ from "jquery"; import { library } from '@fortawesome/fontawesome-svg-core' import { FontAwesomeIcon } from '@fortawesome/react-fontaw ...

Polymerfire: Unable to locate a default bucket

Having an issue with uploading data to the storage Bucket of my app. The line var uploadRef = firebase.storage().ref(); is triggering this error message: Firebase Storage: No default bucket found. Ensure the 'storageBucket' property is set when ...

Steps to display the Sidebar on top of the main information page

One unique feature of my website is the FiltersSideBar located on the left side of the page. It contains various filters to refine search results. To optimize user experience, I implemented a function that hides the sidebar at specific browser window size ...

What is the best way to transfer data to a component that is not directly related

I am looking to showcase an image, title, and description for a specific recipe that I select. Here is my setup using ItemSwiper (parent): <template> <Slide v-for="recipe in storeRecipe.data" :key="recipe.rec ...

RecoilRoot from RecoilJS cannot be accessed within a ThreeJS Canvas

Looking for some guidance here. I'm relatively new to RecoilJS so if I'm overlooking something obvious, please point it out. I'm currently working on managing the state of 3D objects in a scene using RecoilJS Atoms. I have an atom set up to ...

Searching with Neo4j, Java and the Angular library for accurate

When my web application is opened, it displays a form where users can input a list of comma-separated usernames. The application then queries the neo4j database to fetch information for each username. I am interested in implementing autocomplete functiona ...

Inquiry about CSS Media Queries

I am facing an issue with CSS media queries... For my HTML page, I have separate files for desktop and iPad styles - desktop.css and ipad.css. In desktop.css, I have used @import url("ipad.css"); and added a @media not only screen and (device-width:768px) ...

Incorporating JavaScript into a Rails Application

When I click on a link "link_to" in my rails app, I am attempting to trigger a JS file. To confirm that the asset pipeline is functioning correctly, I conducted a test with: $(document).ready(function() { alert("test"); }); The alert successfully po ...

Collapse or display div elements with jQuery - First close all other elements before opening the selected item

The Problem at Hand Currently, the script is expected to hide all elements with the "gallery-collapse" class and reveal the specific content based on the clicked link. However, sometimes multiple divs might appear simultaneously when switching between ite ...

What is the best way to create a drop-down menu that exports data directly to an Excel spreadsheet?

I have been struggling with a seemingly simple issue - I can't seem to get my drop-down box to display the chosen option. The code I'm using is quite similar to this generic one, but for some reason, it's not reporting the selected option to ...

Binding data with non-nested components

My dilemma involves two components - one with checkboxes and the other with a table. These components are not nested within each other. I want to manipulate certain classes in the table columns when a checkbox is unchecked. Can anyone suggest the most ef ...

Utilizing React JS Styled-Components to Import Images from the Public Directory

I've been attempting to set the image as a background-image from the public folder using styled-components. I've tried the following: import styled from "styled-components"; import Background from 'process.env.PUBLIC_URL + /images/ ...

Tackling the white-source security problem in npm libraries

A security advisory from White-source has identified high vulnerability issues with certain libraries used in your repository, specifically with yargs-parser: 1. build-angular-0.13.8.tgz (Root Library) node-sass-4.11.0.tgz sass-graph-2.2 ...

Press the toggle button to switch the image display

Currently learning HTML and attempting to design a dashboard. I want to display the status (ON, OFF, OPEN, or CLOSED) of a room or door using an icon. I have images for open/close doors and lightbulbs. Need assistance in adding an element to all the exist ...

Tips for overcoming a challenge with a promise of $q

Currently in my AngularJS project, I am utilizing $q for promises and feeling a bit overwhelmed with the usage. How can I resolve this promise-related issue? My goal is to either return the user when isLoggedInPromise() is triggered or provide a response ...

What is the best way to combine the existing array data with the previous array data in JavaScript?

I am implementing server-side pagination in my MERN project. Let's say I retrieve 100 products from the database and want to display only 30 products, with 10 products per page. When a user navigates to the 4th page, I need to make another API call to ...

I am looking to generate an array with key-value pairs from an object that will be seen in the examination

I have a task that involves configuring a table and creating objects with key-value pairs for each key. type KeyValuePair<T> = {/** ... */}; let userKeyValuePair :KeyValuePair<{id:number,userName:string}>; // => {key:'id',value: ...