Beispiel #1
0
 private static void WaitForIsLoaded(IPlaylistContainer playlistContainer, CancellationToken cancellationToken)
 {
     while (!playlistContainer.IsLoaded() || cancellationToken.IsCancellationRequested)
     {
         Task.Delay(250, cancellationToken);
     }
 }
Beispiel #2
0
 void pc_PlaylistMoved(IPlaylistContainer pc, PlaylistMovedEventArgs args)
 {
     if (PlaylistMoved != null)
     {
         PlaylistMoved(this, null);
     }
 }
        internal static IContainerPlaylist Get(
            ISession session,
            IPlaylistContainer container,
            IntPtr handle,
            IntPtr folderId,
            PlaylistType playlistType)
        {
            KeyGen key = new KeyGen(handle, folderId, playlistType);

            lock (_instanceLock)
            {
                NativeContainerPlaylist instance;

                if (!_instances.TryGetValue(key, out instance))
                {
                    instance = new NativeContainerPlaylist(session, handle, folderId, playlistType, container);
                    instance.Initialize();

                    if (SessionFactory.IsInternalCachingEnabled)
                    {
                        _instances.Add(key, instance);
                    }
                }

                return(instance);
            }
        }
 public NativeContainerPlaylist(ISession session, IntPtr handle, IntPtr folderId, PlaylistType type, IPlaylistContainer container)
     : base(session, handle)
 {
     _folderId  = folderId;
     _type      = type;
     _container = container;
 }
 public NativeContainerPlaylist(ISession session, IntPtr handle, IntPtr folderId, PlaylistType type, IPlaylistContainer container)
     : base(session, handle)
 {
     _folderId = folderId;
     _type = type;
     _container = container;
 }
Beispiel #6
0
 void pc_Loaded(IPlaylistContainer pc, EventArgs args)
 {
     if (Loaded != null)
     {
         Loaded(this, args);
     }
 }
        /// <summary>
        /// Gets the full path to the given playlist item.
        /// </summary>
        /// <param name="item">The item to get the path of.</param>
        /// <returns>The full path to the item.</returns>
        public static string GetFullPath(this IPlaylistItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var path = item.Path;
            IPlaylistContainer parent = item.Parent;

            while (parent != null)
            {
                if (Path.IsPathRooted(path))
                {
                    break;
                }
                path   = Path.Combine(parent.IncludesFilename ? Path.GetDirectoryName(parent.Path) : parent.Path, path);
                parent = parent.Parent;
            }

            // when used, the playlist items must be rooted *somewhere*
            // otherwise the files they correspond to cannot be located
            if (!Path.IsPathRooted(path))
            {
                throw new InvalidOperationException("The full path couldn't be retrieved. The root playlist must always have a rooted path.");
            }

            return(Path.GetFullPath(path));
        }
        private void OnSearchTextChanged()
        {
            searchTaskCancellationTokenSource?.Cancel();
            var txt = SearchText;

            if (string.IsNullOrWhiteSpace(txt))
            {
                FilteredSongsLoader.Items = Enumerable.Empty <FullSongInfo>();
                return;
            }

            searchTaskCancellationTokenSource = new CancellationTokenSource();
            searchTask = Task.Run(async() =>
            {
                searchPlaylist = await database.Search(txt, searchTaskCancellationTokenSource.Token);
                return(await Map(searchPlaylist.Playlist.Songs));
            })
                         .ContinueWith(
                task => dispatcher.Invoke(() =>
            {
                FilteredSongsLoader.Items = task.Result;
                LoadPlaylistCommand.Refresh();
            }),
                searchTaskCancellationTokenSource.Token,
                TaskContinuationOptions.OnlyOnRanToCompletion,
                TaskScheduler.Default);

            this.InvokePropertyChanged(PropertyChanged, nameof(IsLoading));
            searchTask.ContinueWith(_ => dispatcher.Invoke(() => this.InvokePropertyChanged(PropertyChanged, nameof(IsLoading))));
        }
Beispiel #9
0
 void pc_PlaylistAdded(IPlaylistContainer pc, PlaylistEventArgs args)
 {
     if (PlaylistAdded != null)
     {
         PlaylistAdded(this, args);
     }
 }
Beispiel #10
0
 internal static IntPtr GetPointer(IPlaylistContainer pc)
 {
     if (pc.GetType() == typeof(PlaylistContainerWrapper))
     {
         return(((PlaylistContainerWrapper)pc).pc.pcPtr);
     }
     throw new ArgumentException("Invalid pc");
 }
Beispiel #11
0
        internal void OnLoginComplete(SessionEventArgs e)
        {
            if (e.Status == Error.OK)
            {
                _playlistContainer = PlaylistContainerManager.Get(this, Spotify.sp_session_playlistcontainer(Handle));
            }

            LoginComplete.RaiseEvent(this, e);
        }
        public static bool WaitUntilLoaded(this IPlaylistContainer source, int millisecondsTimeout = 10000)
        {
            var          reset   = new ManualResetEvent(source.IsLoaded);
            EventHandler handler = (s, e) => reset.Set();

            source.Loaded += handler;
            bool result = reset.WaitOne(millisecondsTimeout);

            source.Loaded -= handler;
            return(result);
        }
Beispiel #13
0
        public BasePlaylistContainerViewModel(IPlaylistContainer innerContainer)
        {
            InnerContainer = innerContainer;
            foreach (var item in InnerContainer)
            {
                switch (item)
                {
                case Track track:
                    Items.Add(new TrackViewModel(track));
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
        }
Beispiel #14
0
        private static async Task <IPlaylist> FindPlaylistByName(IPlaylistContainer playlistContainer, string playlistName)
        {
            for (var i = 0; i < playlistContainer.NumPlaylists(); i++)
            {
                if (playlistContainer.PlaylistType(i) != PlaylistType.Playlist)
                {
                    continue;
                }

                var playlist = playlistContainer.Playlist(i);

                await playlist.Load();

                if (playlist.Name() == playlistName)
                {
                    return(playlist);
                }
            }

            return(null);
        }
Beispiel #15
0
 public static async Task Load(this IPlaylistContainer playlistContainer, CancellationToken cancellationToken)
 {
     await Task.Run(() => WaitForIsLoaded(playlistContainer, cancellationToken), cancellationToken);
 }
Beispiel #16
0
 public static async Task Load(this IPlaylistContainer playlistContainer)
 {
     await Load(playlistContainer, CancellationToken.None);
 }
 public static async Task Write(string filePath, IPlaylistContainer playlistContainer, IProgress <(double?, string)> progress)
Beispiel #18
0
 public static PlaylistContainerAssertions Should(this IPlaylistContainer actualValue) => new PlaylistContainerAssertions(actualValue);
Beispiel #19
0
        internal void OnLoginComplete(SessionEventArgs e)
        {
            if (e.Status == Error.OK)
            {
                _playlistContainer = PlaylistContainerManager.Get(this, Spotify.sp_session_playlistcontainer(Handle));
            }

            LoginComplete.RaiseEvent(this, e);
        }