コード例 #1
0
        /// <summary>
        /// Handle an MPTvSeries 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 HandleTvSeriesMessage(Newtonsoft.Json.Linq.JObject message, SocketServer socketServer, Deusty.Net.AsyncSocket sender)
        {
            string action = (string)message["Action"];

            if (!string.IsNullOrEmpty(action))
            {
                // A series id is needed for the following actions.
                // If a series id was supplied we use this, otherwise we
                // try to get an id by the series name.
                //
                // If this isn't successful we do nothing.
                int?   seriesId   = (int?)message["SeriesId"];
                string seriesName = (string)message["SeriesName"];
                bool   resume     = (message["AskToResume"] != null) ? (bool)message["AskToResume"] : true;

                // Get series id by show name if no id supplied
                if (seriesId == null && !string.IsNullOrEmpty(seriesName))
                {
                    seriesId = TVSeriesHelper.GetSeriesIdByName(seriesName);
                }

                if (seriesId != null)
                {
                    // Play specific episode of series
                    if (action == "playepisode")
                    {
                        int?season   = (int?)message["SeasonNumber"];
                        int?episode  = (int?)message["EpisodeNumber"];
                        int startPos = (message["StartPosition"] != null) ? (int)message["StartPosition"] : 0;

                        if (season != null && episode != null)
                        {
                            TVSeriesHelper.Play((int)seriesId, (int)season, (int)episode, resume, startPos);
                        }
                    }
                    // Show movie details for this movie
                    else if (action == "seriesdetails")
                    {
                        TVSeriesHelper.ShowSeriesDetails((int)seriesId);
                    }
                    // Play first unwatched or last added episode of a series
                    else if (action == "playunwatchedepisode")
                    {
                        TVSeriesHelper.PlayFirstUnwatchedEpisode((int)seriesId, resume);
                    }
                    // Play random episode of a series
                    else if (action == "playrandomepisode")
                    {
                        TVSeriesHelper.PlayRandomEpisode((int)seriesId, resume);
                    }
                    // Play all episodes of a season
                    else if (action == "playseason")
                    {
                        int? season               = (int?)message["SeasonNumber"];
                        bool onlyUnwatched        = (message["OnlyUnwatchedEpisodes"] != null) ? (bool)message["OnlyUnwatchedEpisodes"] : false;
                        int  startIndex           = (message["StartIndex"] != null) ? (int)message["StartIndex"] : 0;
                        bool switchToPlaylistView = (message["SwitchToPlaylist"] != null) ? (bool)message["SwitchToPlaylist"] : true;
                        bool startAutomatically   = (message["AutoStart"] != null) ? (bool)message["AutoStart"] : true;
                        if (season != null)
                        {
                            TVSeriesHelper.PlaySeason((int)seriesId, (int)season, startAutomatically, startIndex, onlyUnwatched, switchToPlaylistView);
                        }
                    }
                    // Play all episodes of a series
                    else if (action == "playseries")
                    {
                        bool onlyUnwatched        = (message["OnlyUnwatchedEpisodes"] != null) ? (bool)message["OnlyUnwatchedEpisodes"] : false;
                        int  startIndex           = (message["StartIndex"] != null) ? (int)message["StartIndex"] : 0;
                        bool switchToPlaylistView = (message["SwitchToPlaylist"] != null) ? (bool)message["SwitchToPlaylist"] : true;
                        bool startAutomatically   = (message["AutoStart"] != null) ? (bool)message["AutoStart"] : true;

                        TVSeriesHelper.PlaySeries((int)seriesId, startAutomatically, startIndex, onlyUnwatched, switchToPlaylistView);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Play a media item described by its' MpExtended properties (item id/item type/provider id)
        /// </summary>
        /// <param name="itemId">MpExtended item id</param>
        /// <param name="mediaType">MpExtended media type</param>
        /// <param name="providerId">MpExtended provider id</param>
        /// <param name="playInfo">Additional information to playback the item</param>
        /// <param name="startPos">Start position in the video or playlist</param>
        public static void PlayMediaItem(string itemId, int mediaType, int providerId, Dictionary <string, string> playInfo, int startPos)
        {
            try
            {
                MpExtendedProviders  provider = (MpExtendedProviders)providerId;
                MpExtendedMediaTypes type     = (MpExtendedMediaTypes)mediaType;
                switch (provider)
                {
                case MpExtendedProviders.MovingPictures:
                    if (WifiRemote.IsAvailableMovingPictures)
                    {
                        MovingPicturesHelper.PlayMovie(Int32.Parse(playInfo["Id"]), false, startPos);
                    }
                    else
                    {
                        WifiRemote.LogMessage("MovingPictures not installed but required!", WifiRemote.LogType.Error);
                    }
                    break;

                case MpExtendedProviders.MPTvSeries:
                    if (WifiRemote.IsAvailableTVSeries)
                    {
                        if (type == MpExtendedMediaTypes.TVEpisode)
                        {
                            TVSeriesHelper.PlayEpisode(playInfo["Id"], false, startPos);
                        }
                        else if (type == MpExtendedMediaTypes.TVSeason)
                        {
                            TVSeriesHelper.PlaySeason(Int32.Parse(playInfo["ShowId"]), Int32.Parse(playInfo["SeasonIndex"]), true, startPos, false, true);
                        }
                        else if (type == MpExtendedMediaTypes.TVShow)
                        {
                            TVSeriesHelper.PlaySeries(Int32.Parse(playInfo["Id"]), true, startPos, false, true);
                        }
                    }
                    else
                    {
                        WifiRemote.LogMessage("MP-TvSeries not installed but required!", WifiRemote.LogType.Error);
                    }
                    break;

                case MpExtendedProviders.MPMusic:
                    if (type == MpExtendedMediaTypes.MusicTrack)
                    {
                        MpMusicHelper.PlayMusicTrack(Int32.Parse(playInfo["Id"]), startPos);
                    }
                    else if (type == MpExtendedMediaTypes.MusicAlbum)
                    {
                        MpMusicHelper.PlayAlbum(playInfo["Artist"], playInfo["Album"], startPos);
                    }
                    else if (type == MpExtendedMediaTypes.MusicArtist)
                    {
                        MpMusicHelper.PlayArtist(playInfo["Artist"], startPos);
                    }
                    break;

                case MpExtendedProviders.MPVideo:
                    MpVideosHelper.PlayVideo(Int32.Parse(playInfo["Id"]), startPos);
                    break;

                case MpExtendedProviders.MpVideosShare:
                    if (type == MpExtendedMediaTypes.File)
                    {
                        //TODO: fill myvideos db information instead of just playing the file

                        MpVideosHelper.PlayVideoFromFile(playInfo["Path"], startPos);
                    }
                    else if (type == MpExtendedMediaTypes.Folder)
                    {
                        string[] extensions = playInfo["Extensions"].Split('|');
                        MpVideosHelper.PlayFolder(playInfo["Path"], extensions, startPos);
                    }
                    break;

                case MpExtendedProviders.MpMusicShare:
                    if (type == MpExtendedMediaTypes.File)
                    {
                        MpMusicHelper.PlayFile(playInfo["Path"], startPos);
                    }
                    else if (type == MpExtendedMediaTypes.Folder)
                    {
                        string[] extensions = playInfo["Extensions"].Split('|');
                        MpMusicHelper.PlayAllFilesInFolder(playInfo["Path"], extensions, startPos);
                    }
                    break;

                default:
                    //we have no providers (yet) for tv
                    if (type == MpExtendedMediaTypes.Recording)
                    {
                        if (!WifiRemote.IsAvailableTVPlugin)
                        {
                            WifiRemote.LogMessage("No TVPlugin installed: Aborting playrecording", WifiRemote.LogType.Error);
                            return;
                        }

                        MpTvServerHelper.PlayRecording(Int32.Parse(playInfo["Id"]), startPos, true);
                    }
                    else if (type == MpExtendedMediaTypes.Tv)
                    {
                        if (!WifiRemote.IsAvailableTVPlugin)
                        {
                            WifiRemote.LogMessage("No TVPlugin installed: Aborting playchannel", WifiRemote.LogType.Error);
                            return;
                        }

                        MpTvServerHelper.PlayTvChannel(Int32.Parse(playInfo["Id"]), true);
                    }
                    else
                    {
                        WifiRemote.LogMessage("Provider not implemented yet", WifiRemote.LogType.Warn);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                WifiRemote.LogMessage("Error during creation of PlayListItem: " + ex.ToString(), WifiRemote.LogType.Error);
            }
        }