示例#1
0
        /// <summary>
        /// Plays all songs from the given folder, starting with item defined by startPos
        /// </summary>
        /// <param name="folder">Folder that is played</param>
        /// <param name="extensions">Valid extensions</param>
        /// <param name="startPos">Position from where playback is started (playlist index)</param>
        internal static void PlayAllFilesInFolder(string folder, string[] extensions, int startPos)
        {
            WifiRemote.LogMessage("Adding all files in " + folder + " to current playlist", WifiRemote.LogType.Debug);
            if (Directory.Exists(folder))
            {
                PlaylistHelper.ClearPlaylist("music", false);

                List <PlayListItem> items = new List <PlayListItem>();
                foreach (String f in Directory.GetFiles(folder))
                {
                    if (isValidExtension(f, extensions))
                    {
                        FileInfo fileInfo = new FileInfo(f);
                        items.Add(new PlayListItem(fileInfo.Name, fileInfo.FullName, 0));
                    }
                }
                PlaylistHelper.AddPlaylistItems(PlayListType.PLAYLIST_MUSIC, items, 0);

                PlaylistHelper.StartPlayingPlaylist("music", startPos, true);
            }
            else
            {
                WifiRemote.LogMessage("Folder " + folder + " doesn't exist", WifiRemote.LogType.Warn);
            }
        }
        /// <summary>
        /// Handle an MpExtended message received from a client
        /// </summary>
        /// <param name="message">Message</param>
        /// <param name="socketServer">Socket server</param>
        /// <param name="sender">Sender</param>
        internal static void HandleMpExtendedMessage(Newtonsoft.Json.Linq.JObject message, SocketServer socketServer, Deusty.Net.AsyncSocket sender)
        {
            string itemId     = (string)message["ItemId"];
            int    itemType   = (int)message["MediaType"];
            int    providerId = (int)message["ProviderId"];
            String action     = (String)message["Action"];
            Dictionary <string, string> values = JsonConvert.DeserializeObject <Dictionary <string, string> >(message["PlayInfo"].ToString());
            int startPos = (message["StartPosition"] != null) ? (int)message["StartPosition"] : 0;

            if (action != null)
            {
                if (action.Equals("play"))
                {
                    //play the item in MediaPortal
                    WifiRemote.LogMessage("play mediaitem: ItemId: " + itemId + ", itemType: " + itemType + ", providerId: " + providerId, WifiRemote.LogType.Debug);
                    MpExtendedHelper.PlayMediaItem(itemId, itemType, providerId, values, startPos);
                }
                else if (action.Equals("show"))
                {
                    //show the item details in mediaportal (without starting playback)
                    WifiRemote.LogMessage("show mediaitem: ItemId: " + itemId + ", itemType: " + itemType + ", providerId: " + providerId, WifiRemote.LogType.Debug);

                    MpExtendedHelper.ShowMediaItem(itemId, itemType, providerId, values);
                }
                else if (action.Equals("enqueue"))
                {
                    //enqueue the mpextended item to the currently active playlist
                    WifiRemote.LogMessage("enqueue mediaitem: ItemId: " + itemId + ", itemType: " + itemType + ", providerId: " + providerId, WifiRemote.LogType.Debug);

                    int startIndex = (message["StartIndex"] != null) ? (int)message["StartIndex"] : -1;

                    PlayListType        playlistType = PlayListType.PLAYLIST_VIDEO;
                    List <PlayListItem> items        = MpExtendedHelper.CreatePlayListItemItem(itemId, itemType, providerId, values, out playlistType);

                    PlaylistHelper.AddPlaylistItems(playlistType, items, startIndex);
                }
            }
            else
            {
                WifiRemote.LogMessage("No MpExtended action defined", WifiRemote.LogType.Warn);
            }
        }
示例#3
0
        /// <summary>
        /// Plays all songs from the given artist, starting with item defined by startPos
        /// </summary>
        /// <param name="albumArtist">Artist that is played</param>
        /// <param name="startPos">Position from where playback is started (playlist index)</param>
        internal static void PlayArtist(string albumArtist, int startPos)
        {
            List <Song> songs = new List <Song>();
            string      sql   = String.Format("select * from tracks where strAlbumArtist like '%{0}%'",
                                              DatabaseUtility.RemoveInvalidChars(albumArtist));

            MusicDatabase.Instance.GetSongsByFilter(sql, out songs, "tracks");

            if (songs.Count > 0)
            {
                PlaylistHelper.ClearPlaylist("music", false);
                List <PlayListItem> items = new List <PlayListItem>();
                foreach (Song s in songs)
                {
                    items.Add(PlaylistHelper.ToPlayListItem(s));
                }
                PlaylistHelper.AddPlaylistItems(PlayListType.PLAYLIST_MUSIC, items, 0);

                PlaylistHelper.StartPlayingPlaylist("music", startPos, true);
            }
        }