From: <sam...@us...> - 2006-09-09 17:41:37
|
Revision: 19 http://svn.sourceforge.net/mp-webinterface/?rev=19&view=rev Author: samuel337 Date: 2006-09-09 10:41:13 -0700 (Sat, 09 Sep 2006) Log Message: ----------- added coverart features, alternate RemovePlaylistItem method, fixed asynchronous usage bugs, updated Playlist & music methods, plus more that I can't remember ;-) Modified Paths: -------------- trunk/source/ECP2Assembly/AssemblySettings.cs trunk/source/ECP2Assembly/clsMPHandler.cs trunk/source/ECP2Plugin/Properties/AssemblyInfo.cs trunk/source/ECP2Plugin/clsMain.cs trunk/source/ECP2WebService/App_Code/Service.cs Added Paths: ----------- trunk/source/ECP2Assembly/clsCustomMPObjects.cs trunk/source/ECP2WebService/CoverArtHandler.ashx Modified: trunk/source/ECP2Assembly/AssemblySettings.cs =================================================================== --- trunk/source/ECP2Assembly/AssemblySettings.cs 2006-08-19 17:27:28 UTC (rev 18) +++ trunk/source/ECP2Assembly/AssemblySettings.cs 2006-09-09 17:41:13 UTC (rev 19) @@ -47,29 +47,32 @@ //initialize the apps config file, create it if it doesn't exist private void InitializeConfigFile(string configFileName) { - //if the file name that was passed is blank, then run another overloaded method - if (configFileName == null) + lock (this) { - InitializeConfigFile(); - return; - } + //if the file name that was passed is blank, then run another overloaded method + if (configFileName == null) + { + InitializeConfigFile(); + return; + } - _configFileName = configFileName; + _configFileName = configFileName; - //if the file doesn't exist, create a blank xml - if (!System.IO.File.Exists(_configFileName)) - { - System.IO.StreamWriter fn = new System.IO.StreamWriter(System.IO.File.Open(_configFileName, System.IO.FileMode.Create)); - fn.WriteLine(@"<?xml version=""1.0"" encoding=""utf-8""?>"); - fn.WriteLine(@"<configuration>"); - fn.WriteLine(@" <appSettings>"); - fn.WriteLine(@" <!-- User application and configured property settings go here.-->"); - fn.WriteLine(@" <!-- Example: <add key=""settingName"" value=""settingValue""/> -->"); - fn.WriteLine(@" <add key=""MPComputerAddress"" value=""localhost"" />"); - fn.WriteLine(@" <add key=""MPDirectory"" value="""" />"); - fn.WriteLine(@" </appSettings>"); - fn.WriteLine(@"</configuration>"); - fn.Close(); //all done + //if the file doesn't exist, create a blank xml + if (!System.IO.File.Exists(_configFileName)) + { + System.IO.StreamWriter fn = new System.IO.StreamWriter(System.IO.File.Open(_configFileName, System.IO.FileMode.Create)); + fn.WriteLine(@"<?xml version=""1.0"" encoding=""utf-8""?>"); + fn.WriteLine(@"<configuration>"); + fn.WriteLine(@" <appSettings>"); + fn.WriteLine(@" <!-- User application and configured property settings go here.-->"); + fn.WriteLine(@" <!-- Example: <add key=""settingName"" value=""settingValue""/> -->"); + fn.WriteLine(@" <add key=""MPComputerAddress"" value=""localhost"" />"); + fn.WriteLine(@" <add key=""MPDirectory"" value="""" />"); + fn.WriteLine(@" </appSettings>"); + fn.WriteLine(@"</configuration>"); + fn.Close(); //all done + } } } @@ -97,58 +100,62 @@ } //save an application setting, takes a key and a value - public void SaveSetting(string key, string value) - { - //xml document object - System.Xml.XmlDocument xd = new System.Xml.XmlDocument(); + public void SaveSetting(string key, string value) + { + lock (this) + { - //load the xml file - xd.Load(_configFileName); + //xml document object + System.Xml.XmlDocument xd = new System.Xml.XmlDocument(); - //get the value - System.Xml.XmlElement Node = (System.Xml.XmlElement)xd.DocumentElement.SelectSingleNode(@"/configuration/appSettings/add[@key=""" + key + @"""]"); - if (!(Node==null)) - { - //key found, set the value - Node.Attributes.GetNamedItem("value").Value = value; - } - else - { - //key not found, create it - Node = xd.CreateElement("add"); - Node.SetAttribute("key", key); - Node.SetAttribute("value", value); + //load the xml file + xd.Load(_configFileName); - //look for the appsettings node - System.Xml.XmlNode Root = xd.DocumentElement.SelectSingleNode(@"/configuration/appSettings"); - - //add the new child node (this key) - if (!(Root==null)) - { - Root.AppendChild(Node); - } - else - { - try + //get the value + System.Xml.XmlElement Node = (System.Xml.XmlElement)xd.DocumentElement.SelectSingleNode(@"/configuration/appSettings/add[@key=""" + key + @"""]"); + if (!(Node == null)) { - //appsettings node didn't exist, add it before adding the new child - Root = xd.DocumentElement.SelectSingleNode("/configuration"); - Root.AppendChild(xd.CreateElement("appSettings")); - Root = xd.DocumentElement.SelectSingleNode("/configuration/appSettings"); - Root.AppendChild(Node); + //key found, set the value + Node.Attributes.GetNamedItem("value").Value = value; } - catch (Exception ex) + else { - //failed adding node, throw an error - throw new Exception("Could not set value", ex); + //key not found, create it + Node = xd.CreateElement("add"); + Node.SetAttribute("key", key); + Node.SetAttribute("value", value); + + //look for the appsettings node + System.Xml.XmlNode Root = xd.DocumentElement.SelectSingleNode(@"/configuration/appSettings"); + + //add the new child node (this key) + if (!(Root == null)) + { + Root.AppendChild(Node); + } + else + { + try + { + //appsettings node didn't exist, add it before adding the new child + Root = xd.DocumentElement.SelectSingleNode("/configuration"); + Root.AppendChild(xd.CreateElement("appSettings")); + Root = xd.DocumentElement.SelectSingleNode("/configuration/appSettings"); + Root.AppendChild(Node); + } + catch (Exception ex) + { + //failed adding node, throw an error + throw new Exception("Could not set value", ex); + } + } } + + //finally, save the new version of the config file + xd.Save(_configFileName); } } - //finally, save the new version of the config file - xd.Save(_configFileName); - } - } } \ No newline at end of file Added: trunk/source/ECP2Assembly/clsCustomMPObjects.cs =================================================================== --- trunk/source/ECP2Assembly/clsCustomMPObjects.cs (rev 0) +++ trunk/source/ECP2Assembly/clsCustomMPObjects.cs 2006-09-09 17:41:13 UTC (rev 19) @@ -0,0 +1,204 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ECP2Assembly.CustomMPObjects +{ + [Serializable()] + public class MusicArtist + { + private int m_artistID; + private string m_artistName; + //private MediaPortal.Music.Database.ArtistInfo m_artistInfo; + + + public MusicArtist() + { + + } + + public int ArtistID + { + get + { + return m_artistID; + } + set + { + m_artistID = value; + } + } + + public string ArtistName + { + get + { + return m_artistName; + } + set + { + m_artistName = value; + } + } + + //public MediaPortal.Music.Database.ArtistInfo ArtistInfo + //{ + // get + // { + // return m_artistInfo; + // } + // set + // { + // m_artistInfo = value; + // } + //} + } + + [Serializable()] + public class MusicAlbum + { + private int m_albumID; + private string m_albumName; + private int m_artistID; + private int m_numOfArtists; + //private MediaPortal.Music.Database.AlbumInfo m_albumInfo; + + + public MusicAlbum() + { + + } + + public int AlbumID + { + get + { + return m_albumID; + } + set + { + m_albumID = value; + } + } + + public string AlbumName + { + get + { + return m_albumName; + } + set + { + m_albumName = value; + } + } + + public int ArtistID + { + get + { + return m_artistID; + } + set + { + m_artistID = value; + } + } + + public int NumOfArtists + { + get + { + return m_numOfArtists; + } + set + { + m_numOfArtists = value; + } + } + + //public MediaPortal.Music.Database.AlbumInfo AlbumInfo + //{ + // get + // { + // return m_albumInfo; + // } + // set + // { + // m_albumInfo = value; + // } + //} + } + + [Serializable()] + public class MusicGenre + { + private int m_genreID; + private string m_genreName; + + public MusicGenre() + { + + } + + public int GenreID + { + get + { + return m_genreID; + } + set + { + m_genreID = value; + } + } + + public string GenreName + { + get + { + return m_genreName; + } + set + { + m_genreName = value; + } + } + } + + [Serializable()] + public class PlayList + { + private string m_PlayListName; + private List<MediaPortal.Playlists.PlayListItem> m_PlayListItems; + + public PlayList() + { + m_PlayListItems = new List<MediaPortal.Playlists.PlayListItem>(); + } + + public string PlayListName + { + get + { + return m_PlayListName; + } + set + { + m_PlayListName = value; + } + } + + public List<MediaPortal.Playlists.PlayListItem> PlayListItems + { + get + { + return m_PlayListItems; + } + set + { + m_PlayListItems = value; + } + } + } +} Modified: trunk/source/ECP2Assembly/clsMPHandler.cs =================================================================== --- trunk/source/ECP2Assembly/clsMPHandler.cs 2006-08-19 17:27:28 UTC (rev 18) +++ trunk/source/ECP2Assembly/clsMPHandler.cs 2006-09-09 17:41:13 UTC (rev 19) @@ -312,48 +312,48 @@ public object GetgPlayerProps(string PropName) { - switch(PropName) + switch(PropName.ToLower()) { - case "CurrentFile": + case "currentfile": return MediaPortal.Player.g_Player.CurrentFile; - case "CurrentPosition": + case "currentposition": return MediaPortal.Player.g_Player.CurrentPosition; - case "Duration": + case "duration": return MediaPortal.Player.g_Player.Duration; - case "FullScreen": + case "fullscreen": return MediaPortal.Player.g_Player.FullScreen; - case "HasVideo": + case "hasvideo": return MediaPortal.Player.g_Player.HasVideo; - case "IsDVD": + case "isdvd": return MediaPortal.Player.g_Player.IsDVD; - case "IsRadio": + case "isradio": return MediaPortal.Player.g_Player.IsRadio; - case "IsTV": + case "istv": return MediaPortal.Player.g_Player.IsTV; - case "IsVideo": + case "isvideo": return MediaPortal.Player.g_Player.IsVideo; - case "Paused": + case "paused": return MediaPortal.Player.g_Player.Paused; - case "Playing": + case "playing": return MediaPortal.Player.g_Player.Playing; - case "Speed": + case "speed": return MediaPortal.Player.g_Player.Speed; - case "Stopped": + case "stopped": return MediaPortal.Player.g_Player.Stopped; - case "Volume": + case "volume": return MediaPortal.Player.g_Player.Volume; //if not one of the currently defined ones, use reflection to find it @@ -1023,7 +1023,7 @@ #region Playlist commands - public string CurrentPlaylistName + public string CurrentPlaylistType { get { @@ -1031,7 +1031,7 @@ } } - public int CurrentSongNo + public int CurrentItemNo { get { @@ -1058,7 +1058,20 @@ for (int i = 0; i < pl.Count; i++) { - ECP2PlayList.PlayListItems.Add(pl[i]); + //make a copy of the playlist item so it doesn't affect the actual playlist + MediaPortal.Playlists.PlayListItem OriginalPli; + MediaPortal.Playlists.PlayListItem NewPli; + OriginalPli = pl[i]; + NewPli = new MediaPortal.Playlists.PlayListItem(); + + NewPli.Description = OriginalPli.Description; + NewPli.Duration = OriginalPli.Duration; + NewPli.FileName = OriginalPli.FileName; + NewPli.Played = OriginalPli.Played; + NewPli.Type = OriginalPli.Type; + //ignore the MusicTag property as it can't be serialized properly + + ECP2PlayList.PlayListItems.Add(NewPli); } return ECP2PlayList; @@ -1138,14 +1151,31 @@ return false; } - public bool PlayPlaylistItem(MediaPortal.Playlists.PlayListType playlistType, int songNum) + public bool RemovePlaylistItem(MediaPortal.Playlists.PlayListType playlistType, int itemNum) { + MediaPortal.Playlists.PlayList pl = MediaPortal.Playlists.PlayListPlayer.SingletonPlayer.GetPlaylist(playlistType); + + if (pl == null) { return false; } + + if (itemNum >= pl.Count){ return false; } + + if (pl.Remove(pl[itemNum].FileName) > 0) + { + return true; + } + + return false; + } + + //has bugs - COM call related - FIX ASAP! + public bool PlayPlaylistItem(MediaPortal.Playlists.PlayListType playlistType, int itemNum) + { if (playlistType != MediaPortal.Playlists.PlayListPlayer.SingletonPlayer.CurrentPlaylistType) { MediaPortal.Playlists.PlayListPlayer.SingletonPlayer.CurrentPlaylistType = playlistType; } - MediaPortal.Playlists.PlayListPlayer.SingletonPlayer.Play(songNum); + MediaPortal.Playlists.PlayListPlayer.SingletonPlayer.Play(itemNum); return true; } @@ -1820,6 +1850,105 @@ return albumList; } + + public byte[] GetCoverArtForSong(int SongID) + { + //get song + MediaPortal.Music.Database.Song song = GetSong(SongID); + if (song == null) + { + return null; + } + + return GetCoverArtForSong(song); + } + + public byte[] GetCoverArtForSong(MediaPortal.Music.Database.Song song) + { + //build MusicTag + MediaPortal.TagReader.MusicTag tag = new MediaPortal.TagReader.MusicTag(); + tag.Album = song.Album; + tag.Artist = song.Artist; + tag.Duration = song.Duration; + tag.Genre = song.Genre; + tag.Rating = song.Rating; + tag.TimesPlayed = song.TimesPlayed; + tag.Title = song.Title; + tag.Track = song.Track; + tag.Year = song.Year; + + string artFilename = string.Empty ; + artFilename = MediaPortal.GUI.Music.GUIMusicFiles.GetCoverArt(false, song.FileName, tag); + + if (artFilename == string.Empty) + { + //get default icons + //make GUIListItem to get default icons (no other method available) + MediaPortal.GUI.Library.GUIListItem listItem = new GUIListItem(); + listItem.IsFolder = false; + listItem.Label = "dummy listItem to get default icons"; + listItem.Path = song.FileName; + MediaPortal.Util.Utils.SetDefaultIcons(listItem); + + artFilename = listItem.IconImageBig; + } + + //get absolute path if needed + artFilename= System.IO.Path.GetFullPath(artFilename); + + if (System.IO.File.Exists(artFilename)) + { + //turn file into byte array via fileStream as System.Drawing.Image has serialization issues + System.IO.FileStream fs = new System.IO.FileStream(artFilename, System.IO.FileMode.Open); + byte[] artFile = new byte[fs.Length]; + fs.Read(artFile, 0, (int)fs.Length); + fs.Close(); + fs.Dispose(); + return artFile; + } + + return null; + } + + public byte[] GetCoverArtForFolder(string path) + { + if (!System.IO.Directory.Exists(path)) + { + return null; + } + + string artFilename = string.Empty; + artFilename = MediaPortal.GUI.Music.GUIMusicFiles.GetCoverArt(true, path, null); + + if (artFilename == string.Empty) + { + //get default icons + //make GUIListItem to get default icons (no other method available) + MediaPortal.GUI.Library.GUIListItem listItem = new GUIListItem(); + listItem.IsFolder = true; + listItem.Label = "dummy listItem to get default icons"; + listItem.Path = path; + MediaPortal.Util.Utils.SetDefaultIcons(listItem); + + artFilename = listItem.IconImageBig; + } + + //get absolute path if needed + artFilename = System.IO.Path.GetFullPath(artFilename); + + if (System.IO.File.Exists(artFilename)) + { + //turn file into byte array via fileStream as System.Drawing.Image has serialization issues + System.IO.FileStream fs = new System.IO.FileStream(artFilename, System.IO.FileMode.Open); + byte[] artFile = new byte[fs.Length]; + fs.Read(artFile, 0, (int)fs.Length); + fs.Close(); + fs.Dispose(); + return artFile; + } + + return null; + } #endregion #region Volume commands @@ -1858,7 +1987,7 @@ } #endregion - #region ECP2 Version commands +#region ECP2 Version commands public string MPECP2Version { get Modified: trunk/source/ECP2Plugin/Properties/AssemblyInfo.cs =================================================================== --- trunk/source/ECP2Plugin/Properties/AssemblyInfo.cs 2006-08-19 17:27:28 UTC (rev 18) +++ trunk/source/ECP2Plugin/Properties/AssemblyInfo.cs 2006-09-09 17:41:13 UTC (rev 19) @@ -31,5 +31,5 @@ // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.1.2.0")] -[assembly: AssemblyFileVersion("1.1.2.0")] +[assembly: AssemblyVersion("1.1.2.1")] +[assembly: AssemblyFileVersion("1.1.2.1")] Modified: trunk/source/ECP2Plugin/clsMain.cs =================================================================== --- trunk/source/ECP2Plugin/clsMain.cs 2006-08-19 17:27:28 UTC (rev 18) +++ trunk/source/ECP2Plugin/clsMain.cs 2006-09-09 17:41:13 UTC (rev 19) @@ -17,21 +17,23 @@ void MediaPortal.GUI.Library.IPlugin.Start() { - //define HTTPchannel and setup remoting - System.Runtime.Remoting.RemotingConfiguration.Configure("MediaPortal.exe.config", false); - System.Runtime.Remoting.Channels.Tcp.TcpServerChannel channel = new System.Runtime.Remoting.Channels.Tcp.TcpServerChannel("MediaPortal ECP2", 3334, new ServerActivitySinkProvider()); - System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel, false); - System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(ECP2Assembly.MPHandler), "MPHandler", System.Runtime.Remoting.WellKnownObjectMode.SingleCall); - System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(ECP2Assembly.MPLaunchInfo), "MPLaunchInfo", System.Runtime.Remoting.WellKnownObjectMode.SingleCall); + //define HTTPchannel and setup remoting + System.Runtime.Remoting.RemotingConfiguration.Configure("MediaPortal.exe.config", false); + //turn to RemoteOnly for production version! + System.Runtime.Remoting.RemotingConfiguration.CustomErrorsMode = System.Runtime.Remoting.CustomErrorsModes.Off; + System.Runtime.Remoting.Channels.Tcp.TcpServerChannel channel = new System.Runtime.Remoting.Channels.Tcp.TcpServerChannel("MediaPortal ECP2", 3334, new ServerActivitySinkProvider()); + System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel, false); + System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(ECP2Assembly.MPHandler), "MPHandler", System.Runtime.Remoting.WellKnownObjectMode.SingleCall); + System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(ECP2Assembly.MPLaunchInfo), "MPLaunchInfo", System.Runtime.Remoting.WellKnownObjectMode.SingleCall); - //get settings - MediaPortal.Profile.Settings MPSettings = new MediaPortal.Profile.Settings("mediaportal.xml"); - shutdownDelay = MPSettings.GetValueAsInt("ECP2", "ShutdownDelay", 10); + //get settings + MediaPortal.Profile.Settings MPSettings = new MediaPortal.Profile.Settings("mediaportal.xml"); + shutdownDelay = MPSettings.GetValueAsInt("ECP2", "ShutdownDelay", 10); - ResetLastActivityTime(); + ResetLastActivityTime(); - MediaPortal.GUI.Library.Log.Write("ECP2: Remoting initialised."); - } + MediaPortal.GUI.Library.Log.Write("ECP2: Remoting initialised."); + } void MediaPortal.GUI.Library.IPlugin.Stop() { Modified: trunk/source/ECP2WebService/App_Code/Service.cs =================================================================== --- trunk/source/ECP2WebService/App_Code/Service.cs 2006-08-19 17:27:28 UTC (rev 18) +++ trunk/source/ECP2WebService/App_Code/Service.cs 2006-09-09 17:41:13 UTC (rev 19) @@ -1142,16 +1142,16 @@ #endregion #region playlist commands - [WebMethod(Description="This command returns the name of the current playlist.")] + [WebMethod(Description="This command returns the type of the current playlist.")] public string GetCurrentPlaylistName() { - return GetEMPH().CurrentPlaylistName; + return GetEMPH().CurrentPlaylistType; } - [WebMethod(Description="This command returns song number that's currently playing in the current playlist.")] + [WebMethod(Description="This command returns the item number that's currently playing in the current playlist.")] public int GetCurrentSongNo() { - return GetEMPH().CurrentSongNo; + return GetEMPH().CurrentItemNo ; } [WebMethod(Description="This command returns the items in a playlist given the playlist name (PLAYLIST_MUSIC, PLAYLIST_MUSIC_TEMP, PLAYLIST_VIDEO, PLAYLIST_VIDEO_TEMP) in XML format.")] @@ -1214,7 +1214,7 @@ return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } - [WebMethod(Description="This command adds an item to the nominated playlist.")] + [WebMethod(Description = "This command adds an item to the nominated playlist (PLAYLIST_MUSIC, PLAYLIST_MUSIC_TEMP, PLAYLIST_VIDEO, PLAYLIST_VIDEO_TEMP).")] public bool AddPlaylistItem(string playlistType, string fileName, string description, int duration, string itemType) { if (fileName=="") {return false;} @@ -1241,7 +1241,7 @@ return GetEMPH().AddPlaylistItem(playlistTypeResolve,fileName,description,duration,itemTypeResolve); } - [WebMethod(Description="This command adds an item to the nominated playlist.")] + [WebMethod(Description = "This command adds an item to the nominated playlist (PLAYLIST_MUSIC, PLAYLIST_MUSIC_TEMP, PLAYLIST_VIDEO, PLAYLIST_VIDEO_TEMP).")] public bool AddPlaylistItemUsingDB(string playlistType, string itemType, string fileName) { if (fileName=="") {return false;} @@ -1267,8 +1267,8 @@ return GetEMPH().AddPlaylistItem(playlistTypeResolve,itemTypeResolve,fileName ); } - [WebMethod(Description="This command removes an item from the nominated playlist.")] - public bool RemovePlaylistItem(string playlistType, string fileName) + [WebMethod(Description = "This command removes an item from the nominated playlist (PLAYLIST_MUSIC, PLAYLIST_MUSIC_TEMP, PLAYLIST_VIDEO, PLAYLIST_VIDEO_TEMP).")] + public bool RemovePlaylistItemByFileName(string playlistType, string fileName) { if (fileName=="") {return false;} @@ -1284,7 +1284,22 @@ return GetEMPH().RemovePlaylistItem(playlistTypeResolve,fileName); } - [WebMethod(Description="This command plays an item from the nominated playlist.")] + [WebMethod(Description = "This command removes an item specified by its location in the playlist from the nominated playlist (PLAYLIST_MUSIC, PLAYLIST_MUSIC_TEMP, PLAYLIST_VIDEO, PLAYLIST_VIDEO_TEMP).")] + public bool RemovePlaylistItem(string playlistType, int itemNum) + { + //resolve playlistType + MediaPortal.Playlists.PlayListType playlistTypeResolve; + if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListType), playlistType) == false) + { + return false; + } + + playlistTypeResolve = (MediaPortal.Playlists.PlayListType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListType), playlistType); + + return GetEMPH().RemovePlaylistItem(playlistTypeResolve,itemNum); + } + + [WebMethod(Description = "This command plays an item from the nominated playlist (PLAYLIST_MUSIC, PLAYLIST_MUSIC_TEMP, PLAYLIST_VIDEO, PLAYLIST_VIDEO_TEMP).")] public bool PlayPlaylistItem(string playlistType, int songNum) { //resolve playlistType @@ -1299,8 +1314,8 @@ return GetEMPH().PlayPlaylistItem(playlistTypeResolve,songNum); } - [WebMethod(Description="This command clears a playlist.")] - public bool ClearPlaylistItem(string playlistType) + [WebMethod(Description = "This command clears the nominated playlist (PLAYLIST_MUSIC, PLAYLIST_MUSIC_TEMP, PLAYLIST_VIDEO, PLAYLIST_VIDEO_TEMP).")] + public bool ClearPlaylist(string playlistType) { //resolve playlistType MediaPortal.Playlists.PlayListType playlistTypeResolve; Added: trunk/source/ECP2WebService/CoverArtHandler.ashx =================================================================== --- trunk/source/ECP2WebService/CoverArtHandler.ashx (rev 0) +++ trunk/source/ECP2WebService/CoverArtHandler.ashx 2006-09-09 17:41:13 UTC (rev 19) @@ -0,0 +1,125 @@ +<%@ WebHandler Language="C#" Class="ECP2WebService.CoverArtHandler" %> + +using System; +using System.Web; + +namespace ECP2WebService +{ + public class CoverArtHandler : IHttpHandler + { + + public ECP2Assembly.MPHandler GetEMPH() + { + ECP2Assembly.MPHandler.ConfigFileName = System.Web.HttpRuntime.AppDomainAppPath + "config" + System.IO.Path.DirectorySeparatorChar + "ECP2Assembly.dll.config"; + ECP2Assembly.MPHandler.MPComputerName = System.Configuration.ConfigurationManager.AppSettings.Get("MPComputerAddress"); + + return ECP2Assembly.MPHandler.Instance; + } + + //based on code from http://msdn.microsoft.com/asp.net/whidbey/beta2changes.aspx + public void ProcessRequest(HttpContext context) + { + byte[] imageBytes; + string cacheId = string.Empty; + + if (context.Request.QueryString["SongID"] != null) + { + int songId = 0; + int.TryParse(context.Request.QueryString["SongID"], out songId); + if (songId==0) + { + //parameter not an integer + context.Response.ContentType = "text/plain"; + context.Response.Write("The SongID parameter must be an integer."); + return; + } + + cacheId = songId.ToString(); + + //check to see if cache contains image + Object cachedImageBytes = context.Cache.Get(cacheId); + + if (cachedImageBytes != null) + { + imageBytes = (Byte[])cachedImageBytes; + } + else + { + imageBytes = GetEMPH().GetCoverArtForSong(songId); + if (imageBytes == null) + { + //image not found + context.Response.ContentType = "text/plain"; + context.Response.Write("No image found for the specified SongID."); + return; + } + + // store image in cache for later requests, expire after 2 hrs (above average length of album) + context.Cache.Add(cacheId, imageBytes, null, DateTime.MaxValue, new TimeSpan(2, 0, 0),System.Web.Caching.CacheItemPriority.Normal, null); + } + } + + else if (context.Request.QueryString["FolderPath"] != null) + { + string folderPath = string.Empty; + folderPath = context.Request.QueryString["FolderPath"]; + if (folderPath == string.Empty) + { + //parameter empty + context.Response.ContentType = "text/plain"; + context.Response.Write("The FolderPath parameter must not be empty."); + return; + } + + //convert folderPath from HTML encoding + folderPath = System.Web.HttpUtility.HtmlDecode(folderPath); + + cacheId = folderPath; + + //check to see if cache contains image + Object cachedImageBytes = context.Cache.Get(cacheId); + + if (cachedImageBytes != null) + { + imageBytes = (Byte[])cachedImageBytes; + } + else + { + imageBytes = GetEMPH().GetCoverArtForFolder(folderPath); + if (imageBytes == null) + { + //image not found + context.Response.ContentType = "text/plain"; + context.Response.Write("No image found for the specified folder path."); + return; + } + + // store image in cache for later requests, expire after 2 hrs (above average length of album) + context.Cache.Add(cacheId, imageBytes, null, DateTime.MaxValue, new TimeSpan(2, 0, 0), System.Web.Caching.CacheItemPriority.Normal, null); + } + } + else + { + //no parameters specified + context.Response.ContentType = "text/plain"; + context.Response.Write("no parameters specified - please specify either SongID or FolderPath."); + return; + } + + // return image + context.Response.ContentType = "image/jpeg"; + context.Response.Cache.SetCacheability(HttpCacheability.Public); + context.Response.BufferOutput = false; + context.Response.OutputStream.Write(imageBytes, 0, imageBytes.Length); + } + + public bool IsReusable + { + get + { + return false; + } + } + + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |