{"id":3575,"date":"2021-10-14T10:33:41","date_gmt":"2021-10-14T08:33:41","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=3575"},"modified":"2025-04-09T11:36:10","modified_gmt":"2025-04-09T09:36:10","slug":"a-simple-streaming-mp3-player","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/","title":{"rendered":"A Basic Arduino Streaming MP3 Player"},"content":{"rendered":"<p>Yesterday I was finally resolving some stability issues in my <a href=\"https:\/\/stream.live.vc.bbcmedia.co.uk\/bbc_world_service\">URLStream<\/a> class and I wanted to take the opportunity to highlight  that it is pretty simple to build <strong>a simple mp3 streaming audio player<\/strong> using the Stream API of my <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\">Arduino Audio Tools<\/a> library. You just need to copy the result from an URLStream to your output stream:<\/p>\n<h2>The Arduino Sketch<\/h2>\n<p>In this example Arduino sketch I am streaming <strong>BBC World Service<\/strong> to the analog output pins using an <strong>ESP32 Microcontroller<\/strong>:<\/p>\n<pre><code><br \/>#include \"AudioTools.h\"\n#include \"AudioTools\/AudioCodecs\/CodecMP3Helix.h\"\n\nURLStream url(\"SSID\",\"password\");\nAnalogAudioStream out; \/\/ final output of decoded stream\nEncodedAudioStream dec(out, new MP3DecoderHelix()); \/\/ Decoding stream\nStreamCopy copier(dec, url); \/\/ copy url to decoder\n\nvoid setup(){\n  Serial.begin(115200);\n  AudioLogger::instance().begin(Serial, AudioLogger::Info);  \n\n  \/\/ setup out\n  out.begin(out.defaultConfig(TX_MODE););\n\n  \/\/ setup out based on sampling rate provided by decoder\n  dec.begin();\n\n  \/\/ BBC World - mp3 radio\n  url.begin(\"https:\/\/stream.live.vc.bbcmedia.co.uk\/bbc_world_service\",\"audio\/mp3\");\n  Serial.println(\"starting to play...\");\n}\n\nvoid loop(){\n  copier.copy();\n}\n<\/code><\/pre>\n<p>I think the overall logic is quite easy to understand: we use the <strong>EncodedAudioStream<\/strong> with a Decoder as output which sends the decoded result to the final output <strong>AnalogAudioStream<\/strong> device. The only specific thing to mention here is, that the AnalogAudioStream output device needs to know the number of channels, the bit size and the sample rate to play back the audio correctly and we do not know this information when we setup the output yet, so we just start with some default settings. Fortunately, the decoder has some automatic notification mechanism!<\/p>\n<h2>The Output<\/h2>\n<p>On the ESP32 the analog output is available on GPIO25 (Channel 1) and GPIO26 (Channel 2). You can use a piezo electric element or connect some <strong>earphones<\/strong>:<br \/>\n<img decoding=\"async\" src=\"https:\/\/pschatzmann.github.io\/Resources\/img\/earphones.jpg\" alt=\"Earphones\" \/><\/p>\n<h2>Dependencies<\/h2>\n<p>You need to install the following libraries:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\">arduino-audio-tools<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/pschatzmann\/arduino-libhelix\">arduino-libhelix<\/a><\/li>\n<\/ul>\n<h2>Source code<\/h2>\n<p>You can find the source code for <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\/tree\/main\/examples\/\">this and other streaming examples<\/a> on Github.<\/p>\n<h2>Final Notes<\/h2>\n<p>This example works with Arduino ESP32 and with PlatformIO. You can replace the helix decoder with <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\/wiki\/Encoding-and-Decoding-of-Audio\">any other supported decoder<\/a>.  In the example we used the AnalogAudioStream output class but you can replace it with any other supported <strong>Audio Sink<\/strong>. For details please consult the <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\">Readme of the project<\/a>.<\/p>\n<p>In the next Blog, I will demonstrate how to set up streaming with the AudioPlayer class&#8230;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday I was finally resolving some stability issues in my URLStream class and I wanted to take the opportunity to highlight that it is pretty simple to build a simple mp3 streaming audio player using the Stream API of my Arduino Audio Tools library. You just need to copy the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3546,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[20,22],"tags":[],"class_list":["post-3575","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-machine-sound"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>A Basic Arduino Streaming MP3 Player - Phil Schatzmann<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A Basic Arduino Streaming MP3 Player - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"Yesterday I was finally resolving some stability issues in my URLStream class and I wanted to take the opportunity to highlight that it is pretty simple to build a simple mp3 streaming audio player using the Stream API of my Arduino Audio Tools library. You just need to copy the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-14T08:33:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-09T09:36:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/10\/mp3.png\" \/>\n\t<meta property=\"og:image:width\" content=\"316\" \/>\n\t<meta property=\"og:image:height\" content=\"159\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"pschatzmann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"pschatzmann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/10\\\/14\\\/a-simple-streaming-mp3-player\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/10\\\/14\\\/a-simple-streaming-mp3-player\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"A Basic Arduino Streaming MP3 Player\",\"datePublished\":\"2021-10-14T08:33:41+00:00\",\"dateModified\":\"2025-04-09T09:36:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/10\\\/14\\\/a-simple-streaming-mp3-player\\\/\"},\"wordCount\":299,\"commentCount\":6,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/10\\\/14\\\/a-simple-streaming-mp3-player\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/mp3.png\",\"articleSection\":[\"Arduino\",\"Machine Sound\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/10\\\/14\\\/a-simple-streaming-mp3-player\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/10\\\/14\\\/a-simple-streaming-mp3-player\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/10\\\/14\\\/a-simple-streaming-mp3-player\\\/\",\"name\":\"A Basic Arduino Streaming MP3 Player - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/10\\\/14\\\/a-simple-streaming-mp3-player\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/10\\\/14\\\/a-simple-streaming-mp3-player\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/mp3.png\",\"datePublished\":\"2021-10-14T08:33:41+00:00\",\"dateModified\":\"2025-04-09T09:36:10+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/10\\\/14\\\/a-simple-streaming-mp3-player\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/10\\\/14\\\/a-simple-streaming-mp3-player\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/10\\\/14\\\/a-simple-streaming-mp3-player\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/mp3.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/mp3.png\",\"width\":316,\"height\":159},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/10\\\/14\\\/a-simple-streaming-mp3-player\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"A Basic Arduino Streaming MP3 Player\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\",\"name\":\"Phil Schatzmann Consulting\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\",\"name\":\"pschatzmann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"width\":305,\"height\":305,\"caption\":\"pschatzmann\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A Basic Arduino Streaming MP3 Player - Phil Schatzmann","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/","og_locale":"en_US","og_type":"article","og_title":"A Basic Arduino Streaming MP3 Player - Phil Schatzmann","og_description":"Yesterday I was finally resolving some stability issues in my URLStream class and I wanted to take the opportunity to highlight that it is pretty simple to build a simple mp3 streaming audio player using the Stream API of my Arduino Audio Tools library. You just need to copy the [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/","og_site_name":"Phil Schatzmann","article_published_time":"2021-10-14T08:33:41+00:00","article_modified_time":"2025-04-09T09:36:10+00:00","og_image":[{"width":316,"height":159,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/10\/mp3.png","type":"image\/png"}],"author":"pschatzmann","twitter_card":"summary_large_image","twitter_misc":{"Written by":"pschatzmann","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"A Basic Arduino Streaming MP3 Player","datePublished":"2021-10-14T08:33:41+00:00","dateModified":"2025-04-09T09:36:10+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/"},"wordCount":299,"commentCount":6,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/10\/mp3.png","articleSection":["Arduino","Machine Sound"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/","url":"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/","name":"A Basic Arduino Streaming MP3 Player - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/10\/mp3.png","datePublished":"2021-10-14T08:33:41+00:00","dateModified":"2025-04-09T09:36:10+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/10\/mp3.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/10\/mp3.png","width":316,"height":159},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/10\/14\/a-simple-streaming-mp3-player\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"A Basic Arduino Streaming MP3 Player"}]},{"@type":"WebSite","@id":"https:\/\/www.pschatzmann.ch\/home\/#website","url":"https:\/\/www.pschatzmann.ch\/home\/","name":"Phil Schatzmann Consulting","description":"","publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pschatzmann.ch\/home\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1","name":"pschatzmann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","width":305,"height":305,"caption":"pschatzmann"},"logo":{"@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png"}}]}},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/3575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/comments?post=3575"}],"version-history":[{"count":28,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/3575\/revisions"}],"predecessor-version":[{"id":6679,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/3575\/revisions\/6679"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/3546"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=3575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=3575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=3575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}