snapshot
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/Communication/HTTP/URLStream.h"
|
||||
#include "AudioTools/Disk/AudioSourceURL.h"
|
||||
|
||||
namespace audio_tools {
|
||||
|
||||
/**
|
||||
* @brief URLStream which provides the ICY Http Parameters
|
||||
*
|
||||
*/
|
||||
class AudioSourceIcyUrl : public AudioSourceURL {
|
||||
public:
|
||||
template<typename T, size_t N>
|
||||
AudioSourceIcyUrl(URLStream& urlStream, T(&urlArray)[N], const char* mime, int start=0)
|
||||
: AudioSourceURL(urlStream, urlArray, mime,start) {
|
||||
}
|
||||
|
||||
const char *icyValue(const char* name) {
|
||||
return actual_stream->httpRequest().reply().get(name);
|
||||
}
|
||||
const char *icyName() {
|
||||
return icyValue("icy-name");
|
||||
}
|
||||
const char *icyDescription() {
|
||||
return icyValue("icy-description");
|
||||
}
|
||||
const char *icyGenre() {
|
||||
return icyValue("icy-genre");
|
||||
}
|
||||
|
||||
/// Returns the last section of a url: https://22323.live.streamtheworld.com/TOPRETRO.mp3 gives TOPRETRO.mp3
|
||||
const char *urlName(){
|
||||
const char* result = "";
|
||||
StrView tmpStr(toStr());
|
||||
int pos = tmpStr.lastIndexOf("/");
|
||||
if (pos>0){
|
||||
result = toStr()+pos+1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Returns the icy name if available otherwise we use our custom logic
|
||||
const char* name() {
|
||||
StrView result(icyName());
|
||||
if (result.isEmpty()){
|
||||
result.set(urlName());
|
||||
}
|
||||
return result.c_str();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
# A Simple Streaming Audio Player
|
||||
|
||||
This is just a simple example which demonstrates how to use your own subclasses to add additional functionality.
|
||||
|
||||
We provide the URL ICY parameters in our own AudioSourceIcyUrl subclass!
|
||||
|
||||
### Dependencies
|
||||
|
||||
- https://github.com/pschatzmann/arduino-audio-tools
|
||||
- https://github.com/pschatzmann/arduino-libhelix
|
||||
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* @file player-url-i2s.ino
|
||||
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-player/player-url_subclass-i2s/README.md
|
||||
*
|
||||
* @author Phil Schatzmann
|
||||
* @copyright GPLv3
|
||||
*/
|
||||
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
|
||||
#include "AudioSourceIcyUrl.h"
|
||||
#include "AudioTools/Communication/AudioHttp.h"
|
||||
|
||||
|
||||
const char *urls[] = {
|
||||
"http://stream.srg-ssr.ch/m/rsj/mp3_128",
|
||||
"http://stream.srg-ssr.ch/m/drs3/mp3_128",
|
||||
"http://stream.srg-ssr.ch/m/rr/mp3_128",
|
||||
"http://sunshineradio.ice.infomaniak.ch/sunshineradio-128.mp3",
|
||||
"http://streaming.swisstxt.ch/m/drsvirus/mp3_128"
|
||||
};
|
||||
const char *wifi = "wifi";
|
||||
const char *password = "password";
|
||||
|
||||
URLStream urlStream(wifi, password);
|
||||
AudioSourceIcyUrl source(urlStream, urls, "audio/mp3");
|
||||
I2SStream i2s;
|
||||
MP3DecoderHelix decoder;
|
||||
AudioPlayer player(source, i2s, decoder);
|
||||
|
||||
// additional controls
|
||||
const int volumePin = A0;
|
||||
Debouncer nextButtonDebouncer(2000);
|
||||
const int nextButtonPin = 13;
|
||||
|
||||
|
||||
void printName() {
|
||||
Serial.print("icy name: ");
|
||||
Serial.println(source.icyName());
|
||||
Serial.print("Url name: ");
|
||||
Serial.println(source.urlName());
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// setup output
|
||||
auto cfg = i2s.defaultConfig(TX_MODE);
|
||||
i2s.begin(cfg);
|
||||
|
||||
// setup player
|
||||
player.begin();
|
||||
printName();
|
||||
}
|
||||
|
||||
// Sets the volume control from a linear potentiometer input
|
||||
void updateVolume() {
|
||||
// Reading potentiometer value (range is 0 - 4095)
|
||||
float vol = static_cast<float>(analogRead(volumePin));
|
||||
// min in 0 - max is 1.0
|
||||
player.setVolume(vol/4095.0);
|
||||
}
|
||||
|
||||
|
||||
// Moves to the next url when we touch the pin
|
||||
void updatePosition() {
|
||||
if (digitalRead(nextButtonPin)) {
|
||||
Serial.println("Moving to next url");
|
||||
if (nextButtonDebouncer.debounce()){
|
||||
player.next();
|
||||
printName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
//updateVolume(); // remove comments to activate volume control
|
||||
//updatePosition(); // remove comments to activate position control
|
||||
player.copy();
|
||||
}
|
||||
Reference in New Issue
Block a user