sabinus52/soundtouchapi

用于控制 SoundTouch Bose 扬声器的 API 客户端。

1.5.2 2022-06-11 11:45 UTC

This package is auto-updated.

Last update: 2024-09-11 17:25:16 UTC


README

SoundTouchApi 是一个 PHP 库,允许您与 Bose SoundTouch 扬声器交互。它允许您将控制集成到您自己的 PHP 应用程序或智能家居盒中。

安装

使用 composer 安装此包:

composer require sabinus52/soundtouchapi
composer install

使用方法

require __DIR__ . '/vendor/autoload.php';

use Sabinus\SoundTouch\SoundTouchApi;
use Sabinus\SoundTouch\Component\ContentItem;
use Sabinus\SoundTouch\Constants\Source;
use Sabinus\SoundTouch\Constants\Key;


// Initialize object API
$api = new SoundTouchApi('192.168.0.1');

// Get informations
$info = $api->getInfo();
print 'DeviceID : '.$info->getDeviceID()."\n";
print 'Nom : '.$info->getName()."\n";

// Get now playing
$result = $api->getNowPlaying();
print 'Source : '.$result->getSource()."\n";

// Volume
$volume = $api->getVolume();
print 'Volume : '.$volume->getActual()."\n";
print 'Mute : '.$volume->isMuted()."\n";
$api->setVolume(27); // Set new volume 0..100
$api->mute(); // Cut volume

// Select source BLUETOOTH
$source = new ContentItem();
$source->setSource(Source::BLUETOOTH);
$api->selectSource($source);

// Select station radio TUNEIN
$source = new ContentItem();
$source->setSource(Source::TUNEIN)
    ->setType('stationurl')
    ->setLocation('/v1/playback/station/s17695')
    ->setName('FG Radio FG')
    ->setImage('http://cdn-radiotime-logos.tunein.com/s17695q.png');
$api->selectSource($source);

// Send Command pause music
$api->setKey(Key::PAUSE);
$result = $api->getNowPlaying();
print 'Track : '.$result->getTrack()."\n";
print 'Artist : '.$result->getArtist()."\n";

// List of the sources
$result = $api->getSources();
foreach ($result as $key => $source) {
    print $key.' : '.$source->getName().' / '.$source->getSource()."\n";
}

// Liste of presets
$result = $api->getPresets();
foreach ($result as $preset) {
    print 'Preset '.$preset->getId().' : '.$preset->getContentItem()->getSource().' / '.$preset->getContentItem()->getName()."\n";
}

// Play preset No. 1
$api->playPreset(1);

// Set current source as preset No. 5
$api->setPreset(5);

多房间

require __DIR__ . '/vendor/autoload.php';

use Sabinus\SoundTouch\SoundTouchApi;
use Sabinus\SoundTouch\Component\ContentItem;
use Sabinus\SoundTouch\Constants\Source;
use Sabinus\SoundTouch\Constants\Key;

// Initialize object API
$api = new SoundTouchApi('192.168.0.1');

// Create zone
$zone = new Zone();
$zone->setMaster('ABCD123456')->setSender('192.168.0.1');
$slave1 = new ZoneSlave();
$slave1->setMacAddress('111ABCDEF')->setIpAddress('192.168.0.2');
$slave2 = new ZoneSlave();
$slave2->setMacAddress('222ABCDEF')->setIpAddress('192.168.0.3');
$zone->setSlaves( [ $slave1, $slave2 ] );
$api->setZone($zone);

// Remove slave
$api->removeZoneSlave($slave2);
// Add slave
$api->addZoneSlave($slave2);

Jeedom

一个特定类,用于将控制集成到 Jeedom 中。(更多功能)

查看我的 Jeedom 插件: https://github.com/sabinus52/jeedom-bose-soundtouch

示例

use Sabinus\SoundTouch\JeedomSoundTouchApi;

$speaker = new JeedomSoundTouchApi('soundtouch');

// Power ON
$speaker->powerOn();

// Select BlueTooth
$speaker->selectBlueTooth();
$status = $speaker->getNowPlaying();
print 'Source : '.$status->getSource()."\n";
print 'Track : '.$status->getTrack()."\n";
print 'Artist : '.$status->getArtist()."\n";
$speaker->play();
$speaker->nextTrack();
$status = $speaker->getNowPlaying(true); // Refresh status
print 'Track : '.$status->getTrack()."\n";
print 'Artist : '.$status->getArtist()."\n";

// Select source HDMI
$speaker->selectHDMI();

// Display volume and change it
print 'Volume Actual : '.$speaker->getLevelVolume()."\n";
print 'Mute : '.$speaker->isMuted()."\n";
$speaker->setVolume(27);
print 'New volume : '.$speaker->getLevelVolume(true)."\n";