My usual approach to switch between stations, was to first set the volume to zero, then a stopSong, connect to the new url, and if the new stream is running, set the volume back to the normal level. Something like this:
stream.setVolume(0);
if(stream.isRunning())
{ stream.stopSong();
}
stream.connectToHost(TargetUrl);
if(stream.isRunning())
{ stream.setVolume(volumevalue); // restore volume
}
This method, more often than not, gives audible clicks or odd (short) snippets of unwanted sound. I tried various 'solutions' such as adding delays before turning up the volume again, using fading volume slowly up, all not very elegant or 100% fixing the problem.
But now I found a new method. Instead of restoring the volume after a plain connect, wait for the codec callback, and let that handle the volume restore.
// Called when codec is detected
void codecCallBack(const char *codec)
{ Serial.printf("codec: %s\n", codec);
stream.setVolume(volumevalue); // restore volume
}
Thought let's share this idea, for me this works very satisfying. No clicks, no odd snippets, just a smooth switch.
My usual approach to switch between stations, was to first set the volume to zero, then a stopSong, connect to the new url, and if the new stream is running, set the volume back to the normal level. Something like this:
This method, more often than not, gives audible clicks or odd (short) snippets of unwanted sound. I tried various 'solutions' such as adding delays before turning up the volume again, using fading volume slowly up, all not very elegant or 100% fixing the problem.
But now I found a new method. Instead of restoring the volume after a plain connect, wait for the codec callback, and let that handle the volume restore.
Thought let's share this idea, for me this works very satisfying. No clicks, no odd snippets, just a smooth switch.