コード例 #1
0
        /// <summary>
        /// Add track to playlist.
        /// </summary>
        /// <param name="playlistId">
        /// ID of playlist (1 and 2 supported only).
        /// </param>
        /// <param name="trackId">
        /// Track ID of track to add.
        /// </param>
        /// <param name="allowTwice">
        /// True if track should be added although it's already in available in the playlist.
        /// </param>
        /// <returns>
        /// True if track successfully added to playlist.
        /// </returns>
        public static bool AddTrackToPlayList(int playlistId, int trackId, bool allowTwice)
        {
            if (!allowTwice)
            {
                TrackListModel m = (playlistId == 1 ? RemotePlaylist : PlayQueuePlaylist).TrackModel;

                for (int i = 0; i < m.Count; i++)
                {
                    object t = m.GetItem(i);

                    if (t is DatabaseTrackInfo && ((DatabaseTrackInfo)t).TrackId == trackId)
                    {
                        return(false);
                    }
                }
            }

            switch (playlistId)
            {
            case 1: {
                Selection          selection = null;
                MusicLibrarySource source    = MusicLibrary;

                for (int i = 0; i < source.TrackModel.Count; i++)
                {
                    object t = source.TrackModel.GetItem(i);

                    if (t is DatabaseTrackInfo && ((DatabaseTrackInfo)t).TrackId == trackId)
                    {
                        selection = new Hyena.Collections.Selection();
                        selection.Select(i);
                        break;
                    }
                }

                if (selection != null)
                {
                    RemotePlaylist.AddSelectedTracks(source, selection);
                    return(true);
                }

                break;
            }

            case 2: {
                DatabaseTrackInfo track = new DatabaseTrackModelProvider <DatabaseTrackInfo>(
                    ServiceManager.DbConnection).FetchSingle(trackId);

                if (track != null)
                {
                    PlayQueuePlaylist.EnqueueTrack(track, false);
                    return(true);
                }

                break;
            }
            }

            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Set track to play (immediately).
        /// </summary>
        /// <param name="playlistId">
        /// ID of playlsit in which the requested track is located (0 for no playlist).
        /// </param>
        /// <param name="trackId">
        /// ID of track in database.
        /// </param>
        /// <returns>
        /// Returns true if track is available and is plaing now.
        /// </returns>
        public static byte PlayTrack(int playlistId, long trackId)
        {
            if (trackId < 1)
            {
                return(0);
            }

            DatabaseTrackInfo track = new DatabaseTrackModelProvider <DatabaseTrackInfo>(
                ServiceManager.DbConnection).FetchSingle(trackId);

            if (track == null)
            {
                return(0);
            }

            Source         source          = Helper.GetPlaylistSource(playlistId);
            Source         requestedSource = source;
            TrackListModel model           = null;

            if (source == null)
            {
                source = MusicLibrary;
            }

            model = ((ITrackModelSource)source).TrackModel;

            if (model != null)
            {
                int i = 0;

                for (i = 0; i < model.Count; i++)
                {
                    TrackInfo t = (TrackInfo)model.GetItem(i);

                    if (t is DatabaseTrackInfo && ((DatabaseTrackInfo)t).TrackId == track.TrackId)
                    {
                        break;
                    }
                }

                if (i != model.Count)
                {
                    ServiceManager.PlaybackController.Source = (ITrackModelSource)source;
                    ServiceManager.PlayerEngine.OpenPlay((TrackInfo)model.GetItem(i));
                    _playTimeout = Timestamp();
                    return((byte)(source == requestedSource ? 2 : 1));
                }
            }

            ServiceManager.PlayerEngine.OpenPlay(track);
            _playTimeout = Timestamp();
            return(1);
        }