Exemplo n.º 1
0
 public bool IsConnected()
 {//Will send a request to the DLNA server and then see if we get a valid reply
     Connected = false;
     try
     {
         Socket SocWeb = HelperDLNA.MakeSocket(this.IP, this.Port);
         SocWeb.Send(Encoding.UTF8.GetBytes(HelperDLNA.MakeRequest("GET", this.SMP, 0, "", this.IP, this.Port)), SocketFlags.None);
         this.HTML = HelperDLNA.ReadSocket(SocWeb, true, ref this.ReturnCode);
         if (this.ReturnCode != 200)
         {
             return(false);
         }
         this.Services = DLNAService.ReadServices(HTML);
         if (this.HTML.ToLower().IndexOf("<friendlyname>") > -1)
         {
             this.FriendlyName = this.HTML.ChopOffBefore("<friendlyName>").ChopOffAfter("</friendlyName>").Trim();
         }
         foreach (DLNAService S in this.Services.Values)
         {
             if (S.ServiceType.ToLower().IndexOf("avtransport:1") > -1)//avtransport is the one we will be using to control the device
             {
                 this.ControlURL = S.controlURL;
                 this.Connected  = true;
                 return(true);
             }
         }
     }
     catch {; }
     return(false);
 }
Exemplo n.º 2
0
        private string Pause(string ControlURL, int Instance)
        {//Called to pause playing a movie or a music track
            string XML = XMLHead;

            XML += "<u:Pause xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>" + Instance + "</InstanceID></u:Pause>" + Environment.NewLine;
            XML += XMLFoot + Environment.NewLine;
            Socket SocWeb  = HelperDLNA.MakeSocket(this.IP, this.Port);
            string Request = HelperDLNA.MakeRequest("POST", ControlURL, XML.Length, "urn:schemas-upnp-org:service:AVTransport:1#Pause", this.IP, this.Port) + XML;

            SocWeb.Send(Encoding.UTF8.GetBytes(Request), SocketFlags.None);
            return(HelperDLNA.ReadSocket(SocWeb, true, ref this.ReturnCode));
        }
Exemplo n.º 3
0
        private string StartPlay(string ControlURL, int Instance)
        {//Start playing the new upload film or music track
            string XML = XMLHead;

            XML += "<u:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>" + Instance + "</InstanceID><Speed>1</Speed></u:Play>" + Environment.NewLine;
            XML += XMLFoot + Environment.NewLine;
            Socket SocWeb  = HelperDLNA.MakeSocket(this.IP, this.Port);
            string Request = HelperDLNA.MakeRequest("POST", ControlURL, XML.Length, "urn:schemas-upnp-org:service:AVTransport:1#Play", this.IP, this.Port) + XML;

            SocWeb.Send(Encoding.UTF8.GetBytes(Request), SocketFlags.None);
            return(HelperDLNA.ReadSocket(SocWeb, true, ref this.ReturnCode));
        }
Exemplo n.º 4
0
        private string GetTransportInfo(string ControlURL)
        {//Returns the current position for the track that is playing on the DLNA server
            string XML     = XMLHead + "<m:GetTransportInfo xmlns:m=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"ui4\">0</InstanceID></m:GetTransportInfo>" + XMLFoot + Environment.NewLine;
            Socket SocWeb  = HelperDLNA.MakeSocket(this.IP, this.Port);
            string Request = HelperDLNA.MakeRequest("POST", ControlURL, XML.Length, "urn:schemas-upnp-org:service:AVTransport:1#GetTransportInfo", this.IP, this.Port) + XML;

            if (SocWeb != null)
            {
                SocWeb.Send(Encoding.UTF8.GetBytes(Request), SocketFlags.None);
                return(HelperDLNA.ReadSocket(SocWeb, true, ref this.ReturnCode));
            }
            else
            {
                return("");
            }
        }
Exemplo n.º 5
0
        //public bool AddToQueue(string UrlToPlay, ref bool NewTrackPlaying)
        //{//We add music tracks to a play list queue and then we poll the server so we know when to send the next track in the queue to play
        //    if (!this.Connected) this.Connected = this.IsConnected();
        //    if (!this.Connected) return false;
        //    foreach (string Url in PlayListQueue.Values)
        //    {
        //        if (Url.ToLower() == UrlToPlay.ToLower())
        //            return false;
        //    }
        //    PlayListQueue.Add(PlayListQueue.Count + 1, UrlToPlay);
        //    if (!NewTrackPlaying)
        //    {
        //        PlayListPointer = PlayListQueue.Count + 1;
        //        StopPlay(false);
        //        TryToPlayFile(UrlToPlay);
        //        NewTrackPlaying = true;
        //    }
        //    return false;
        //}

        //private string NextPlayList(string ControlURL, string UrlToPlay, int Instance)
        //{//Yes  this would be nice but it does not queue the track up and that is why we use our own queue and then poll the DLNA server to know when to play the next track
        //    string XML = XMLHead;
        //    XML += "<u:SetNextAVTransportURI xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">" + Environment.NewLine;
        //    XML += "<InstanceID>" + Instance + "</InstanceID>" + Environment.NewLine;
        //    XML += "<NextURI>" + UrlToPlay.Replace(" ", "%20") + "</NextURI>" + Environment.NewLine;
        //    XML += "<NextURIMetaData>" + Desc() + "</NextURIMetaData>" + Environment.NewLine;
        //    XML += "</u:SetNextAVTransportURI>" + Environment.NewLine;
        //    XML += XMLFoot + Environment.NewLine;
        //    Socket SocWeb = HelperDLNA.MakeSocket(this.IP, this.Port);
        //    string Request = HelperDLNA.MakeRequest("POST", ControlURL, XML.Length, "urn:schemas-upnp-org:service:AVTransport:1#SetNextAVTransportURI", this.IP, this.Port) + XML;
        //    SocWeb.Send(Encoding.UTF8.GetBytes(Request), SocketFlags.None);
        //    string HTML = HelperDLNA.ReadSocket(SocWeb, true, ref this.ReturnCode);
        //    return HTML;
        //}

        private string UploadFileToPlay(string ControlURL, string UrlToPlay, string[] info = null)
        {///Later we will send a message to the DLNA server to start the file playing
            string XML = XMLHead;

            XML += "<u:SetAVTransportURI xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">" + Environment.NewLine;
            XML += "<InstanceID>0</InstanceID>" + Environment.NewLine;
            XML += "<CurrentURI>" + encodeUrl(UrlToPlay) + "</CurrentURI>" + Environment.NewLine;
            if (info != null)
            {
                XML += "<CurrentURIMetaData>" + Desc(UrlToPlay, info) + "</CurrentURIMetaData>" + Environment.NewLine;
            }
            else
            {
                XML += "<CurrentURIMetaData></CurrentURIMetaData>" + Environment.NewLine;
            }
            XML += "</u:SetAVTransportURI>" + Environment.NewLine;
            XML += XMLFoot + Environment.NewLine;
            Socket SocWeb  = HelperDLNA.MakeSocket(this.IP, this.Port);
            string Request = HelperDLNA.MakeRequest("POST", ControlURL, XML.Length, "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI", this.IP, this.Port) + XML;

            SocWeb.Send(Encoding.UTF8.GetBytes(Request), SocketFlags.None);
            return(HelperDLNA.ReadSocket(SocWeb, true, ref this.ReturnCode));
        }