samvdb / php-musiccast-api
PHP Wrapper for Yamaha MusicCast API
Requires
- php: ^5.5 || ^7.0
- myclabs/php-enum: ^1.5
- php-http/cache-plugin: ^1.2
- php-http/client-common: ^1.3
- php-http/client-implementation: ^1.0
- php-http/discovery: ^1.0
- php-http/httplug: ^1.1
- psr/cache: ^1.0
- psr/http-message: ^1.0
- symfony/yaml: ^3.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- guzzlehttp/psr7: ^1.2
- nikic/php-parser: ^3.0
- php-http/guzzle6-adapter: ^1.0
- phpro/grumphp: ^0.11.1
- phpunit/php-code-coverage: ^4
- phpunit/phpunit: ^4.0 || ^5.5
- squizlabs/php_codesniffer: ^2.7
This package is not auto-updated.
Last update: 2024-11-09 21:11:59 UTC
README
DEPRECATED!!!!
grandDam improved this library alot, it includes tests and more functionality.
Use this fork Library instead!
composer require granddam/php-musiccast-api
DEPRECATED!!!!
A simple wrapper for the Yamaha MusicCast API. Not all call's have been implemented yet so pull requests are welcome!
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
Update
The API pdf's can also be found in this repository.
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 samvdb/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.
Creating a client
$yamaha = new MusicCast\Client([ 'host' => 'localhost', 'port' => 80, // default value ]);
Using the API
$result = $yamaha->api('zone')->status('main'); print_r($result);
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
Credits
This api is highly inspired by the excellent Github api client made by KnpLabs!