granddam/php-musiccast-api

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

A PHP library for interacting with Yamaha MusicCast speakers

dev-master / 1.0.x-dev 2020-09-23 10:46 UTC

This package is not auto-updated.

Last update: 2021-12-05 17:48:03 UTC


README

A php library for interacting with Yamaha MusicCast speakers.

Build Status

Based on the API specification found at https://jayvee.com.au/downloads/commands/yamaha/YXC_API_Spec_Basic.pdf

Updated API specs on 2017/04: https://www.pdf-archive.com/2017/04/21/yxc-api-spec-advanced/yxc-api-spec-advanced.pdf

Requirements

PHP >= 5.6 Guzzle library, (optional) PHPUnit to run tests.

Install

Download Composer

$ curl -s http://getcomposer.org/installer | php

Via composer

$ composer require granddam/php-musiccast-api php-http/guzzle6-adapter

You can install any adapter you want but guzzle is probably fine for what you want to do.

Examples

Start all groups playing music

require 'vendor/autoload.php';

$musicCast = new MusicCast\Network();
$controllers = $musicCast->getControllers();
foreach ($controllers as $controller) {
    echo $controller->getGroup() + "\n";
    echo "\tState: " . $controller->getStateName() . "\n";
    $controller->play();
}

Enabling events

Yamaha can notify you directly in case of changes. The events are spread out as UDP unicast packets. In order to receive these packets you must subscribe every 10 minutes, else the subscription will expire.

Only the IP that requests the subscription will receive the events.

The default port is 41100.

$yamaha->api('events')->subscribe();

Using php sockets to read the events

Pretty easy using Clue's socket wrapper.

$ composer require clue/socket-raw
$factory = new \Socket\Raw\Factory();
$socket = $factory->createUdp4();
$socket->bind('0.0.0.0:41100');

while(true) {
    $data = $socket->read(5120);
    $result = json_decode($data, true);
    
    print_r($result);
}

Testing

$ composer test