UPNP-Device ansteuern

Hallo Gemeinde,

erstmal schönen Sonntag.

Nachdem ich vor einem halben Jahr 2 Threads eröffnete bezüglich der Ansteuerung von UPNP-Geräten, welche jedoch leider ins Leere führten, habe ich die Geschichte erstmal ruhen lassen.

Jetzt hat mich aber nochmal das Interesse gepackt und so habe ich mit WireShark die UPNP-Befehle diverser Programme mitgeschnitten und verglichen.

Das Ganze habe ich nun versucht in das Script von Paresy (Ansteuern einzelner Sonos Player) zu implementieren. Der Teilerfolg ist zumindest eine Rückmeldung der entsprechenden Geräte - allerdings eine Fehlermeldung. MP3 zu streamen habe ich aber noch nicht geschafft. Ich vermute ein Problem mit der absoluten Pfadangabe zum File:

   HTTP/1.1 404 Page not found
   Content-type: text/html
   Content-length: 31
   X-AV-Server-Info: av=5.0; hn=""; cn="Sony Corporation"; mn="STR-DN2010"; mv="1.0";
   Server: MediabolicMWEB/-20110625.043845
   Connection: close

   ErrorPage not found!

Hier mal das Script.

<?

//---------------------------------------------------------------------------------------------------
//UPNP Test Script 11/2012
//basierend auf Paresy´s Script zum Ansteuern einzelner Sonos-Player
//---------------------------------------------------------------------------------------------------

//IPAdresse und Port
$address = "192.168.178.151:8080";
$port = 8080;

if($IPS_SENDER == "Designer")
{
$action = $IPS_COMPONENT; //IPSYMID Feld verwenden
}
else if($IPS_SENDER == "Variable")
{
$action = $IPS_VALUE; //Per Variable getriggert
}
else //Aktion über Execute gestartet. Festgelegte Aktion starten
{
$action = "Titel"; // Titel, Play, Pause, Stop, Next, Previous, SetVolume, SetMute
$action = "Play"; // Titel, Play, Pause, Stop, Next, Previous, SetVolume, SetMute
}

$volume = 10; // SetVolume 0 - 100
$mute = 0; // 0 > Musik / 1 > kein Ton

//---------------------------------------------------------------------------------------------------
//Datei laden
//Kommentar: Absolute Dateipfade einbinden ? / Datenbank einbinden ? Twonky ?
//---------------------------------------------------------------------------------------------------

$file = "http://192.168.178.128/Haus_Programme/Test.mp3";


//UPNP-Befehle---------------------------------------------------------------------------------------

//URI definieren-------------------------------------------------------------------------------------

$content_uri='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.'
SOAPAction: "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"
Content-Length: '.(394 + strlen(htmlspecialchars($file))).'
Content-Type: text/xml; charset="utf-8"
CONNECTION: close

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <s:Body>
    <u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
      <InstanceID>0</InstanceID>
      <CurrentURI>'.$file.'</CurrentURI>
      <CurrentURIMetaData></CurrentURIMetaData>
    </u:SetAVTransportURI>
  </s:Body>
</s:Envelope>';

//Play-----------------------------------------------------------------------------------------------

$content_play='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.'
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 340
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
         <Speed>1</Speed>
      </u:Play>
   </s:Body>
</s:Envelope>';

//Pause----------------------------------------------------------------------------------------------

$content_pause='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.'
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Pause"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 317
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:Pause xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
      </u:Pause>
   </s:Body>
</s:Envelope>';

//Stop-----------------------------------------------------------------------------------------------

$content_stop='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.'
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Stop"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 315
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:Stop xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
      </u:Stop>
   </s:Body>
</s:Envelope>';

//Next-----------------------------------------------------------------------------------------------

$content_next='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.'
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Next"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 315
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:Next xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
      </u:Next>
   </s:Body>
</s:Envelope>';

//Previous-------------------------------------------------------------------------------------------

$content_previous='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.'
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Previous"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 323
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:Previous xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
      </u:Previous>
   </s:Body>
</s:Envelope>';

//Setvolume------------------------------------------------------------------------------------------

$content_setvolume='POST /RenderingControl/ctrl HTTP/1.1
HOST: '.$address.'
SOAPACTION: "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: “(404+('.strlen($volume).'))”
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:SetVolume xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1">
         <InstanceID>0</InstanceID>
         <Channel>Master</Channel>
         <DesiredVolume>.$volume.</DesiredVolume>
      </u:SetVolume>
   </s:Body>
</s:Envelope>';

//SetMute--------------------------------------------------------------------------------------------

$content_setmute='POST /RenderingControl/ctrl HTTP/1.1
HOST: '.$address.'
SOAPACTION: "urn:schemas-upnp-org:service:RenderingControl:1#SetMute"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 396
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:SetMute xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1">
         <InstanceID>0</InstanceID>
         <Channel>Master</Channel>
         <DesiredMute>.$mute.</DesiredMute>
      </u:SetMute>
   </s:Body>
</s:Envelope>';

//---------------------------------------------------------------------------------------------------
//weitere Befehle ergänzen / Switch nicht vergessen-------------------------------------------
//---------------------------------------------------------------------------------------------------

//Switch definieren--------------------------------------------------------------------------------

switch($action)
{
  case "Titel":
      $content = $content_uri;
    break;
  case "Play":
      $content = $content_play;
    break;
  case "Pause":
      $content = $content_pause;
    break;
  case "Stop":
      $content = $content_stop;
    break;
  case "Next":
      $content = $content_next;
    break;
  case "Previous":
      $content = $content_previous;
    break;
  case "SetVolume":
      $content = $content_setvolume;
    break;
  case "SetMute":
      $content = $content_setmute;
    break;
}

//Senden----------------------------------------------------------------------------------------

$fp = fsockopen ($address, $port, $errno, $errstr, 10);
if (!$fp) {
    echo "$errstr ($errno)<br />
";
} else {
    fputs ($fp, $content);
    $ret = "";
    while (!feof($fp)) {
        $ret.= fgets($fp,128);
    }
    fclose($fp);
}

//Rückgabe--------------------------------------------------------------------------------------

if(strpos($ret, "200 OK") === false)
{
echo $ret;
} else {
echo "OK";
}

?>

Vielleicht hat ja jemand eine Idee, wo der Fehler liegt. :wink:

Viele Grüße

André

… bin ein kleines Stück weiter und bekomme jetzt Fehlermeldungen wonach der falsche MIME-Type vorliegt:

HTTP/1.1 500 Internal Server Error
CONTENT-LENGTH: 513
CONTENT-TYPE: text/xml; charset=„utf-8“
X-AV-Server-Info: av=„5.0“; cn=„Sony Corporation“; mn=„SA-NS400“; mv=„1.00“
X-AV-Physical-Unit-Info: pa=„SA-NS400“
EXT:
SERVER: KnOS/3.2 UPnP/1.0 DMP/3.5

s:Client
UPnPError

714
Illegal MIME-type

Das veränderte Script bei welchem ich auch erst die URI übergebe und dann die Aktion:

<?

//------------------------------------------------------------------------------
//UPNP Test Script 11/2012 V012
//basierend auf Paresy´s Script zum Ansteuern einzelner Sonos-Player
//------------------------------------------------------------------------------

//IPAdresse und Port
$address = "192.168.178.151";
$port = "8080";

$volume = 20; // SetVolume 0 - 100
$mute = 0; // 0 > Musik / 1 > kein Ton

//------------------------------------------------------------------------------
//Datei laden
//Kommentar: Absolute Dateipfade einbinden ? / Datenbank einbinden ? Twonky ?
//------------------------------------------------------------------------------

$file = "http://stream.hoerradar.de/psr128";
//$file = "http://192.168.178.128/Haus_Programme/Test.mp3";

//UPNP-Befehle------------------------------------------------------------------

//URI definieren----------------------------------------------------------------

$content_uri='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPAction: "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"
Content-Length: '.(394 + strlen(htmlspecialchars($file))).'
Content-Type: text/xml; charset="utf-8"
CONNECTION: close

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <s:Body>
    <u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
      <InstanceID>0</InstanceID>
      <CurrentURI>'.$file.'</CurrentURI>
      <CurrentURIMetaData></CurrentURIMetaData>
    </u:SetAVTransportURI>
  </s:Body>
</s:Envelope>';

//URI-Senden--------------------------------------------------------------------

$fp = fsockopen ($address, $port, $errno, $errstr);

if (!$fp)
{
    echo "$errstr ($errno)<br />
";
}
    else
{
    fputs ($fp, $content_uri);

    $ret = "";

while (!feof($fp))
{
    $ret.= fgets($fp,128);
}
fclose($fp);
}

//Rückgabe----------------------------------------------------------------------

if(strpos($ret, "200 OK") === false)
{
echo $ret;
}
else
{
echo "OK";
}

//Aktion wählen-----------------------------------------------------------------

$action = "Play"; // Titel, Play, Pause, Stop, Next, Previous, SetVolume, SetMute

//Play--------------------------------------------------------------------------

$content_play='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 340
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
         <Speed>1</Speed>
      </u:Play>
   </s:Body>
</s:Envelope>';

//Pause-------------------------------------------------------------------------

$content_pause='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Pause"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 317
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:Pause xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
      </u:Pause>
   </s:Body>
</s:Envelope>';

//Stop--------------------------------------------------------------------------

$content_stop='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Stop"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 315
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:Stop xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
      </u:Stop>
   </s:Body>
</s:Envelope>';

//Next--------------------------------------------------------------------------

$content_next='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Next"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 315
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:Next xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
      </u:Next>
   </s:Body>
</s:Envelope>';

//Previous----------------------------------------------------------------------

$content_previous='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Previous"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 323
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:Previous xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
      </u:Previous>
   </s:Body>
</s:Envelope>';

//Setvolume---------------------------------------------------------------------

$content_setvolume='POST /RenderingControl/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPACTION: "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: '.(404+(strlen($volume))).'
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:SetVolume xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1">
         <InstanceID>0</InstanceID>
         <Channel>Master</Channel>
         <DesiredVolume>'.$volume.'</DesiredVolume>
      </u:SetVolume>
   </s:Body>
</s:Envelope>';

//SetMute-----------------------------------------------------------------------

$content_setmute='POST /RenderingControl/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPACTION: "urn:schemas-upnp-org:service:RenderingControl:1#SetMute"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 396
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:SetMute xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1">
         <InstanceID>0</InstanceID>
         <Channel>Master</Channel>
         <DesiredMute>'.$mute.'</DesiredMute>
      </u:SetMute>
   </s:Body>
</s:Envelope>';

//------------------------------------------------------------------------------
//weitere Befehle ergänzen / Switch nicht vergessen-----------------------------
//------------------------------------------------------------------------------

//Switch definieren-------------------------------------------------------------

switch($action)
{
  case "Play":
      $content = $content_play;
    break;
  case "Pause":
      $content = $content_pause;
    break;
  case "Stop":
      $content = $content_stop;
    break;
  case "Next":
      $content = $content_next;
    break;
  case "Previous":
      $content = $content_previous;
    break;
  case "SetVolume":
      $content = $content_setvolume;
    break;
  case "SetMute":
      $content = $content_setmute;
    break;
}

//Senden------------------------------------------------------------------------

$fp = fsockopen ($address, $port, $errno, $errstr);

if (!$fp)
{
    echo "$errstr ($errno)<br />
";
}
    else
{
    fputs ($fp, $content);

    $ret = "";

while (!feof($fp))
{
    $ret.= fgets($fp,128);
}
fclose($fp);
}

//Rückgabe----------------------------------------------------------------------

if(strpos($ret, "200 OK") === false)
{
echo $ret;
}
else
{
echo "OK";
}

?>

Kann mir jemand mit den absoluten Pfadangaben, Ports (Server-seitig) und ggf. Zugriff auf Twonky, Asset-UPNP oder Medienbibliothek helfen ?
Die POST-Codes entsprechen UPNP-Standard. Wäre schön, wenn das zugegeben schwierige Thema zu knacken ist und Medien oder auch nur Befehle an UPNP-Clents gesendet werden könnten :slight_smile:

Viele Grüße

André

Hallo Gemeinde,

nach der trial and error Methode ist es mir nun endlich gelungen Musik auf die Netzwerk-Lautsprecher zu bekommen :slight_smile:

Es war letztlich die Netzwerk-Freigabe der Dateien und kleine Anpassungen im Script (siehe unten). Ich habe vorerst als „proof of concept“ die url´s von Asset-UPNP verwendet.

Kennt jemand eine Lösung in Netzwerk-Ordnern zu browsen und dann gezielt die Datei abspielen zu lassen ?

Viele Grüße

André

<?

//------------------------------------------------------------------------------
//UPNP Test Script 11/2012 V018
//------------------------------------------------------------------------------

//IPAdresse und Port
$address = "192.168.178.151";
$port = "8080";

$volume = 20; // SetVolume 0 - 100
$mute = 0; // 0 > Musik / 1 > kein Ton

//------------------------------------------------------------------------------
//Datei laden
//Kommentar: Absolute Dateipfade einbinden ? / Datenbank einbinden ? Twonky ?
//------------------------------------------------------------------------------


$file = "http://192.168.178.128:26125/content/c2/b16/f44100/d6450-co659.mp3";
//$file = "http://192.168.178.128:26125/content/c2/b16/f44100/d5015-co1851.mp3";
//$file = "http://192.168.178.128:26125/content/c2/b16/f44100/d5011-co1851.mp3";

//UPNP-Befehle------------------------------------------------------------------

//URI definieren----------------------------------------------------------------

$content_uri='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPAction: "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"
Content-Length: '.(394+strlen(htmlspecialchars($file))).'
Content-Type: text/xml; charset="utf-8"
CONNECTION: close

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <s:Body>
    <u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
      <InstanceID>0</InstanceID>
      <CurrentURI>'.$file.'</CurrentURI>
      <CurrentURIMetaData></CurrentURIMetaData>
    </u:SetAVTransportURI>
  </s:Body>
</s:Envelope>';

//URI-Senden--------------------------------------------------------------------

$fp = fsockopen ($address, $port, $errno, $errstr);

if (!$fp)
{
    echo "$errstr ($errno)<br />
";
}
    else
{
    fputs ($fp, $content_uri);

    $ret = "";

while (!feof($fp))
{
    $ret.= fgets($fp,128);
}
fclose($fp);
}

//Rückgabe----------------------------------------------------------------------

if(strpos($ret, "200 OK") === false)
{
echo $ret;
}
else
{
echo "OK";
}

//Aktion wählen-----------------------------------------------------------------

$action = "Play"; // Titel, Play, Pause, Stop, Next, Previous, SetVolume, SetMute

//Play--------------------------------------------------------------------------

$content_play='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 340
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
         <Speed>1</Speed>
      </u:Play>
   </s:Body>
</s:Envelope>';

//Pause-------------------------------------------------------------------------

$content_pause='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Pause"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 317
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:Pause xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
      </u:Pause>
   </s:Body>
</s:Envelope>';

//Stop--------------------------------------------------------------------------

$content_stop='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Stop"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 315
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:Stop xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
      </u:Stop>
   </s:Body>
</s:Envelope>';

//Next--------------------------------------------------------------------------

$content_next='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Next"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 315
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:Next xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
      </u:Next>
   </s:Body>
</s:Envelope>';

//Previous----------------------------------------------------------------------

$content_previous='POST /AVTransport/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Previous"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 323
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:Previous xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
      </u:Previous>
   </s:Body>
</s:Envelope>';

//Setvolume---------------------------------------------------------------------

$content_setvolume='POST /RenderingControl/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPACTION: "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: '.(404+(strlen($volume))).'
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:SetVolume xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1">
         <InstanceID>0</InstanceID>
         <Channel>Master</Channel>
         <DesiredVolume>'.$volume.'</DesiredVolume>
      </u:SetVolume>
   </s:Body>
</s:Envelope>';

//SetMute-----------------------------------------------------------------------

$content_setmute='POST /RenderingControl/ctrl HTTP/1.1
HOST: '.$address.':'.$port.'
SOAPACTION: "urn:schemas-upnp-org:service:RenderingControl:1#SetMute"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 396
CONNECTION: close

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <u:SetMute xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1">
         <InstanceID>0</InstanceID>
         <Channel>Master</Channel>
         <DesiredMute>'.$mute.'</DesiredMute>
      </u:SetMute>
   </s:Body>
</s:Envelope>';

//------------------------------------------------------------------------------
//weitere Befehle ergänzen / Switch nicht vergessen-----------------------------
//------------------------------------------------------------------------------

//Switch definieren-------------------------------------------------------------

switch($action)
{
  case "Play":
      $content = $content_play;
    break;
  case "Pause":
      $content = $content_pause;
    break;
  case "Stop":
      $content = $content_stop;
    break;
  case "Next":
      $content = $content_next;
    break;
  case "Previous":
      $content = $content_previous;
    break;
  case "SetVolume":
      $content = $content_setvolume;
    break;
  case "SetMute":
      $content = $content_setmute;
    break;
}

//Senden------------------------------------------------------------------------

$fp = fsockopen ($address, $port, $errno, $errstr);

if (!$fp)
{
    echo "$errstr ($errno)<br />
";
}
    else
{
    fputs ($fp, $content);

    $ret = "";

while (!feof($fp))
{
    $ret.= fgets($fp,128);
}
fclose($fp);
}

//Rückgabe----------------------------------------------------------------------

if(strpos($ret, "200 OK") === false)
{
echo $ret;
}
else
{
echo "OK";
}

?>

Ich bin mehr oder weniger am selben Problem dran.
Ich möchte Songs von Google Music auf meine UPNP Lautsprecher rendern.
Und das Ganze dann mit Alexa steuern.

Ich bin soweit das ich Google Music synchronisiert bekomme.
Als nächstes werde ich jetzt deine Scripte probieren ob ich damit die Ausgabe auf den Lautsprechern hinbekomme.

Hier ist mein bisheriges Script. Ist allerdings in Python, aber das programmiere ich auch gerne in php nochmal neu. Das kann ich nämlich deutlich besser :smiley:

https://github.com/wizkoder/gmusic_for_alexa

Hallo wizkoder,

der Threads ist 4 Jahre alt :wink: Zufall, das die Postfachfunktion bei mir noch eingeschaltet war :smiley:

Das Projekt klingt interessant. Googleplay Music nutze ich allerdings nicht. Eher Amazon Music oder Spotify.
Zumindest Punkt 7 und 8 kannst Du Dir in dem Thread anlesen:

UPNP/DLNA for IPS: new version

Falls Du das in PHP wandelst ist es bestimmt leichter mit IPS zu handeln. Vielleicht könnte man auch andere Streamingdienste damit arbeiten lassen?

Gruß André