Aaaaand.... the next problem.
I'm getting a crash:
Uncaught Error: ""setVisibility can be called only on elements in DOM tree!
And since I'm not calling anything to do with visibility, I don't know where it originates from.
Basically, I'm using a playlist called __blacklist__ to store tracks. On start play of a track I reference if it occurs in __blacklist__ and if so skip to the next song. So far so good.
The problem occurs in the menu item to send a track (or selection) to the blacklist. It basically works. But sometimes when right-clicking on a track or selection, I'm getting the above error. Not sure what it clashes with, because if I just right-click now 50 times in a row, it works fine...
I've got code in 2 files. my local.js contains:
Code: Select all
(function () {
var currState;
var player = app.player;
var track;
var handleBlacklistTrackChange = async function () {
var testTrack = player.getCurrentTrack(); // cannot use fast, we will need this for async operation
track = testTrack;
if( track) {
var occursInBlacklist = await doesTrackOccurInBlacklist( track );
if( occursInBlacklist ) {
app.player.nextAsync(true);
}
}
};
var onPlaybackState = function (state) {
if (state === 'trackChanged') {
handleBlacklistTrackChange();
};
};
//
localListen(player, 'playbackState', onPlaybackState);
handleBlacklistTrackChange(); // set initial state
})();
And an actions_add.js containing:
Code: Select all
var blacklistName = '_Blacklist_';
var getBlacklist = async function (plst) {
var playlists = plst.getChildren();
await playlists.whenLoaded();
for (var i = 0; i < playlists.count; i++) {
playlists.locked(function () {
item = playlists.getValue(i);
})
if ( item.title === blacklistName ) {
blacklistId = item;
return blacklistId;
}
};
};
//This function can be called to check if a given track occurs in the blacklist.
var doesTrackOccurInBlacklist = async function (track) {
var blacklistId = undefined;
if( track ) {
ODS('RW: doesTrackOccurInBlacklist Start: ' + track.artist + ' - ' + track.title + ' ID: ' + track.id);
}
blacklistId = await getBlacklist(app.playlists.root);
if ( blacklistId == undefined ) {
ODS('RW: doesTrackOccurInBlacklist: No blacklist found');
}
var blacklistTracks = blacklistId.getTracklist();
await blacklistTracks.whenLoaded();
var hasher = {};
for (var i = 0; i < blacklistTracks.count; i++) {
blacklistTracks.locked(function () {
item = blacklistTracks.getValue(i);
})
if ( track.id === item.id ) {
return true;
}
}
return false;
}
window.actions.sendToBlacklist = {
icon: 'playlist',
title: _('Send Selection To Blacklist'),
execute: function () {
var blacklistId = undefined;
var createBlacklist = async function() {
ODS('RW: createBlacklist');
blacklistId = app.playlists.root.newPlaylist();
blacklistId.name = blacklistName;//'_Blacklist_';
blacklistId.isAutoPlaylist = false;
blacklistId.commitAsync().then(function () {
blacklistId.isNew = true;
});
return blacklistId;
};
var addToBlacklist = async function() {
blacklistId = await getBlacklist(app.playlists.root);
if ( blacklistId == undefined ) {
createBlacklist();
}
if ( blacklistId == undefined ) {
//Generate error message
return;
};
var list = await uitools.getSelectedTracklist().whenLoaded();
if (list.count === 0) {
return;
}
blacklistId.addTracksAsync(list);
}
addToBlacklist();
}
}
window.actions.sendTo.override({
submenu: async function($super, params) {
var result = await $super(params);
result.push({
action: actions.sendToBlacklist,
order: 50,
grouporder: 40,
});
return result;
}
});
I can zip and upload the files if needed.
Aaaaand.... the next problem.
I'm getting a crash:
Uncaught Error: ""setVisibility can be called only on elements in DOM tree!
And since I'm not calling anything to do with visibility, I don't know where it originates from.
Basically, I'm using a playlist called __blacklist__ to store tracks. On start play of a track I reference if it occurs in __blacklist__ and if so skip to the next song. So far so good.
The problem occurs in the menu item to send a track (or selection) to the blacklist. It basically works. But sometimes when right-clicking on a track or selection, I'm getting the above error. Not sure what it clashes with, because if I just right-click now 50 times in a row, it works fine...
I've got code in 2 files. my local.js contains:
[code](function () {
var currState;
var player = app.player;
var track;
var handleBlacklistTrackChange = async function () {
var testTrack = player.getCurrentTrack(); // cannot use fast, we will need this for async operation
track = testTrack;
if( track) {
var occursInBlacklist = await doesTrackOccurInBlacklist( track );
if( occursInBlacklist ) {
app.player.nextAsync(true);
}
}
};
var onPlaybackState = function (state) {
if (state === 'trackChanged') {
handleBlacklistTrackChange();
};
};
//
localListen(player, 'playbackState', onPlaybackState);
handleBlacklistTrackChange(); // set initial state
})();
[/code]
And an actions_add.js containing:
[code]var blacklistName = '_Blacklist_';
var getBlacklist = async function (plst) {
var playlists = plst.getChildren();
await playlists.whenLoaded();
for (var i = 0; i < playlists.count; i++) {
playlists.locked(function () {
item = playlists.getValue(i);
})
if ( item.title === blacklistName ) {
blacklistId = item;
return blacklistId;
}
};
};
//This function can be called to check if a given track occurs in the blacklist.
var doesTrackOccurInBlacklist = async function (track) {
var blacklistId = undefined;
if( track ) {
ODS('RW: doesTrackOccurInBlacklist Start: ' + track.artist + ' - ' + track.title + ' ID: ' + track.id);
}
blacklistId = await getBlacklist(app.playlists.root);
if ( blacklistId == undefined ) {
ODS('RW: doesTrackOccurInBlacklist: No blacklist found');
}
var blacklistTracks = blacklistId.getTracklist();
await blacklistTracks.whenLoaded();
var hasher = {};
for (var i = 0; i < blacklistTracks.count; i++) {
blacklistTracks.locked(function () {
item = blacklistTracks.getValue(i);
})
if ( track.id === item.id ) {
return true;
}
}
return false;
}
window.actions.sendToBlacklist = {
icon: 'playlist',
title: _('Send Selection To Blacklist'),
execute: function () {
var blacklistId = undefined;
var createBlacklist = async function() {
ODS('RW: createBlacklist');
blacklistId = app.playlists.root.newPlaylist();
blacklistId.name = blacklistName;//'_Blacklist_';
blacklistId.isAutoPlaylist = false;
blacklistId.commitAsync().then(function () {
blacklistId.isNew = true;
});
return blacklistId;
};
var addToBlacklist = async function() {
blacklistId = await getBlacklist(app.playlists.root);
if ( blacklistId == undefined ) {
createBlacklist();
}
if ( blacklistId == undefined ) {
//Generate error message
return;
};
var list = await uitools.getSelectedTracklist().whenLoaded();
if (list.count === 0) {
return;
}
blacklistId.addTracksAsync(list);
}
addToBlacklist();
}
}
window.actions.sendTo.override({
submenu: async function($super, params) {
var result = await $super(params);
result.push({
action: actions.sendToBlacklist,
order: 50,
grouporder: 40,
});
return result;
}
});
[/code]
I can zip and upload the files if needed.