Skip to content

Instantly share code, notes, and snippets.

@Staars
Created June 13, 2025 11:31
Show Gist options
  • Save Staars/f83fb389695d4845a16ca43cdfd1a1ae to your computer and use it in GitHub Desktop.
Save Staars/f83fb389695d4845a16ca43cdfd1a1ae to your computer and use it in GitHub Desktop.
Simple MP3-Player for upcoming i2s driver version
class PLAYER
var mp3s, mp3_index
def init()
import path
import string
var d = path.listdir("/")
self.mp3s = []
self.mp3_index = 0
for f:d
if string.endswith(f,".mp3")
log(f"Found MP3 file: {f}")
self.mp3s.push(f)
end
end
log(f"playlist: {self.mp3s}")
tasmota.add_rule("event#i2splay=ended", /->self.next_song())
if size(self.mp3s) == 0
log("No MP3 files found in root directory", 1)
else
log(f"Found {size(self.mp3s)} MP3 files")
self.next_song()
end
end
def next_song()
if self.mp3_index < size(self.mp3s)
log(f"Next song index: {self.mp3_index}")
else
log(f"Restarting song list")
self.mp3_index = 0
end
var song = self.mp3s[self.mp3_index]
log(f"Playing song: {song}")
tasmota.cmd(f"i2splay {song}")
self.mp3_index += 1
end
def stop()
log("Stopping playback")
tasmota.remove_rule("event#i2splay=ended")
tasmota.cmd("i2sstop")
end
end
var p = PLAYER()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment