<?php
$IP_TABLE = array(
'sonos_chambre' => '192.168.0.17',
'sonos_cuisine' => '192.168.0.15',
'sonos_dressing' => '192.168.0.18',
'sonos_hall' => '192.168.0.19',
'sonos_bain' => '192.168.0.23',
'sonos_salon' => '192.168.0.20'
);
$PORT_TABLE = array(
'sonos_chambre' => 1400,
'sonos_cuisine' => 1400,
'sonos_dressing' => 1400,
'sonos_hall' => 1400,
'sonos_bain' => 1400,
'sonos_salon' => 1400
);
function sendUpnp($sendTo, $msg, $type = 'control'){
global $STREAM_TIMEOUT, $DEBUG, $IP_TABLE, $PORT_TABLE;
if($type == 'control'){
$sRequestXml = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:'.$msg.' xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:'.$msg.'></s:Body></s:Envelope>';
$url = 'http://' . $IP_TABLE[$sendTo] . ':' . $PORT_TABLE[$sendTo] . '/MediaRenderer/AVTransport/Control';
}
else if($type == 'volume'){
$sRequestXml = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetVolume xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"><InstanceID>0</InstanceID><Channel>Master</Channel><DesiredVolume>' . $msg . '</DesiredVolume></u:SetVolume></s:Body></s:Envelope>';
$url = 'http://' . $IP_TABLE[$sendTo] . ':' . $PORT_TABLE[$sendTo] . '/MediaRenderer/RenderingControl/Control';
}
else if($type == 'getvolume'){
$sRequestXml = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetVolume xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"><InstanceID>0</InstanceID><Channel>Master</Channel></u:GetVolume></s:Body></s:Envelope>';
$url = 'http://' . $IP_TABLE[$sendTo] . ':' . $PORT_TABLE[$sendTo] . '/MediaRenderer/RenderingControl/Control';
}
else if($type == 'information'){
$sRequestXml = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetPositionInfo xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Channel>Master</Channel></u:GetPositionInfo></s:Body></s:Envelope>';
$url = 'http://' . $IP_TABLE[$sendTo] . ':' . $PORT_TABLE[$sendTo] . '/MediaRenderer/AVTransport/Control';
}
else if($type == 'playing'){
$sRequestXml = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetTransportInfo xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Channel>Master</Channel></u:GetTransportInfo></s:Body></s:Envelope>';
$url = 'http://' . $IP_TABLE[$sendTo] . ':' . $PORT_TABLE[$sendTo] . '/MediaRenderer/AVTransport/Control';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 300); //timeout after 5 minutes (60 * 5 = 300)
if($type == 'control'){
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml", "SOAPAction: \"urn:schemas-upnp-org:service:AVTransport:1#$msg\""));
}
else if($type == 'volume'){
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml", "SOAPAction: \"urn:schemas-upnp-org:service:RenderingControl:1#SetVolume\""));
}
else if($type == 'getvolume'){
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml", "SOAPAction: \"urn:schemas-upnp-org:service:RenderingControl:1#GetVolume\""));
}
else if($type == 'information'){
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml", "SOAPAction: \"urn:schemas-upnp-org:service:RenderingControl:1#GetPositionInfo\""));
}
else if($type == 'playing'){
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml", "SOAPAction: \"urn:schemas-upnp-org:service:RenderingControl:1#GetTransportInfo\""));
}
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sRequestXml);
$sResponse = curl_exec($ch);
return $sResponse;
}
// Lance la lecture de la playlist
function playSonos($room){
sendUpnp('sonos_'.$room, 'Play');
}
// Met en pause la lecture
function pauseSonos($room){
sendUpnp('sonos_'.$room, 'Pause');
}
// Prochain morceau dans la playlist
function nextSonos($room){
sendUpnp('sonos_'.$room, 'Next');
}
// Précédent morceau dans la playlist
function previousSonos($room){
sendUpnp('sonos_'.$room, 'Previous');
}
// Stop la lecture de la musique
function stopSonos($room){
sendUpnp('sonos_'.$room, 'Stop');
}
// Change le volume du Sonos (entre 0 et 100)
function volumeSonos($volume = 0, $room){
sendUpnp('sonos_'.$room, $volume, 'volume');
}
?>
<?php
include ('sonos.php');
$action = $_GET('action');
$room = $_GET('room');
$volume = $GET('volume');
switch ($action) {
case "play" : playSonos($room); break;
case "pause" : pauseSonos($room); break;
case "next" : nextSonos($room); break;
case "previous" : previousSonos($room); break;
case "stop" : stopSonos($room); break;
case "volume" : volumeSonos($volume,$room); break;
default: break;
}
?>
http://IP/framework_sonos.php?action=stop&room=sonos_dressing
darkwinter a écrit:Tu pourras tester chez toi DJ momo?
<?
phpinfo();
?>
Utilisateurs parcourant ce forum : Aucun utilisateur inscrit et 31 invité(s)