/// <summary> /// Get items from the list control /// </summary> /// <param name="list">list control</param> private void GetItemsFromListControl(GUIListControl list) { //make sure the list isn't in the progress of being filled (list count growing) int itemCount = 0; for (int i = 0; i < 20; i++) { Thread.Sleep(200); if (list.Count > 0 && list.Count == itemCount) { break; } itemCount = list.Count; } WifiRemote.LogMessage("Retrieving " + itemCount + " dialog list items: ", WifiRemote.LogType.Debug); List <GUIListItem> items = list.ListItems; for (int i = 0; i < itemCount; i++) { FacadeItem item = new FacadeItem(list[i]); //WifiRemote.LogMessage("Add dialog list items: " + item.Label, WifiRemote.LogType.Debug); ListItems.Add(item); } }
/// <summary> /// Gets the text from the given control id on the dialog and returns it /// </summary> /// <param name="dialog">MP Dialog</param> /// <param name="controlId">ID of the label</param> /// <returns></returns> public String GetLabel(GUIDialogWindow dialog, params int[] controlIds) { try { int index = 0; StringBuilder text = new StringBuilder(); foreach (int control in controlIds) { String t = GetSingleLabel(dialog, control); if (t != null && !t.Equals("")) { if (index > 0) { text.AppendLine(); } index++; text.Append(t); } } return(text.ToString()); } catch (Exception ex) { WifiRemote.LogMessage("Error filling dialog: " + ex, WifiRemote.LogType.Error); } return(null); }
/// <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> /// Create playlist item from a file /// </summary> /// <param name="file">Path to file</param> /// <returns>Playlist item</returns> internal static MediaPortal.Playlists.PlayListItem CreatePlaylistItemFromMusicFile(string file) { FileInfo info = null; MediaPortal.Playlists.PlayListItem item = new MediaPortal.Playlists.PlayListItem(); try { info = new FileInfo(file); } catch (Exception e) { WifiRemote.LogMessage("Error loading music item from file: " + e.Message, WifiRemote.LogType.Error); } if (info != null) { item.Description = info.Name; item.FileName = info.FullName; item.Type = PlayListItem.PlayListItemType.Audio; MusicDatabase mpMusicDb = MusicDatabase.Instance; Song song = new Song(); bool inDb = mpMusicDb.GetSongByFileName(item.FileName, ref song); if (inDb) { item.Duration = song.Duration; } } return(item); }
/// <summary> /// Save the current playlist to file /// </summary> /// <param name="name">Name of new playlist</param> internal static void SaveCurrentPlaylist(string name) { try { using (MediaPortal.Profile.Settings reader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) { string playlistFolder = reader.GetValueAsString("music", "playlists", ""); if (!Path.IsPathRooted(playlistFolder)) { playlistFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), playlistFolder); } PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; PlayList playList = playListPlayer.GetPlaylist(playListPlayer.CurrentPlaylistType); String fileName = Path.Combine(playlistFolder, name + ".m3u"); PlayListM3uIO m3uPlayList = new PlayListM3uIO(); m3uPlayList.Save(playList, fileName); } } catch (Exception ex) { WifiRemote.LogMessage("Error saving playlist: " + ex.ToString(), WifiRemote.LogType.Warn); } }
/// <summary> /// Create playlist item from a folder /// </summary> /// <param name="folder">Path to folder</param> /// <returns>Playlist item</returns> internal static List <MediaPortal.Playlists.PlayListItem> CreatePlaylistItemFromMusicFolder(string folder, string[] extensions) { FileInfo[] files = null; List <MediaPortal.Playlists.PlayListItem> returnList = new List <MediaPortal.Playlists.PlayListItem>(); try { DirectoryInfo info = new DirectoryInfo(folder); files = info.GetFiles(); } catch (Exception e) { WifiRemote.LogMessage("Error fetching music files from folder: " + e.Message, WifiRemote.LogType.Error); } if (files != null) { foreach (FileInfo f in files) { if (IsValidExtension(f.FullName, extensions)) { returnList.Add(CreatePlaylistItemFromMusicFile(f.FullName)); } } } return(returnList); }
internal static void PlayFolder(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("video", false); int index = 0; foreach (String f in Directory.GetFiles(folder)) { if (IsValidExtension(f, extensions)) { PlaylistHelper.AddItemToPlaylist("video", f, index, false); index++; } } PlaylistHelper.RefreshPlaylistIfVisible(); PlaylistHelper.StartPlayingPlaylist("video", startPos, true); } else { WifiRemote.LogMessage("Folder " + folder + " doesn't exist", WifiRemote.LogType.Warn); } }
/// <summary> /// Plays a MpVideos movie /// </summary> /// <param name="id"></param> /// <param name="startPos"></param> internal static void PlayVideo(int id, int startPos) { //Code mostly copied from WindowPlugins -> GUIVideoFiles -> GuiVideoTitle.cs IMDBMovie movie = new IMDBMovie(); VideoDatabase.GetMovieInfoById(id, ref movie); if (movie == null && movie.ID < 0) { WifiRemote.LogMessage("No video found for id " + id, WifiRemote.LogType.Warn); return; } GUIVideoFiles.Reset(); // reset pincode ArrayList files = new ArrayList(); //Code for MediaPortal 1.3 Beta and higher VideoDatabase.GetFilesForMovie(movie.ID, ref files); if (files.Count > 1) { GUIVideoFiles.StackedMovieFiles = files; GUIVideoFiles.IsStacked = true; } else { GUIVideoFiles.IsStacked = false; } GUIVideoFiles.MovieDuration(files, false); GUIVideoFiles.PlayMovie(movie.ID, false); }
/// <summary> /// Handle a "showdialog" 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 HandleShowDialogMessage(Newtonsoft.Json.Linq.JObject message, SocketServer socketServer, Deusty.Net.AsyncSocket sender) { String dialogType = (String)message["DialogType"]; String dialogId = (String)message["DialogId"]; if (dialogType != null) { String title = (String)message["Title"]; String text = (String)message["Text"]; if (dialogType.Equals("yesno")) { //show dialog in new thread so we don't block the tcp thread new Thread(new ParameterizedThreadStart(ShowYesNoThreaded)).Start(new object[] { dialogId, title, text, socketServer, sender }); } else if (dialogType.Equals("ok")) { new Thread(new ParameterizedThreadStart(ShowOkDialogThreaded)).Start(new object[] { title, text }); } else if (dialogType.Equals("yesnoselect")) { List <String> options = new List <String>(); JArray array = (JArray)message["Options"]; if (array != null) { foreach (JValue v in array) { options.Add((string)v.Value); } } //show dialog in new thread so we don't block the tcp thread new Thread(new ParameterizedThreadStart(ShowYesNoThenSelectThreaded)).Start(new object[] { dialogId, title, text, options, socketServer, sender }); } else if (dialogType.Equals("select")) { List <String> options = new List <String>(); JArray array = (JArray)message["Options"]; if (array != null) { foreach (JValue v in array) { options.Add((string)v.Value); } } //show dialog in new thread so we don't block the tcp thread new Thread(new ParameterizedThreadStart(ShowSelectThreaded)).Start(new object[] { dialogId, title, options, socketServer, sender }); } else { WifiRemote.LogMessage("Dialog type " + dialogType + " not supported yet", WifiRemote.LogType.Warn); } } else { WifiRemote.LogMessage("No dialog type specified", WifiRemote.LogType.Warn); } }
/// <summary> /// Retrieves the name of the playlist /// </summary> /// <param name="type">Type of the playlist</param> public static String GetPlaylistName(String type) { PlayListType plType = GetTypeFromString(type); PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; PlayList playList = playListPlayer.GetPlaylist(plType); WifiRemote.LogMessage("Playlist name test:" + playList.Name, WifiRemote.LogType.Debug); return(playList.Name); }
/// <summary> /// Play video given a file path /// </summary> /// <param name="file">File to video</param> /// <param name="startPos">Start position of video</param> internal static void PlayVideoFromFile(String file, int startPos) { if (File.Exists(file)) { new Communication().PlayVideoFile(file, startPos, "video"); } else { WifiRemote.LogMessage("File " + file + " doesn't exist", WifiRemote.LogType.Warn); } }
/// <summary> /// Set repeat if type is of the current playlist type /// </summary> /// <param name="type">Type of the playlist</param> public static void Repeat(string type, bool repeat) { WifiRemote.LogMessage("Set playlist repeat:" + repeat, WifiRemote.LogType.Debug); PlayListType plType = GetTypeFromString(type); WifiRemote.LogMessage("plType:" + plType, WifiRemote.LogType.Debug); WifiRemote.LogMessage("currentType:" + PlayListPlayer.SingletonPlayer.CurrentPlaylistType, WifiRemote.LogType.Debug); if (plType == PlayListPlayer.SingletonPlayer.CurrentPlaylistType) { PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; playListPlayer.RepeatPlaylist = repeat; RefreshPlaylistIfVisible(); } }
/// <summary> /// Update the facade infor with the current values /// </summary> private void UpdateFacadeInfo() { try { GUIWindow currentPlugin = GUIWindowManager.GetWindow(GUIWindowManager.ActiveWindow); Object o = currentPlugin.GetControl(50); if (o != null) { if (o.GetType() == typeof(GUIFacadeControl)) { GUIFacadeControl facade = (GUIFacadeControl)o; SelectedIndex = facade.SelectedListItemIndex; Visible = facade.VisibleFromSkinCondition; Count = facade.Count; ViewType = facade.CurrentLayout.ToString(); } else if (o.GetType() == typeof(GUIMenuControl)) { //TODO: also support home menu GUIMenuControl menu = (GUIMenuControl)o; SelectedIndex = menu.FocusedButton; Visible = false; Count = menu.ButtonInfos.Count; ViewType = "menu"; } else { SelectedIndex = 0; Visible = false; Count = 0; ViewType = null; } } else { SelectedIndex = 0; Visible = false; Count = 0; ViewType = null; } } catch (Exception ex) { WifiRemote.LogMessage("Error on updating facade info: " + ex.ToString(), WifiRemote.LogType.Error); } }
/// <summary> /// Plays a recording from mp tvserver /// </summary> /// <param name="id">Id of recording</param> /// <param name="startPos">Start postion</param> /// <param name="startFullscreen">If true, will switch to fullscreen after playback is started</param> public static void PlayRecording(int recordingId, int startPos, bool startFullscreen) { if (GUIGraphicsContext.form.InvokeRequired) { PlayRecordingDelegate d = PlayRecording; GUIGraphicsContext.form.Invoke(d, recordingId, startPos, startFullscreen); return; } TvDatabase.Recording rec = TvDatabase.Recording.Retrieve(recordingId); bool success = TvPlugin.TVUtil.PlayRecording(rec, startPos); if (startFullscreen && success) { WifiRemote.LogMessage("Switching to fullscreen", WifiRemote.LogType.Debug); g_Player.ShowFullScreenWindowTV(); } }
/// <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); } }
/// <summary> /// Changes the position of an item in the playlist /// </summary> /// <param name="type">Type of the playlist</param> /// <param name="oldIndex">Current position of item</param> /// <param name="newIndex">Target position of item</param> public static void ChangePlaylistItemPosition(String type, int oldIndex, int newIndex) { PlayListType plType = GetTypeFromString(type); PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; PlayList playList = playListPlayer.GetPlaylist(plType); if (oldIndex >= 0 && newIndex >= 0 && playList.Count > oldIndex && playList.Count > newIndex) { WifiRemote.LogMessage("Change playlist index " + oldIndex + " to " + newIndex, WifiRemote.LogType.Debug); PlayListItem item = playList[oldIndex]; playList.Remove(item.FileName); //Note: we need -1 here, because Insert wants the item after which the song should be inserted, not the actual index playList.Insert(item, newIndex - 1); RefreshPlaylistIfVisible(); } else { WifiRemote.LogMessage("Index for changing playlistPosition invalid (old: " + oldIndex + ", new: " + newIndex + ")", WifiRemote.LogType.Warn); } }
/// <summary> /// Play a tv channel /// </summary> /// <param name="channelId">Id of the channel</param> /// <param name="startFullscreen">If true, will switch to fullscreen after playback is started</param> public static void PlayTvChannel(int channelId, bool startFullscreen) { if (GUIGraphicsContext.form.InvokeRequired) { PlayTvChannelDelegate d = PlayTvChannel; GUIGraphicsContext.form.Invoke(d, channelId, startFullscreen); return; } if (g_Player.Playing && !g_Player.IsTimeShifting) { WifiRemote.LogMessage("Stopping current media so we can start playing tv", WifiRemote.LogType.Debug); g_Player.Stop(); } //the tv window isn't active and we're not playing tv fullscreen //if (GUIWindowManager.ActiveWindow != (int)MediaPortal.GUI.Library.GUIWindow.Window.WINDOW_TV && if (!g_Player.Playing) { WifiRemote.LogMessage("Tv Window not active, activating it", WifiRemote.LogType.Debug); MediaPortal.GUI.Library.GUIWindowManager.ActivateWindow((int)MediaPortal.GUI.Library.GUIWindow.Window.WINDOW_TV); } WifiRemote.LogMessage("Start channel " + channelId, WifiRemote.LogType.Debug); TvDatabase.Channel channel = TvDatabase.Channel.Retrieve(channelId); if (channel != null) { bool success = TvPlugin.TVHome.ViewChannelAndCheck(channel); WifiRemote.LogMessage("Started channel " + channelId + " Success: " + success, WifiRemote.LogType.Info); if (startFullscreen && success) { WifiRemote.LogMessage("Switching to fullscreen", WifiRemote.LogType.Debug); g_Player.ShowFullScreenWindowTV(); } } else { Log.Warn("Couldn't retrieve channel for id: " + channelId); } }
internal static void ShowMusicTrackDetails(int _trackId) { WifiRemote.LogMessage("Not implemented yet for mp music", WifiRemote.LogType.Info); }
/// <summary> /// Show details of folder /// </summary> /// <param name="folder"></param> internal static void ShowFolderDetails(string folder) { WifiRemote.LogMessage("Not implemented yet for mp video", WifiRemote.LogType.Info); }
/// <summary> /// Show details of a video /// </summary> /// <param name="videoId">Id of video</param> internal static void ShowVideoDetails(int videoId) { WifiRemote.LogMessage("Not implemented yet for mp video", WifiRemote.LogType.Info); }
/// <summary> /// Play a radio channel /// </summary> /// <param name="channelId">Id of the channel</param> public static void PlayRadioChannel(int channelId) { if (GUIGraphicsContext.form.InvokeRequired) { PlayRadioChannelDelegate d = PlayRadioChannel; GUIGraphicsContext.form.Invoke(d, channelId); return; } WifiRemote.LogMessage("Start radio channel " + channelId, WifiRemote.LogType.Debug); TvDatabase.Channel channel = TvDatabase.Channel.Retrieve(channelId); if (channel != null) { if (GUIWindowManager.ActiveWindow != (int)MediaPortal.GUI.Library.GUIWindow.Window.WINDOW_RADIO) { WifiRemote.LogMessage("Radio Window not active, activating it", WifiRemote.LogType.Debug); MediaPortal.GUI.Library.GUIWindowManager.ActivateWindow((int)MediaPortal.GUI.Library.GUIWindow.Window.WINDOW_RADIO); } GUIPropertyManager.RemovePlayerProperties(); GUIPropertyManager.SetProperty("#Play.Current.ArtistThumb", channel.DisplayName); GUIPropertyManager.SetProperty("#Play.Current.Album", channel.DisplayName); GUIPropertyManager.SetProperty("#Play.Current.Title", channel.DisplayName); GUIPropertyManager.SetProperty("#Play.Current.Title", channel.DisplayName); string strLogo = Utils.GetCoverArt(Thumbs.Radio, channel.DisplayName); if (string.IsNullOrEmpty(strLogo)) { strLogo = "defaultMyRadioBig.png"; } GUIPropertyManager.SetProperty("#Play.Current.Thumb", strLogo); if (g_Player.Playing && !channel.IsWebstream()) { if (!g_Player.IsTimeShifting || (g_Player.IsTimeShifting && channel.IsWebstream())) { WifiRemote.LogMessage("Stopping current media so we can start playing radio", WifiRemote.LogType.Debug); g_Player.Stop(); } } bool success = false; if (channel.IsWebstream()) { IList <TuningDetail> details = channel.ReferringTuningDetail(); TuningDetail detail = details[0]; WifiRemote.LogMessage("Play webStream:" + detail.Name + ", url:" + detail.Url, WifiRemote.LogType.Debug); success = g_Player.PlayAudioStream(detail.Url); GUIPropertyManager.SetProperty("#Play.Current.Title", channel.DisplayName); } else { // TV card radio channel WifiRemote.LogMessage("Play TV card radio channel", WifiRemote.LogType.Debug); //Check if same channel is alrady playing if (g_Player.IsRadio && g_Player.Playing) { Channel currentlyPlaying = TvPlugin.TVHome.Navigator.Channel; if (currentlyPlaying != null && currentlyPlaying.IdChannel == channel.IdChannel) { WifiRemote.LogMessage("Already playing TV card radio channel with id:" + channel.IdChannel + ", do not tune again", WifiRemote.LogType.Debug); } else { success = TvPlugin.TVHome.ViewChannelAndCheck(channel); } } else { success = TvPlugin.TVHome.ViewChannelAndCheck(channel); } } WifiRemote.LogMessage("Started radio channel " + channelId + " Success: " + success, WifiRemote.LogType.Debug); } else { Log.Warn("Couldn't retrieve radio channel for id: " + channelId); } }
/// <summary> /// Create a playlist item from a MP recording /// </summary> /// <param name="recordingId">Id of recording</param> /// <returns>Playlist item</returns> internal static MediaPortal.Playlists.PlayListItem CreatePlaylistItemFromRecording(int recordingId) { WifiRemote.LogMessage("Not implemented yet for mp tv recordings", WifiRemote.LogType.Info); return(null); }
/// <summary> /// Show the details page of a tv channel /// </summary> /// <param name="tvChannelId">Id of channel</param> internal static void ShowTvChannelDetails(int tvChannelId) { WifiRemote.LogMessage("Not implemented yet for mp tv channels", WifiRemote.LogType.Info); }
/// <summary> /// Show the details of a tv recording in MediaPortal /// </summary> /// <param name="recordingId">Id of recording</param> internal static void ShowRecordingDetails(int recordingId) { WifiRemote.LogMessage("Not implemented yet for mp recording", WifiRemote.LogType.Info); }
/// <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> public static List <PlayListItem> CreatePlayListItemItem(string itemId, int mediaType, int providerId, Dictionary <string, string> playInfo, out PlayListType playlistType) { playlistType = PlayListType.PLAYLIST_VIDEO;//default to video try { List <PlayListItem> items = new List <PlayListItem>(); MpExtendedProviders provider = (MpExtendedProviders)providerId; MpExtendedMediaTypes type = (MpExtendedMediaTypes)mediaType; switch (provider) { case MpExtendedProviders.MovingPictures: if (WifiRemote.IsAvailableMovingPictures) { playlistType = PlayListType.PLAYLIST_VIDEO; items.Add(MovingPicturesHelper.CreatePlaylistItem(Int32.Parse(playInfo["Id"]))); } else { WifiRemote.LogMessage("MovingPictures not installed but required!", WifiRemote.LogType.Error); } break; case MpExtendedProviders.MPTvSeries: if (WifiRemote.IsAvailableTVSeries) { playlistType = PlayListType.PLAYLIST_VIDEO; if (type == MpExtendedMediaTypes.TVEpisode) { items.Add(TVSeriesHelper.CreatePlaylistItemFromEpisode(playInfo["Id"])); } else if (type == MpExtendedMediaTypes.TVSeason) { items = TVSeriesHelper.CreatePlaylistItemsFromSeason(Int32.Parse(playInfo["ShowId"]), Int32.Parse(playInfo["SeasonIndex"])); } else if (type == MpExtendedMediaTypes.TVShow) { items = TVSeriesHelper.CreatePlaylistItemsFromShow(Int32.Parse(playInfo["Id"])); } } else { WifiRemote.LogMessage("MP-TvSeries not installed but required!", WifiRemote.LogType.Error); } break; case MpExtendedProviders.MPMusic: playlistType = PlayListType.PLAYLIST_MUSIC; if (type == MpExtendedMediaTypes.MusicTrack) { items.Add(MpMusicHelper.CreatePlaylistItemFromMusicTrack(Int32.Parse(playInfo["Id"]))); } else if (type == MpExtendedMediaTypes.MusicAlbum) { items = MpMusicHelper.CreatePlaylistItemsFromMusicAlbum(playInfo["Artist"], playInfo["Album"]); } else if (type == MpExtendedMediaTypes.MusicArtist) { items = MpMusicHelper.CreatePlaylistItemsFromMusicArtist(playInfo["Artist"]); // MpMusicHelper.PlayArtist(playInfo["Artist"], startPos); } break; case MpExtendedProviders.MPVideo: playlistType = PlayListType.PLAYLIST_VIDEO; //MpVideosHelper.PlayVideo(Int32.Parse(playInfo["Id"]), startPos); break; case MpExtendedProviders.MpVideosShare: playlistType = PlayListType.PLAYLIST_VIDEO; if (type == MpExtendedMediaTypes.File) { items.Add(MpVideosHelper.CreatePlaylistItemFromVideoFile(playInfo["Path"])); } else if (type == MpExtendedMediaTypes.Folder) { string[] extensions = playInfo["Extensions"].Split('|'); items = MpVideosHelper.CreatePlaylistItemFromVideoFolder(playInfo["Path"], extensions); } break; case MpExtendedProviders.MpMusicShare: playlistType = PlayListType.PLAYLIST_MUSIC; if (type == MpExtendedMediaTypes.File) { items.Add(MpMusicHelper.CreatePlaylistItemFromMusicFile(playInfo["Path"])); } else if (type == MpExtendedMediaTypes.Folder) { string[] extensions = playInfo["Extensions"].Split('|'); items = MpMusicHelper.CreatePlaylistItemFromMusicFolder(playInfo["Path"], extensions); } break; default: playlistType = PlayListType.PLAYLIST_VIDEO; //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(null); } items.Add(MpTvServerHelper.CreatePlaylistItemFromRecording(Int32.Parse(playInfo["Id"]))); } else { WifiRemote.LogMessage("Provider not implemented yet", WifiRemote.LogType.Warn); } break; } return(items); } catch (Exception ex) { WifiRemote.LogMessage("Error during play of MediaItem: " + ex.ToString(), WifiRemote.LogType.Error); } return(null); }
/// <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); } }
internal static void ShowFileDetails(string p) { WifiRemote.LogMessage("Not implemented yet for mp music", WifiRemote.LogType.Info); }
/// <summary> /// Show the details of a mediaitem on MediaPortal (without actually starting playback) /// </summary> /// <param name="itemId"></param> /// <param name="mediaType"></param> /// <param name="providerId"></param> /// <param name="playInfo"></param> internal static void ShowMediaItem(string itemId, int mediaType, int providerId, Dictionary <string, string> playInfo) { try { MpExtendedProviders provider = (MpExtendedProviders)providerId; MpExtendedMediaTypes type = (MpExtendedMediaTypes)mediaType; switch (provider) { case MpExtendedProviders.MovingPictures: if (WifiRemote.IsAvailableMovingPictures) { MovingPicturesHelper.ShowMovieDetails(Int32.Parse(playInfo["Id"])); } else { WifiRemote.LogMessage("MovingPictures not installed but required!", WifiRemote.LogType.Error); } break; case MpExtendedProviders.MPTvSeries: if (WifiRemote.IsAvailableTVSeries) { if (type == MpExtendedMediaTypes.TVEpisode) { TVSeriesHelper.ShowEpisodeDetails(Int32.Parse(playInfo["ShowId"]), Int32.Parse(playInfo["SeasonIndex"]), Int32.Parse(playInfo["Id"])); } else if (type == MpExtendedMediaTypes.TVSeason) { TVSeriesHelper.ShowSeasonDetails(Int32.Parse(playInfo["ShowId"]), Int32.Parse(playInfo["SeasonIndex"])); } else if (type == MpExtendedMediaTypes.TVShow) { TVSeriesHelper.ShowSeriesDetails(Int32.Parse(playInfo["Id"])); } } else { WifiRemote.LogMessage("MP-TvSeries not installed but required!", WifiRemote.LogType.Error); } break; case MpExtendedProviders.MPMusic: if (type == MpExtendedMediaTypes.MusicTrack) { MpMusicHelper.ShowMusicTrackDetails(Int32.Parse(playInfo["Id"])); } else if (type == MpExtendedMediaTypes.MusicAlbum) { MpMusicHelper.ShowAlbumDetails(playInfo["Artist"], playInfo["Album"]); } else if (type == MpExtendedMediaTypes.MusicArtist) { MpMusicHelper.ShowArtistDetails(playInfo["Artist"]); } break; case MpExtendedProviders.MPVideo: MpVideosHelper.ShowVideoDetails(Int32.Parse(playInfo["Id"])); break; case MpExtendedProviders.MpVideosShare: if (type == MpExtendedMediaTypes.File) { //TODO: fill myvideos db information instead of just playing the file MpVideosHelper.ShowFileDetails(playInfo["Path"]); } else if (type == MpExtendedMediaTypes.Folder) { string[] extensions = playInfo["Extensions"].Split('|'); MpVideosHelper.ShowFolderDetails(playInfo["Path"]); } break; case MpExtendedProviders.MpMusicShare: if (type == MpExtendedMediaTypes.File) { MpMusicHelper.ShowFileDetails(playInfo["Path"]); } else if (type == MpExtendedMediaTypes.Folder) { MpMusicHelper.ShowFolderDetails(playInfo["Path"]); } break; default: //we have no providers (yet) for tv if (type == MpExtendedMediaTypes.Recording) { if (!WifiRemote.IsAvailableTVPlugin) { WifiRemote.LogMessage("No TVPlugin installed: Aborting showrecording", WifiRemote.LogType.Error); return; } MpTvServerHelper.ShowRecordingDetails(Int32.Parse(playInfo["Id"])); } else if (type == MpExtendedMediaTypes.Tv) { if (!WifiRemote.IsAvailableTVPlugin) { WifiRemote.LogMessage("No TVPlugin installed: Aborting showchannel", WifiRemote.LogType.Error); return; } MpTvServerHelper.ShowTvChannelDetails(Int32.Parse(playInfo["Id"])); } else { WifiRemote.LogMessage("Provider not implemented yet", WifiRemote.LogType.Warn); } break; } } catch (Exception ex) { WifiRemote.LogMessage("Error during show of MediaItem: " + ex.ToString(), WifiRemote.LogType.Error); } }
/// <summary> /// Handle an Playlist 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 HandlePlaylistMessage(Newtonsoft.Json.Linq.JObject message, SocketServer socketServer, Deusty.Net.AsyncSocket sender) { String action = (string)message["PlaylistAction"]; String playlistType = (message["PlaylistType"] != null) ? (string)message["PlaylistType"] : "music"; bool shuffle = (message["Shuffle"] != null) ? (bool)message["Shuffle"] : false; bool autoPlay = (message["AutoPlay"] != null) ? (bool)message["AutoPlay"] : false; bool showPlaylist = (message["ShowPlaylist"] != null) ? (bool)message["ShowPlaylist"] : true; if (action.Equals("new") || action.Equals("append")) { //new playlist or append to playlist int insertIndex = 0; if (message["InsertIndex"] != null) { insertIndex = (int)message["InsertIndex"]; } // Add items from JSON or SQL JArray array = (message["PlaylistItems"] != null) ? (JArray)message["PlaylistItems"] : null; JObject sql = (message["PlayListSQL"] != null) ? (JObject)message["PlayListSQL"] : null; if (array != null || sql != null) { if (action.Equals("new")) { PlaylistHelper.ClearPlaylist(playlistType, false); } int index = insertIndex; if (array != null) { // Add items from JSON foreach (JObject o in array) { PlaylistEntry entry = new PlaylistEntry(); entry.FileName = (o["FileName"] != null) ? (string)o["FileName"] : null; entry.Name = (o["Name"] != null) ? (string)o["Name"] : null; entry.Duration = (o["Duration"] != null) ? (int)o["Duration"] : 0; PlaylistHelper.AddItemToPlaylist(playlistType, entry, index, false); index++; } PlaylistHelper.RefreshPlaylistIfVisible(); if (shuffle) { PlaylistHelper.Shuffle(playlistType); } } else { // Add items with SQL string where = (sql["Where"] != null) ? (string)sql["Where"] : String.Empty; int limit = (sql["Limit"] != null) ? (int)sql["Limit"] : 0; PlaylistHelper.AddSongsToPlaylistWithSQL(playlistType, where, limit, shuffle, insertIndex); } if (autoPlay) { if (message["StartPosition"] != null) { int startPos = (int)message["StartPosition"]; insertIndex += startPos; } PlaylistHelper.StartPlayingPlaylist(playlistType, insertIndex, showPlaylist); } } } else if (action.Equals("load")) { //load a playlist string playlistName = (string)message["PlayListName"]; string playlistPath = (string)message["PlaylistPath"]; if (!string.IsNullOrEmpty(playlistName) || !string.IsNullOrEmpty(playlistPath)) { PlaylistHelper.LoadPlaylist(playlistType, (!string.IsNullOrEmpty(playlistName)) ? playlistName : playlistPath, shuffle); if (autoPlay) { PlaylistHelper.StartPlayingPlaylist(playlistType, 0, showPlaylist); } } } else if (action.Equals("get")) { //get all playlist items of the currently active playlist List <PlaylistEntry> items = PlaylistHelper.GetPlaylistItems(playlistType); MessagePlaylistDetails returnPlaylist = new MessagePlaylistDetails(); returnPlaylist.PlaylistType = playlistType; returnPlaylist.PlaylistName = PlaylistHelper.GetPlaylistName(playlistType); returnPlaylist.PlaylistRepeat = PlaylistHelper.GetPlaylistRepeat(playlistType); returnPlaylist.PlaylistItems = items; socketServer.SendMessageToClient(returnPlaylist, sender); } else if (action.Equals("remove")) { //remove an item from the playlist int indexToRemove = (message["Index"] != null) ? (int)message["Index"] : 0; PlaylistHelper.RemoveItemFromPlaylist(playlistType, indexToRemove); } else if (action.Equals("move")) { //move a playlist item to a new index int oldIndex = (message["OldIndex"] != null) ? (int)message["OldIndex"] : 0; int newIndex = (message["NewIndex"] != null) ? (int)message["NewIndex"] : 0; PlaylistHelper.ChangePlaylistItemPosition(playlistType, oldIndex, newIndex); } else if (action.Equals("play")) { //start playback of a playlist item int index = (message["Index"] != null) ? (int)message["Index"] : 0; PlaylistHelper.StartPlayingPlaylist(playlistType, index, showPlaylist); } else if (action.Equals("clear")) { //clear the playlist PlaylistHelper.ClearPlaylist(playlistType, true); } else if (action.Equals("list")) { //get a list of all available playlists MessagePlaylists returnList = new MessagePlaylists(); returnList.PlayLists = PlaylistHelper.GetPlaylists(); socketServer.SendMessageToClient(returnList, sender); } else if (action.Equals("save")) { //save the current playlist to file String name = (message["Name"] != null) ? (String)message["Name"] : null; if (name != null) { PlaylistHelper.SaveCurrentPlaylist(name); } else { WifiRemote.LogMessage("Must specify a name to save a playlist", WifiRemote.LogType.Warn); } } else if (action.Equals("shuffle")) { PlaylistHelper.Shuffle(playlistType); } else if (action.Equals("repeat")) { WifiRemote.LogMessage("Playlist action repeat", WifiRemote.LogType.Debug); if (message["Repeat"] != null) { bool repeat = (bool)message["Repeat"]; PlaylistHelper.Repeat(playlistType, repeat); } else { WifiRemote.LogMessage("Must specify repeat to change playlist repeat mode", WifiRemote.LogType.Warn); } } }