From: <kro...@us...> - 2010-11-25 08:32:57
|
Revision: 3980 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=3980&view=rev Author: kroko_koenig Date: 2010-11-25 08:32:51 +0000 (Thu, 25 Nov 2010) Log Message: ----------- fixed music and added playlist / play now xml also some documentation Modified Paths: -------------- trunk/plugins/AndroidRemote/Server/AndroidRemote/AndroidServer.cs trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs trunk/plugins/AndroidRemote/Server/AndroidRemote.suo Added Paths: ----------- trunk/plugins/AndroidRemote/Release/Android Server communication.docx Added: trunk/plugins/AndroidRemote/Release/Android Server communication.docx =================================================================== (Binary files differ) Property changes on: trunk/plugins/AndroidRemote/Release/Android Server communication.docx ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/plugins/AndroidRemote/Server/AndroidRemote/AndroidServer.cs =================================================================== --- trunk/plugins/AndroidRemote/Server/AndroidRemote/AndroidServer.cs 2010-11-25 06:55:00 UTC (rev 3979) +++ trunk/plugins/AndroidRemote/Server/AndroidRemote/AndroidServer.cs 2010-11-25 08:32:51 UTC (rev 3980) @@ -53,9 +53,7 @@ #region IPlugin public void Start() { - // - //Action action = new Action(Action.ActionType.ACTION_EXIT, 0, 0); - //GUIGraphicsContext.OnAction(action); + logInfo("Start server"); LoadSettings(); listen = new Thread(DoListen); @@ -63,6 +61,7 @@ } public void Stop() { + logInfo("Stop server"); } #endregion @@ -87,17 +86,18 @@ { try { - objServer_Log("Try to init command controler " + Server + ":" + Port); + logInfo("Try to init command controler " + Server + ":" + Port); myListener = new TcpListener(IPAddress.Parse(Server), Convert.ToInt32(Port)); myListener.Start(); myListener.BeginAcceptSocket(new AsyncCallback(DoAcceptSocketCallback), myListener); - objServer_Log("Command controler " + Server + ":" + Port + " is running"); + logInfo("Command controler " + Server + ":" + Port + " is running"); } catch { - objServer_Log("Failed to init command controler " + Server + ":" + Port); + logInfo("Failed to init command controler " + Server + ":" + Port); + logInfo("Check your IP and port settings."); } } private static void DoAcceptSocketCallback(IAsyncResult ar) @@ -106,6 +106,8 @@ TcpListener listener = (TcpListener)ar.AsyncState; Socket clientSocket = listener.EndAcceptSocket(ar); + logDebug("Listener accept connection from " + clientSocket.RemoteEndPoint.ToString()); + // work on request Request req = new Request(clientSocket); Thread thread = new Thread(new ThreadStart(req.DoWork)); @@ -170,10 +172,14 @@ #endregion - void objServer_Log(string message) + public static void logInfo(string message) { - Log.Info("Android remote: " + message); + Log.Info("Android remote | " + message); } + public static void logDebug(string message) + { + Log.Debug("Android remote | " + message); + } } } Modified: trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs =================================================================== --- trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs 2010-11-25 06:55:00 UTC (rev 3979) +++ trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs 2010-11-25 08:32:51 UTC (rev 3980) @@ -45,8 +45,6 @@ private byte[] read; private byte[] buffer; - private static Dictionary<string, string> musicList = new Dictionary<string, string>(); - public Request(Socket Socket) { socket = Socket; @@ -143,7 +141,7 @@ if (req.EndsWith(".mp3")) { string orgPath = AndroidServer.MusicPath + "\\" + req; - ReplyMusicFile(Path.GetFileName(orgPath)); + ReplyMusicFile(orgPath); } else { @@ -154,12 +152,24 @@ #endregion #region nowplaying - else if (req.StartsWith("/nowplaying")) + else if (req.StartsWith("/nowplaying/now.xml")) { ReplyNowPlaying(); } + else if (req.StartsWith("/nowplaying/list.xml")) + { + ReplyNowPlayingPlaylist(); + } #endregion + #region favicon + else if (req.StartsWith("/favicon.ico")) + { + //todo use resource + ReplyPictureFile("c:\\favicon.ico"); + } + #endregion + else { SendErrorURL(req); @@ -255,13 +265,13 @@ string[] dirs = Directory.GetDirectories(dir, "*.*", SearchOption.TopDirectoryOnly); foreach (string f in dirs) { - msg += "<Folder>" + Path.GetFileName(f) + "</Folder>\r\n"; + msg += "<Folder>" + HttpUtility.HtmlEncode(Path.GetFileName(f)) + "</Folder>\r\n"; } //files string[] files = Directory.GetFiles(dir, "*.jpg", SearchOption.TopDirectoryOnly); foreach (string f in files) { - msg += "<File>" + Path.GetFileName(f) + "</File>\r\n"; + msg += "<File>" + HttpUtility.HtmlEncode(Path.GetFileName(f)) + "</File>\r\n"; } msg += "</Directory>\r\n"; // send @@ -355,8 +365,6 @@ { if (Directory.Exists(dir)) { - musicList.Clear(); - string msg = string.Empty; // header msg += "HTTP/1.0 200 Ok\r\n"; @@ -370,16 +378,13 @@ string[] dirs = Directory.GetDirectories(dir, "*.*", SearchOption.TopDirectoryOnly); foreach (string f in dirs) { - msg += "<Folder>" + Path.GetFileName(f) + "</Folder>\r\n"; + msg += "<Folder>" + HttpUtility.HtmlEncode(Path.GetFileName(f)) + "</Folder>\r\n"; } string[] files = Directory.GetFiles(dir, "*.mp3", SearchOption.TopDirectoryOnly); foreach (string f in files) { - string name = Path.GetFileName(f).ToLower(); - musicList.Add(name, f); - - msg += "<File>" + name + "</File>\r\n"; + msg += "<File>" + HttpUtility.HtmlEncode(Path.GetFileName(f)) + "</File>\r\n"; } msg += "</Directory>\r\n"; // send @@ -392,29 +397,20 @@ } private void ReplyMusicFile(string Filename) { - if (musicList.ContainsKey(Filename)) + if (File.Exists(Filename)) { - string path = musicList[Filename]; + byte[] b = FileToByteArray(Filename); - if (File.Exists(path)) - { - byte[] b = FileToByteArray(path); - - string msg = string.Empty; - // header - msg += "HTTP/1.0 200 Ok\r\n"; - msg += "Content-Type: audio/mpeg" + "\r\n"; - msg += "Content-Length: " + b.Length + "\r\n"; - msg += "Proxy-Connection: close" + "\r\n"; - msg += "\r\n"; - sendMessage(socket, msg); - // content - sendBytes(socket, b); - } - else - { - SendErrorFile(Filename); - } + string msg = string.Empty; + // header + msg += "HTTP/1.0 200 Ok\r\n"; + msg += "Content-Type: audio/mpeg" + "\r\n"; + msg += "Content-Length: " + b.Length + "\r\n"; + msg += "Proxy-Connection: close" + "\r\n"; + msg += "\r\n"; + sendMessage(socket, msg); + // content + sendBytes(socket, b); } else { @@ -477,7 +473,52 @@ // send sendMessage(socket, msg); } + private void ReplyNowPlayingPlaylist() + { + MediaPortal.Playlists.PlayListPlayer player = MediaPortal.Playlists.PlayListPlayer.SingletonPlayer; + MediaPortal.Playlists.PlayList list = player.GetPlaylist(player.CurrentPlaylistType); + int currentSong = player.CurrentSong; + + string msg = string.Empty; + // header + msg += "HTTP/1.0 200 Ok\r\n"; + msg += "Content-Type: application/xml; charset=utf-8; filename=info.xml" + "\r\n"; + msg += "Proxy-Connection: close" + "\r\n"; + msg += "\r\n"; + // content + msg += "<?xml version=\"1.0\"?>\r\n"; + msg += "<NowPlayingPlaylist>\r\n"; + + msg += "<CurrentItem>" + currentSong.ToString() + "</CurrentItem>\r\n"; + msg += "<TotalItem>" + list.Count.ToString() + "</TotalItem>\r\n"; + + foreach (MediaPortal.Playlists.PlayListItem item in list) + { + string desc = item.Description; + int duration = item.Duration; + string file = item.FileName; + bool played = item.Played; + string typ = item.Type.ToString(); + + desc = HttpUtility.HtmlEncode(desc); + + msg += "<Item>\r\n"; + + msg += "<Title>" + desc + "</Title>\r\n"; + msg += "<Duration>" + duration + "</Duration>\r\n"; + msg += "<Played>" + played.ToString() + "</Played>\r\n"; + msg += "<Typ>" + typ + "</Typ>\r\n"; + + msg += "</Item>\r\n"; + } + + msg += "</NowPlayingPlaylist>\r\n"; + // send + + sendMessage(socket, msg); + } + private void SendErrorURL(string Url) { System.Diagnostics.Debug.WriteLine("URL NOT FOUND " + Url); Modified: trunk/plugins/AndroidRemote/Server/AndroidRemote.suo =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |