コード例 #1
0
 private static void WaitForIsLoaded(IPlaylistContainer playlistContainer, CancellationToken cancellationToken)
 {
     while (!playlistContainer.IsLoaded() || cancellationToken.IsCancellationRequested)
     {
         Task.Delay(250, cancellationToken);
     }
 }
コード例 #2
0
ファイル: PlaylistContainer.cs プロジェクト: shbmira/PlayMe
 void pc_PlaylistMoved(IPlaylistContainer pc, PlaylistMovedEventArgs args)
 {
     if (PlaylistMoved != null)
     {
         PlaylistMoved(this, null);
     }
 }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
 public NativeContainerPlaylist(ISession session, IntPtr handle, IntPtr folderId, PlaylistType type, IPlaylistContainer container)
     : base(session, handle)
 {
     _folderId  = folderId;
     _type      = type;
     _container = container;
 }
コード例 #5
0
 public NativeContainerPlaylist(ISession session, IntPtr handle, IntPtr folderId, PlaylistType type, IPlaylistContainer container)
     : base(session, handle)
 {
     _folderId = folderId;
     _type = type;
     _container = container;
 }
コード例 #6
0
ファイル: PlaylistContainer.cs プロジェクト: shbmira/PlayMe
 void pc_Loaded(IPlaylistContainer pc, EventArgs args)
 {
     if (Loaded != null)
     {
         Loaded(this, args);
     }
 }
コード例 #7
0
        /// <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));
        }
コード例 #8
0
        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))));
        }
コード例 #9
0
ファイル: PlaylistContainer.cs プロジェクト: shbmira/PlayMe
 void pc_PlaylistAdded(IPlaylistContainer pc, PlaylistEventArgs args)
 {
     if (PlaylistAdded != null)
     {
         PlaylistAdded(this, args);
     }
 }
コード例 #10
0
ファイル: PlaylistContainer.cs プロジェクト: shbmira/PlayMe
 internal static IntPtr GetPointer(IPlaylistContainer pc)
 {
     if (pc.GetType() == typeof(PlaylistContainerWrapper))
     {
         return(((PlaylistContainerWrapper)pc).pc.pcPtr);
     }
     throw new ArgumentException("Invalid pc");
 }
コード例 #11
0
ファイル: NativeSession.cs プロジェクト: Dkrinker/torshify
        internal void OnLoginComplete(SessionEventArgs e)
        {
            if (e.Status == Error.OK)
            {
                _playlistContainer = PlaylistContainerManager.Get(this, Spotify.sp_session_playlistcontainer(Handle));
            }

            LoginComplete.RaiseEvent(this, e);
        }
コード例 #12
0
        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);
        }
コード例 #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();
                }
            }
        }
コード例 #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);
        }
コード例 #15
0
 public static async Task Load(this IPlaylistContainer playlistContainer, CancellationToken cancellationToken)
 {
     await Task.Run(() => WaitForIsLoaded(playlistContainer, cancellationToken), cancellationToken);
 }
コード例 #16
0
 public static async Task Load(this IPlaylistContainer playlistContainer)
 {
     await Load(playlistContainer, CancellationToken.None);
 }
コード例 #17
0
 public static async Task Write(string filePath, IPlaylistContainer playlistContainer, IProgress <(double?, string)> progress)
コード例 #18
0
 public static PlaylistContainerAssertions Should(this IPlaylistContainer actualValue) => new PlaylistContainerAssertions(actualValue);
コード例 #19
0
ファイル: NativeSession.cs プロジェクト: sekotin/torshify
        internal void OnLoginComplete(SessionEventArgs e)
        {
            if (e.Status == Error.OK)
            {
                _playlistContainer = PlaylistContainerManager.Get(this, Spotify.sp_session_playlistcontainer(Handle));
            }

            LoginComplete.RaiseEvent(this, e);
        }