I am having troubles getting the media Player Widget to switch icons between the Play Arrow and the Stop Box. I can change the label, but not the icon. All other controls I’m using in the app seem to work OK.
I am running this on an Adafruit Feather M0 using Arduino library version 0.4.6. And I’m running the app on both an iPad and iPhone (does the same on both). The version says 2.8.6 on the iPad.
Any help would be appreciated. Below is the code snipped causing me problems. I read some earlier forum threads with this problem and it seemed to have been resolved so maybe it’s something I’m missing. Thanks for any suggestions…
Mark
#define PIN_SHOWS_MEDIA_CONTROL V2 // Press Media Control
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// --- Switch_0 Was Pressed ---
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (! digitalRead(BUTTON_A))
{
Serial.println("Button 0 Pressed");
Blynk.setProperty(PIN_SHOWS_MEDIA_CONTROL, "isOnPlay", "false"); // Doesn't Work
Blynk.setProperty(PIN_SHOWS_MEDIA_CONTROL, "label", "Paused..."); // Works OK
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// --- Switch_1 Was Pressed ---
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (! digitalRead(BUTTON_B))
{
Serial.println("Button 1 Pressed");
Blynk.setProperty(PIN_SHOWS_MEDIA_CONTROL, "isOnPlay", "true"); // Doesn't work
Blynk.setProperty(PIN_SHOWS_MEDIA_CONTROL, "label", "Playing..."); // Works OK
}
Thank you for your quick reply. Jamin, I tried using HIGH and LOW with no change. Costas, I believe I ran across an earlier thread of yours helping somebody else. What I have is basically what you show. So I think that there is either a new (reintroduced) bug in the Blynk system, or it may be something specific to my setup. I’m using the Adafruit Feather M0 (basically an Arduino Zero).
Below I’m attaching a simple sketch that I’m hoping somebody can load and verify if the control works on their system. I’ve tried to cut it down to the bare bones. Knowing if it works for somebody else with the current Blynk version would help me narrow it down. The sketch simply swaps the Media Player between Pause and Stop every 4 seconds. On mine I see the Media Player title changes but the icon (square or triangle) never changes.
Thanks for any help!
Mark
// ***************************************************************************
// Blynk Media Control Test
// ***************************************************************************
#include <SPI.h>
#include <Ethernet2.h> // For Feather M0
#include <BlynkSimpleEthernet2.h> // For FeatherM0
// ===================================
// Ethernet Client
// ===================================
// The IP address will be dependent on your local network:
byte ethernetMACAddress[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetClient client;
char auth[] = "Your Key Here...";
// ===================================
// PINS
// ===================================
#define PIN_SHOWS_MEDIA_CONTROL V2 // Media Control
#define PIN_LED_HEARTBEAT 13 // OnBoard LED
boolean toggle = 0;
uint32_t HeartBeatMillis = millis(); // Start Count
// ===========================================================================
// setup()
// ===========================================================================
void setup()
{
// ---HB LED ---
pinMode(PIN_LED_HEARTBEAT, OUTPUT);
digitalWrite(PIN_LED_HEARTBEAT, LOW);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Wait for Serial Port to become Active
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
while (!Serial)
{
// Wait!
}
Serial.begin(115200);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Get DHCP IP Before Proceeding
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Serial.print("DHCP - Getting IP: ");
Ethernet.begin(ethernetMACAddress); // Get IP from DHCP
Serial.println(Ethernet.localIP()); // Print IP
Blynk.begin(auth); // Begin Bllynk
Serial.println("Setup complete.\n");
HeartBeatMillis = millis(); // Start Count
}
// ===========================================================================
// loop()
// ===========================================================================
void loop()
{
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// HeartBeat LED and Media Control
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (millis() - HeartBeatMillis >= 4000) // If 4 Seconds have gone by...
{
// --- Toggle the On-Board LED ---
HeartBeatMillis = millis(); // Update Current Count
toggle = !toggle;
digitalWrite(PIN_LED_HEARTBEAT, toggle); // Flash Heartbeat LED
// --- Toggle Media Widget ---
if (toggle)
{
Blynk.setProperty(PIN_SHOWS_MEDIA_CONTROL, "isOnPlay", "true");
Serial.println("Set to Play!");
Blynk.setProperty(PIN_SHOWS_MEDIA_CONTROL, "label", "Play...");
}
else
{
Blynk.setProperty(PIN_SHOWS_MEDIA_CONTROL, "isOnPlay", "false");
Serial.println("Set to Pause!");
Blynk.setProperty(PIN_SHOWS_MEDIA_CONTROL, "label", "Paused...");
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Blynk Processing
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Blynk.run();
}
// ============================================================================
// Media Control Event - This function is not necessary, but shows the Icon does interact with the user
// ============================================================================
BLYNK_WRITE(PIN_SHOWS_MEDIA_CONTROL)
{
String action = param.asStr();
if (action == "play")
{
// Do something
}
if (action == "stop")
{
// Do something
}
if (action == "next")
{
// Do something
}
if (action == "prev")
{
// Do something
}
Blynk.setProperty(PIN_SHOWS_MEDIA_CONTROL, "label", action);
Serial.print(action);
Serial.println();
}
I found that the icon changes just fine, even if the device is offline. I just used the basic sketch in the demo, and labels change, Icon changes, everything seem to work as it is supposed to. I have no idea what the isOnPlay property is supposed to bring to the table? I commented them out and it made no difference, icon changes just like a button widget would.
BLYNK_WRITE(V29) // Media Player Function
{
String action = param.asStr();
if (action == "play") {
//Blynk.setProperty(V29, "isOnPlay", "true");
}
if (action == "stop") {
//Blynk.setProperty(V29, "isOnPlay", "false");
}
if (action == "next") {
// do stuff
}
if (action == "prev") {
// do stuff
}
Blynk.setProperty(V29, "label", action);
Serial1.print(action);
Serial1.println();
}
Thanks for responding. The issue I’m running into isn’t when the user is interacting with the iPad (or whatever device). That works fine. When I touch the control on the iPad it works fine and issues the actions you’re showing above.
The issue is when I try to change the control status from Arduino code. The situation is that my device is playing a file and the file ends so I have to send a command to the control to show that it’s stopped. I can send the a title to the control, but I can’t change the control state (which means that although I’ve told it to stop playing the icon still shows it’s playing).
I see that as a boolean trigger this is how I was able to toggle it off and on (in this case using a button widget, but any old 1/0 will do).
BLYNK_WRITE(V30) // Media Player Button Toggle
{
boolean action2 = param.asInt(); // Gets a 1 or 0 which is treated as True or False respectively
if (action2) { // If true
Blynk.setProperty(V29, "isOnPlay", "true");
Blynk.setProperty(V29, "label", "play");
} else { // if False
Blynk.setProperty(V29, "isOnPlay", "false");
Blynk.setProperty(V29, "label", "stop");
}
}
@MarkC Turns out this wasn’t initially implemented in iOS version. We’ll fix that.
As a temporarily workaround, try sending actual command “stop” to virtual pin. E.g.: