# Building my own mp3 player in MMBasic

**URL:** <https://forum.clockworkpi.com/t/building-my-own-mp3-player-in-mmbasic/16510>\
**Category:** PicoCalc\
**Created:** [April 3, 2025, 11:32pm UTC](https://forum.clockworkpi.com/t/building-my-own-mp3-player-in-mmbasic/16510 "2025-04-03T23:32:55Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Dominikus\_Koch](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/dominikus_koch/32/11230_2.png) [@Dominikus\_Koch](https://forum.clockworkpi.com/u/Dominikus_Koch)\
**Post date:** [April 9, 2025, 9:47am UTC](https://forum.clockworkpi.com/t/building-my-own-mp3-player-in-mmbasic/16510/7 "2025-04-09T09:47:01Z")

</div>

Hi 🙂  
Thanks for your reply. I reworked my code myself a few days ago and added a path variable for the music folder too. I added a Cover view and a better refresh (with no blinking while changing tracks).

Furthermore, I don’t like random music shuffling, but I like to have the choice, so I take your random function as a commentary - so everybody can decide to use it or not.

> [@Flavio\_Villanustre](#):
>
> I also found out that OPTION CPUSPEED 200000 is required with the PI Pico 2w, in case others get an error about insufficient CPU speed.

You are right here

> [@Music on the picocalc](https://forum.clockworkpi.com/t/music-on-the-picocalc/16426):
>
> How would I play music on the picocalc? I am assuming songs could be stored in a file on the sd card. Ideas?

[adcockm](https://forum.clockworkpi.com/u/adcockm)  
said you can go up to 380000 with a Pico 2 - and he is right.

**My new Code with**

- Album Cover (4Bit 320\*320px bmp)
- better path variables for easier use
- [Flavio\_Villanustre](https://forum.clockworkpi.com/u/Flavio_Villanustre) shuffle function
- [Flavio\_Villanustre](https://forum.clockworkpi.com/u/Flavio_Villanustre) better stop function

```auto
'music
x=1
y=0
tmp$=""
Dim mp3$(100)
path$ = "b:\music\"

f1=1
f$=Dir$(path$ + "*.mp3",FILE)
cover$ = "cover.bmp"

Do While f$<>""
   mp3$(f1)=path$+f$
   f$=Dir$()
   f1=f1+1
Loop

'Randomize
'For i=1 To f1 - 1
' k$ = mp3$(i)
' j = Rnd(f1 - 1) + 1
' mp3$(i) = mp3$(j)
' mp3$(j) = k$
'Next

CLS
On error skip 1
Load image(path$ + cover$)
Print "########################"
Print "####### SiD Music ######"
Print "########################"
Do While x < f1
  Print @(0,40) mp3$(x)
  Open mp3$(x) For input As #1
  y = Lof(1)
  Close #1
  Play mp3 mp3$(x)
  z=Cint(((y*8)/320000))

  Do While z > 0
     k$ = Inkey$

    If k$ <> "" Then
      Select Case Asc(k$)
        Case 131: Play stop
                  z=0
        Case 130: Play stop
                  x = x-2
                  z=0
        Case 32: Play stop
                        CLS
	                x=f1
                        z=0
      End Select
    End If

    Pause 100
    z=z-1
    min = Int(z / 60)
    sec = z Mod 60
    If sec < 10 Then
      tmp$ = Str$(min)+":0"+Str$(sec)+" "
    Else
      tmp$ = Str$(min)+":"+Str$(sec)+" "
    EndIf
    Print @(0,60) tmp$
    Pause (900)
   Loop
  Play stop
  x=x+1
Loop

```

---

_[View the full topic](https://forum.clockworkpi.com/t/building-my-own-mp3-player-in-mmbasic/16510)._
