Solve the error "Property 'container' of null is not accessible" in musickit.js while running an Angular application on a server

I am currently developing an application that combines Angular and MusicKit to offer users the ability to listen to music simultaneously. However, I encountered a challenging error when trying to run the application using ng serve --host x.x.x.x instead of the default localhost with ng serve:

core.js:14597 ERROR TypeError: Cannot read property 'container' of null  
    at Player. (musickit.js:formatted:6614)  
    at musickit.js:formatted:726  
    at Object.next (musickit.js:formatted:739)  
    at fulfilled (musickit.js:formatted:627)  
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388)  
    at Object.onInvoke (core.js:16156)  
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:387)  
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:138)  
    at zone.js:872  
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)  



21:08:38.100 core.js:14597 ERROR Error: Uncaught (in promise): 
TypeError: Cannot read property 'isFairplay' of undefined  
TypeError: Cannot read property 'isFairplay' of undefined  
    at MediaExtension.get [as isFairplay] (musickit.js:formatted:5020)  
    at musickit.js:formatted:6728  
    at Array.filter ()  
    at Player._playbackDataForItem (musickit.js:formatted:6726)  
    at Player. (musickit.js:formatted:6504)  
    at musickit.js:formatted:726  

The "isFairplay" error may be related to the initial error, but I included it as a precaution. While running on a remote server (ng build, move the dist folder over to /var/www/html) with nginx, the application runs smoothly locally using "ng serve --host x.x.x.x" against my local IP. Everything functions properly when using plain ng serve. I have tested with different Apple Music accounts in various browsers and incognito windows in Chrome.

The goal is to: 1. Display a list of songs from the user's library 2. Allow users to choose a song 3. Subscribe to observable steps: 4. Queue the selected song with musicKit.queueSong 5. Play the queued song using musicKit.player.play()

The errors occur after step 5. Despite adding container.id to the song object, it seems that Apple fails to queue the song correctly. The queuing process returns successfully, indicating other elements in the object might be null or undefined, not just container.id.

The code snippet below demonstrates the above steps. "playSong(..)" is subscribed to in another class:

playSong(songs: any[], index: number): Observable {  
    if(songs) {  
      //songs play without the forEach, but musicKit still complains 
      //about not finding container.id in the song object  
      songs.forEach(song => song['container'] = { 'id' : song.id });  


      return from(this.musicKitService.setQueue({ 'items': songs, startPosition: index}))  
        .pipe(mergeMap(x => this.play()));  
    }  
  }  

  modifyPlayback(arg: Observable): Observable {  
    return arg.pipe(map(x => this.setTitle()));  
  }  

  play(): Observable {  
    return this.modifyPlayback(from(this.player.play()));  
  }      

The expectation is for the song to start playing in the browser post these actions. Essentially, a single song is being queued and then instructed to play by musicKit.js. However, upon attempting to play the queued song, musicKit.js finds no song available. The mystery lies in what happens to the song after a successful queueing outside of localhost.

In addition, I have posted this issue on the Apple Developer Forums, seeking assistance from others who faced similar problems last year without resolution.

To note, this problem only occurs in Chrome. The code functions correctly in Firefox and mobile Safari.

Answer №1

Resolution:

I discovered that in Chrome, musicKit.js necessitates SSL for the hosted site to function properly. While running everything locally posed no issues for me, attempting to run against my network's IP address triggered errors due to the lack of SSL. Once I configured https on my server, these errors ceased. It seems that this requirement is not explicitly stated in the musicKit.js documentation, although it is possible that I overlooked it.

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

Is there a way to incorporate the "Handoff to Human" feature in a Microsoft Teams bot app by utilizing the Teams Toolkit? Can this functionality be implemented using TypeScript?

Can someone assist me with figuring out how to incorporate the "handoff conversation to human agent mechanism" in my project using TypeScript, Microsoft Bot Framework, and Teams Toolkit? ...

Issue encountered when executing the migration fresh seed: SyntaxError, which indicates the absence of a closing parenthesis after the

Having trouble with a nextJS project that utilizes mikro-orm? Struggling to overcome this persistent error for days: C:\Users\BossTrails\Documents\core.nest-main_2\node_modules\.bin\mikro-orm:2 basedir=$(dirname "$(e ...

The <div> element is not displaying the JSON response when using Ajax

I have created a basic login form and I am attempting to validate it using an AJAX call. The validation process is successful, but the issue arises when the correct email or password is entered. Instead of displaying the JSON success or error message in a ...

Trigger refetchQueries post-execution of a mutation operation

In the past, I executed a mutation in a similar manner as shown below: export const useEditLocationName = () => { const [editFavoriteLocationName] = useEditFavoriteLocationNameMutation({ refetchQueries: [{ query: GetMyFavouritePlacesDocument}], ...

Retrieve information from the server (using asp.net) using Java Script and store it in the local storage of the client device

I am receiving a JSON object from the server-side, but I have been struggling to save it in LocalStorage. When I check FireBug, this is how it appears: If you are having trouble viewing the images clearly, try opening them in a separate page by right-click ...

Does Angular have an OnActivate function in its methods?

At the moment, my angular page is utilizing ngOnInit(). When I navigate to /home and click on the home link, it seems that ngOnInit() is not being triggered. Is there an equivalent of onActivate() perhaps? ngOnInit() { this.getPage(1); } ...

Struggling with "Content" not being recognized in Typescript PouchDB transpilation errors?

I have been diligently working on an Ionic app for the past three months with no major issues during development or deployment to mobile devices. However, yesterday I encountered a frustrating NPM dependency problem while trying to deploy to mobile. In an ...

Integrate NodeJs into Ionic framework for enhanced functionality and dynamic

I created a hybrid application using Ionic framework. Currently, I have been using PHP and MySQL as the backend technology. However, after doing some research, I realized that Node.js with Express.js and MongoDB are considered more modern options. Most ...

There seems to be a problem with how the navbar is being displayed in ResponsiveSlides.js

I am currently using WordPress, but I have come here seeking help with a jQuery/CSS issue. I am utilizing responsiveSlides.js to create a simple slideshow, however, when viewing it here at gallery link, it appears that something is not quite right. STEPS: ...

Steps to finish (refresh) a mongoDB record

Currently, I am dealing with the following scenario: An API request from one service is creating multiple MongoDB documents in a single collection. For example: [ {_id: 1, test1: 2, test: 3}, {_id: 2, test1: 3, test: 4} ] Subsequently, a second service ...

Retrieving data from child components within an array in another component using Angular

How can I assign the value of the variable 5 in Array(5) to another variable in this code? My goal: export class HelloComponent { @Input() page: number; active = 0; pages; constructor() { this.pages = Array(this.page) // instead of Array( ...

There is an issue with types in React when using TypeScript: The type '(user: User) => Element' cannot be assigned to the type '((props: User) => any) & ReactNode'

I'm encountering an error in the terminal and need some assistance. I am not well-versed in TypeScript, so any guidance to resolve this issue would be highly appreciated. https://i.stack.imgur.com/PWATV.png The Loadable component code: import { Circ ...

Modifying the disabled attribute of an input tag upon button click in Angular 2

I am currently working on a function in Angular 2 where I want to toggle the disabled attribute of an input tag upon button click. Right now, I can disable it once but I am looking to make it switch back and forth dynamically. Below is the HTML template c ...

Create a custom chrome browser extension designed specifically for sharing posts on

I'm working on creating a basic chrome extension that features an icon. When the icon is clicked, I want the official Twitter window to pop up (similar to what you see here). One common issue with existing extensions is that the Twitter window remains ...

api for enhancing images in Laravel app through preview, enlarge, and zoom functionalities

As I work on my website, I aim to display images in a compact space, such as within a 300x300 <div>. What I envision is the ability for users to preview or enlarge these images upon clicking, allowing for a closer and more detailed view. For exampl ...

Tips for confirming schedule accuracy

Trying to determine if a specific time falls between two others is the task at hand. Allow me to illustrate: Presently, it's Thursday, and the time reads 11:39 PM. Establishment X operates from 12:00 AM to 11:59 PM on Thursdays (a regular occurrence ...

Using React Bootstrap to conditionally render columns within an array map

Within my React application, I am currently utilizing the map function to generate Bootstrap columns in the JSX code of the render method. One specific attribute within the array object I'm mapping is named "taken." Depending on whether this attribute ...

What sets apart importing components in computed from importing components in dynamic import in Vue.js?

Imagine there are 4 components available on a page or within a component, and the user can utilize them based on their selection by toggling between Input, Image, Video, or Vudio components. There are two ways to lazily load these components: 1) <temp ...

I am encountering a JSON parsing error while trying to implement jQuery autocomplete, despite using a local array

I'm attempting to implement the jQuery autocomplete feature on a WordPress website. My ultimate goal is to link the input field to an ajax request that will retrieve data from a database. However, I've encountered an unusual error when trying to ...

The following MongoDB errors unexpectedly popped up: MongoNetworkError: connect ETIMEDOUT and MongoServerSelectionError: connect ETIMEDOUT

I've been working on a React and NextJS App for about a month now, utilizing MongoDB as my database through MongoDB Atlas. I'm currently using the free version of MongoDB Atlas. For the backend, I rely on NextJS's api folder. Everything wa ...