Ejemplo n.º 1
0
 public function PlayFiles(array $files, $volumeChange)
 {
     $ip = $this->ReadPropertyString("IPAddress");
     $timeout = $this->ReadPropertyString("TimeOut");
     if ($timeout && Sys_Ping($ip, $timeout) != true) {
         throw new Exception("Sonos Box " . $ip . " is not available");
     }
     include_once __DIR__ . "/sonosAccess.php";
     $sonos = new SonosAccess($ip);
     $positionInfo = $sonos->GetPositionInfo();
     $mediaInfo = $sonos->GetMediaInfo();
     $transportInfo = $sonos->GetTransportInfo();
     $isGroupCoordinator = $this->ReadPropertyBoolean("GroupCoordinator");
     if ($isGroupCoordinator) {
         $volume = GetValueInteger($this->GetIDForIdent("GroupVolume"));
     } else {
         $volume = GetValueInteger($this->GetIDForIdent("Volume"));
     }
     //adjust volume if needed
     if ($volumeChange != 0) {
         // pause if playing
         if ($transportInfo == 1) {
             $sonos->Pause();
         }
         // volume request absolte or relative?
         if ($volumeChange[0] == "+" || $volumeChange[0] == "-") {
             if ($isGroupCoordinator) {
                 $this->changeGroupVolume($volumeChange);
             } else {
                 $this->ChangeVolume($volumeChange);
             }
         } else {
             if ($isGroupCoordinator) {
                 $this->SetGroupVolume($volumeChange);
             } else {
                 $this->SetVolume($volumeChange);
             }
         }
     }
     foreach ($files as $key => $file) {
         // only files on SMB share or http server can be used
         if (preg_match('/^\\/\\/[\\w,.,\\d,-]*\\/\\S*/', $file) == 1) {
             $uri = "x-file-cifs:" . $file;
         } elseif (preg_match('/^http:\\/\\/[\\w,.,\\d,-,:]*\\/\\S*/', $file) == 1) {
             $uri = $file;
         } else {
             throw new Exception("File (" . $file . ") has to be located on a Samba share (e.g. //ipsymcon.fritz.box/tts/text.mp3) or a HTTP server (e.g. http://ipsymcon.fritz.box/tts/text.mp3)");
         }
         $sonos->SetAVTransportURI($uri);
         $sonos->Play();
         IPS_Sleep(500);
         $fileTransportInfo = $sonos->GetTransportInfo();
         while ($fileTransportInfo == 1 || $fileTransportInfo == 5) {
             IPS_Sleep(200);
             $fileTransportInfo = $sonos->GetTransportInfo();
         }
     }
     // reset to what was playing before
     $sonos->SetAVTransportURI($mediaInfo["CurrentURI"], $mediaInfo["CurrentURIMetaData"]);
     if ($positionInfo["Track"] > 1) {
         $sonos->Seek("TRACK_NR", $positionInfo["Track"]);
     }
     if ($positionInfo["TrackDuration"] != "0:00:00") {
         $sonos->Seek("REL_TIME", $positionInfo["RelTime"]);
     }
     if ($volumeChange != 0) {
         // set back volume
         if ($isGroupCoordinator) {
             $this->SetGroupVolume($volume);
         } else {
             $this->SetVolume($volume);
         }
     }
     if ($transportInfo == 1) {
         $sonos->Play();
     }
 }
Ejemplo n.º 2
0
     SetValueInteger(IPS_GetObjectIDByName("Status", IPS_GetParent($_IPS["SELF"])), GetValueInteger(IPS_GetObjectIDByName("Status", $MemberOfGroup)));
     $actuallyPlaying = GetValueString(IPS_GetObjectIDByName("nowPlaying", $MemberOfGroup));
     SetValueInteger(IPS_GetObjectIDByName("Radio", IPS_GetParent($_IPS["SELF"])), GetValueInteger(IPS_GetObjectIDByName("Radio", $MemberOfGroup)));
     if (IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "SleeptimerControl")) {
         SetValueInteger(IPS_GetObjectIDByName("Sleeptimer", IPS_GetParent($_IPS["SELF"])), @GetValueInteger(IPS_GetObjectIDByName("Sleeptimer", $MemberOfGroup)));
     }
 } else {
     SetValueInteger(IPS_GetObjectIDByName("Status", IPS_GetParent($_IPS["SELF"])), $status);
     // Titelanzeige
     $currentStation = 0;
     if ($status != 1) {
         // No title if not playing
         $actuallyPlaying = "";
     } else {
         $positionInfo = $sonos->GetPositionInfo();
         $mediaInfo = $sonos->GetMediaInfo();
         if (strlen($positionInfo["streamContent"]) != 0) {
             $actuallyPlaying = $positionInfo["streamContent"];
         } else {
             $actuallyPlaying = utf8_decode($positionInfo["title"] . " | " . $positionInfo["artist"]);
         }
         // start find current Radio in VariableProfile
         $radioStations = get_available_stations();
         $playingRadioStation = '';
         foreach ($radioStations as $radioStation) {
             if ($radioStation["url"] == htmlspecialchars_decode($mediaInfo["CurrentURI"])) {
                 $playingRadioStation = $radioStation["name"];
                 break;
             }
         }
         if ($playingRadioStation == '') {