Ejemplo n.º 1
0
        private void OnAudioResourceUpdated(object sender, AudioResourceUpdatedEventArgs e)
        {
            lock (Lock) {
                if (sender == null || !ReferenceEquals(sender, Current))
                {
                    return;
                }

                Log.Info("AudioResource was changed by loader, saving containing playlist");

                var modifyR = playlistManager.ModifyPlaylist(e.QueueItem.MetaData.ContainingPlaylistId, (list, _) => {
                    foreach (var item in list.Items)
                    {
                        if (ReferenceEquals(item.AudioResource, e.QueueItem.AudioResource))
                        {
                            item.AudioResource = e.Resource;
                        }
                    }
                });
                if (!modifyR.Ok)
                {
                    Log.Warn($"Failed to save playlist {e.QueueItem.MetaData.ContainingPlaylistId}: {modifyR.Error}");
                }
            }
        }
Ejemplo n.º 2
0
        private void OnAudioResourceUpdated(object sender, AudioResourceUpdatedEventArgs e)
        {
            if (e.QueueItem.MetaData.ContainingPlaylistId == null)
            {
                return;
            }

            lock (Lock) {
                Log.Info("AudioResource was changed by loader, saving containing playlist");

                E <LocalStr> modifyR;
                lock (playlistManager.Lock) {
                    var listId      = e.QueueItem.MetaData.ContainingPlaylistId;
                    var newResource = e.Resource;
                    var oldResource = e.QueueItem.AudioResource;
                    if (playlistManager.TryGetIndexOf(listId, oldResource, out var index))
                    {
                        modifyR = playlistManager.ChangeItemAtDeep(listId, index, newResource);
                    }
                    else
                    {
                        Log.Error($"Could not find resource {e.Resource} in playlist {listId}");
                        modifyR = new LocalStr("See above");
                    }
                }
                if (!modifyR.Ok)
                {
                    Log.Warn($"Failed to save playlist {e.QueueItem.MetaData.ContainingPlaylistId}: {modifyR.Error}");
                }
            }
        }