捕获Apple MusicKit JS中的错误

问题描述

我遇到了使用MusicKit JS创建网络播放器的情况。仍然是新事物,我遇到了可能会引发各种错误的问题。

例如,当尝试使用...播放特定歌曲时

function previewUpdater(scope){

    let counter = document.querySelector("#previewPhotoCounter")
    let previewBox = document.querySelector("#photosPreview")
    let locationSelector = document.querySelector("#newAlbumLocation")
    let eventSelector = document.querySelector("#newAlbumEvent")
    let dateSelector = document.querySelector("#newAlbumDate")
    
    counter.innerHTML = currentPhotos.length


    // This "initial" part of the function is used to fill the preview Box with
    // all the pictures when this filtering area is first visited,it's not very
    // relevant regarding the question.

    if (scope == "initial") {

        fillOptions()
        for (let i = 0; i < currentPhotos.length; i++) {
            let newDiv = document.createElement("div")
            let newImg = document.createElement("img")
    
            newImg.setAttribute("src",currentPhotos[i].path);
    
            newImg.addEventListener("click",openPhotoViewer)
    
            newDiv.appendChild(newImg)
    
            previewBox.appendChild(newDiv)
        
        }
    }

        // Here starts the part of the function regarding filtering
    if (scope=="subsequent") {
            // Remove photos that were already there

            while (previewBox.lastElementChild) {
                previewBox.removeChild(previewBox.lastElementChild);
            }

            // Getting data from the select fields and date picker
            let selectedLocation = locationSelector.options[locationSelector.selectedindex].text;
            let selectedEvent = eventSelector.options[eventSelector.selectedindex].text;
            let selectedDate = dateSelector.value

            for (let i = 0; i < currentPhotos.length; i++) {
                let newDiv = document.createElement("div")
                let newImg = document.createElement("img")
           
                // This is currently doing nothing,it's just my way of kNowing if the select fields
                // and date picker have been selected or are in their default values:
                if (selectedLocation != "Localization..." || selectedEvent != "Event..." || selectedDate != "" ) {
                    console.log("selected!")
                }
                
                // This,for example,checks if the current photo has the same date as the selected date
                console.log(selectedDate==currentPhotos[i].date)
                
                // From here on it's simply adding the pictures to the preview Box
                newImg.setAttribute("src",currentPhotos[i].path);
                newImg.addEventListener("click",openPhotoViewer)
        
                newDiv.appendChild(newImg)
        
                previewBox.appendChild(newDiv)
            
            }
}

我收到以下错误信息...

apple_player.play().then (function(){
                
    console.log ('Playing Song!');

}).catch (e => {

    console.log ('Play Error:' + e );

});

但是,并非所有歌曲都会发生这种情况,只是某些歌曲会发生这种情况。正如您在代码中看到的那样,我尝试使用CATCH进行包装,甚至尝试使用TRY / CATCH进行包装。错误仍然弹出。

我怎么抓到这个?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)