admin管理员组

文章数量:1122826

I am trying to use Apple's Musickit JS to play songs from Apple Music on a browser.

For some reason this works with some songs but not others in Chrome and Firefox (but it always works in Safari).

So far, I've created my Auth key and managed to allow users to authorise and play a song using Safari, but when using Chrome or Firefox, nothing happens and I don't even get an error message.

I have called in the API and included the "async" and "data-web-components" attributes like so:

<script src=".js" data-web-components async></script>

And my JS that works on Safari is as below:

document.addEventListener('musickitloaded', function() {
  MusicKit.configure({
    developerToken: 'MyDeveloperToken',
    app: {
      name: 'Apple Music App',
      build: '1.0.0'
    }
  });

});

function playASong() {
  var music = MusicKit.getInstance();
  music.authorize().then(function() {
    var url = '';
    music.setQueue({ url: url }).then(function(queue) {
      music.player.prepareToPlay(queue.nextPlayableItem).then(function() {
        music.player.play();
      });
    });
  });
}
const playbtn = document.querySelector(".play-button");
playbtn.addEventListener("click", function () {
    playASong();
});

When pressing the play button on Safari, I can see the Audio element appearing at the bottom of the page with the SRC:

<audio id="apple-music-player" preload="metadata" title="Hello, Hi - Little Simz - Hello, Hi - Single" src=".cpsl.aac.wa.m3u8"></audio>

However when using Chrome I am seeing the SRC as something along the lines of:

<audio id="apple-music-player" preload="metadata" title="Hello, Hi - Little Simz - Hello, Hi - Single" src="blob:;></audio>

I can't see any reason why this wouldn't work across the board, and none of the documentation I've seen is offering a solution, so any help is greatly appreciated!

本文标签: Apple Musickit JS not playing some songs on Chrome or Firefox browsers (working in Safari)Stack Overflow