5 - Music Player Control Widget
The rarely used Music Player Control Widget… one of these days soon to control actual music on the RPi
Right now this is just a working demo… controlling something (right now just the output of the display) via the Player buttons.
And also toggling between Stop and Play with a normal button (and synchronized feedback between the two)
// ----- Music Player Widget -----
var PlayerWidget = new blynk.VirtualPin(17); // Setup BrightPi IR LED Button
var PlayerButton = new blynk.VirtualPin(18); // Setup BrightPi IR LED Button
var PlayerDisplay = new blynk.VirtualPin(19); // Setup BrightPi IR LED Button
// Activates the Player via button
PlayerButton.on('write', function(param) { // Watches for button
if (param == 0) { // If PlayerButton OFF
PlayerWidget.write('stop'); // Stop PlayerWidget
blynk.syncVirtual(17); // Sync PlayerWidget to process command
} else if (param == 1) { // If PlayerButton ON
PlayerWidget.write('play'); // Play PlayerWidget
blynk.syncVirtual(17); // Sync PlayerWidget to process command
}
});
// Player functions
PlayerWidget.on('write', function(param) { // Watches for PlayerWidget
PlayerDisplay.write(param); // Shows Player Widget output on Display Widget
if (param == 'stop') { // If PlayerWidget 'stop'
//
PlayerButton.write(0); // Toggle PlayerButton OFF
// Do something to STOP music/video/etc.
//
} else if (param == 'play') { // If PlayerWidget 'play'
//
PlayerButton.write(1); // Toggle PlayerButton OON
// Do something to PLAY music/video/etc.
//
} else if (param == 'prev') { // If PlayerWidget 'play'
//
// Do something to skip BACKWARD to music/video.etc.
//
} else if (param == 'next') { // If PlayerWidget 'play'
//
// Do something to skip FORWARD to music/video/etc.
//
}
});