【问题标题】:How to play music using Apple Music Kit JS如何使用 Apple Music Kit JS 播放音乐
【发布时间】:2020-09-01 21:46:00
【问题描述】:

我正在尝试使用 Apple Music Kit JS 创建一个小型播放器,但我在播放歌曲时遇到了问题。

这是我当前的代码:

<html>

<head>
  <meta charset=utf-8>
  <link rel="shortcut icon" href="#" />
  <title>Hear for Mac</title>
</head>

<body>

  <script src="https://js-cdn.music.apple.com/musickit/v1/musickit.js"></script>
  <script>
    const music = MusicKit.configure({
      developerToken: 'token', // I put my own token in the real code
      app: {
        name: 'Hear',
        build: '1978.4.1'
      }
    });

    music.authorize().then(function () {
      console.log("Authorized");
      music.setQueue({
        song: '1292397498'
      }).then(function () {
         music.play();
      })
    })

    window.music = music;
  </script>
</body>

</html>

这是我尝试播放时遇到的错误:

TypeError: Argument 1 ('event') to EventTarget.dispatchEvent must be an instance of Event

【问题讨论】:

    标签: javascript apple-music apple-musickit apple-musickit-js


    【解决方案1】:

    你首先忘记了脚本

    document.addEventListener('musickitloaded',function() {
    // here configuration of MusicKit Instance and all the playback
    }
    

    当您尝试配置 MusicKit 时,它尚未加载

    【讨论】:

      猜你喜欢
      • 2022-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      • 2016-06-19
      • 2012-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多