Music player

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Music player

Post by Henko »

Hi, i use this music player to play my own (digitized) LP's and CD's.
It has a fix size and fits on an iPhone 5S and up.
B83D5F5A-7C8A-4A96-A0D9-81E7559EF191.jpeg
B83D5F5A-7C8A-4A96-A0D9-81E7559EF191.jpeg (322.88 KiB) Viewed 6481 times
The code:

Code: Select all

' music player (version Dec. 11th, 2019)
'
init_program()
new_track1:
fx=xs+10 ! fy=ys+10 ! fw=sw-100 ! fh=sh-200
f$=file_select$("music & sounds","mp3,wav",fx,fy,fw,fh,1,1,.8)
if f$="" then new_track1 else fsnr=file_select$.nr
new_track2:
music m$ load f$ ! tmax=music_length(m$) ! to=-1
music m$ volume slider_value("vol") ! music m$ play
do slowdown
t=music_time(m$)/tmax ! tp=int(100*t)
if tp<>to then
  slider "prog" value t ! xp=.xs+t*(.sw-75)+30 ! yp=.ys+425
  fill color .8,.8,.8 ! fill rect xs+28,yp to xs+sw-10,yp+12
  if tp> 5 then draw text "0%" at xs+28,yp
  if tp<90 then draw text "100%" at xs+sw-50,yp
  draw text tp&"%" at xp,yp ! to=tp
  end if
if slider_changed("prog") then
  music m$ time slider_value("prog")*tmax
  end if
if slider_changed("vol") then music m$ volume slider_value("vol")
if bp("sele") then
  music m$ stop ! fill rect xp-25,yp to xp+40,yp+12
  slider "prog" value 0 ! goto new_track1
  end if
if bp("loop") then
  loop+=1 ! loop=loop%3
  fill rect 460,ys+490 to 530,ys+505
  if loop=1 then draw text "loop" at 482,ys+490
  if loop=2 then draw text "shuffle" at 472,ys+490
  end if
if bp("quit") then stop
if not music_playing(m$) and not paused then
  if loop=0 then new_track1
  if loop=1 then ! music m$ time 0 ! to=-1 ! music m$ play ! end if
  if loop=2 then
    fsnr=rnd(file_select$.nf)
    list "xf%cg/te" select fsnr
    f$=file_select$.fil$(fsnr) ! goto new_track2
    end if
  end if
if bp("play") then
  if paused then
    music m$ play ! button "play" text chr$(9209) ! paused =0
    else
    music m$ stop ! button "play" text chr$(57914) ! paused =1
    end if
  end if
if bp("prev") and fsnr>0 then
  do
    if fsnr=0 then no_prev
    fsnr-=1 ! f$=file_select$.fil$(fsnr)
    until not is_cd(f$)
  list "xf%cg/te" select fsnr ! goto new_track2
  no_prev:
  end if
if bp("next") then
  do
    if fsnr=file_select$.nf-1 then no_next
    fsnr+=1 ! f$=file_select$.fil$(fsnr) 
    until not is_cd(f$)
  list "xf%cg/te" select fsnr ! goto new_track2
  no_next:
  end if
until forever
end

def init_program()
option angle degrees ! set underground on
graphics ! graphics clear .8,.8,.8
draw color 0,0,0 ! fill color .8,.8,.8
set toolbar off
get screen size .sw,.sh
if device_type$="iPhone" then ! .device=0 ! .xs=0 ! .ys=0
  else
 .device=1 ! .xs=(.sw-320)/2 ! .ys=(.sh-568)/2 ! .sw=320 ! .sh=568
  end if
if .device=1 then
  xo=.xs-t ! yo=.ys-t ! xe=.xs+.sw+t ! ye=.ys+.sh+t
  win(xo,yo,xe,ye,12,3,0,0,1) ! draw color 0,0,0
  end if
xp=.xs+.sw-60 ! yp=.ys+330
slider "vol" value 0.3 at xp,yp size .sh-230 angle -90
draw text "Vol" at xp-8,yp+20
dy=.sh-261 ! draw size 1 ! draw font size 14
for i=0 to 1 step .1
  y=yp-i*dy ! draw line xp-5,y to xp+5,y
  draw text i at xp+20,y-6
  next i
xp=.xs+20 ! yp=.ys+390 ! dx=(.sw-46)/1.1
slider "prog" value 0 at xp,yp size .sw-40 angle 0
for i=0 to 1 step .1
  x=xp+i*dx+16 ! draw line x,yp+12 to x,yp+22
  next i
draw text "0%" at xp+8,yp+35
draw text "100%" at .xs+.sw-50,yp+35
xp=.xs+16 ! yp=.ys+450 ! bs=40
set buttons custom ! set buttons font size bs
button "prev" text chr$(9198) at xp+60,yp size bs,bs
button "next" text chr$(9197) at xp+180,yp size bs,bs
button "play" text chr$(9209) at xp+120,yp size bs,bs
button "loop" text chr$(9851) at xp+240,yp size bs,bs
button "sele" text chr$(9195) at xp,yp size bs,bs
set buttons default ! set buttons font size 16
draw text "new    prev   st/st  next" at xp+7,yp+bs
xp=.xs+.sw/2-60 ! yp=.ys+.sh-40
button "quit" text "Quit program" at xp,yp size 120,30
end def

' paged filesector
' list files with extension ext$ from current directory and
'      one level lower subdirectories
' background remains unchanged after fileselector closes
' title$ = title of the fileselector window
' aux$ = selectable file extensions, comma separated
'        If ext$="" then all files will be displayed in the list
'
def file_select$(title$,aux$,xs,ys,ww,hh,R,G,B)
name$= "xf%cg/te"
page name$ set ! page name$ frame xs,ys,ww,hh
page name$ color R,G,B,0
fill color R,G,B ! set buttons custom
button name$&"win" text "" at 0,0 size ww,hh ! set buttons default
button name$&"title" text title$ at 1,1 size ww-2,27
button name$&"cancel" text " Cancel " at 10,hh-50 size 70,40
button name$&"up" text chr$(9035) at 90,hh-50 size 40,40
button name$&"ok" text " OK " at ww-80,hh-50 size 70,40
button name$&"up" hide
set lists font size 16
again:
if level=1 then button name$&"up" show
auxe$=aux$ ! if level=0 then auxe$&=",cd"
split auxe$ to ext$,n_ext with ","
dir "" list files fil$,nfiles
if level=0 then dir "" list dirs dir$,ndirs else ndirs=0
nlist=nfiles+ndirs
dim ff$(nlist) ! nf=0
for i=0 to nfiles-1 ! f$=fil$(i) ! pos=instr(f$,".")
  if pos>-1 then
    e$=right$(f$,len(f$)-pos-1)
    for k=0 to n_ext-1
      if e$=ext$(k) then ! nf+=1 ! ff$(nf-1)=f$ ! end if
      next k
    end if
  next i
for i=0 to ndirs-1 ! nf+=1 ! ff$(nf-1)=dir$(i) ! next i
if nf then
  dim fil$(nf) ! for i=0 to nf-1 ! fil$(i)=ff$(i) ! next i
  end if
sort fil$ ! set lists custom ! fill color R,G,B
list name$ text fil$ at 3,33 size ww-7,hh-96
page name$ show
nr=-1 ! fsel$="" 
do slowdown
  if bp("quit") then stop
  if bp(name$&"cancel") then ! fsel$="" ! break ! end if
  if bp(name$&"up") then
    dir ".." set ! level=0 ! button name$&"up" hide ! goto again
    end if
  nr=list_selected(name$) ! if nr=-1 then continue
  fsel$=fil$(nr)
  if bp(name$&"ok") then 
    if level=1 or not is_cd(fsel$) then break
    to_cd(fsel$) ! goto again
    end if
  until forever
page "" set ! return fsel$
end def

def is_cd(f$)
pos=instr(f$,".") ! e$=right$(f$,len(f$)-pos-1)
if e$="cd" then return 1 else return 0
end def

def to_cd(f$)
dir f$ set ! button name$&"up" show ! file_select$.level=1
end def

def win(xo,yo,xe,ye,d,t,r,g,b)
pi=atan(1)! pi2=2*pi ! pi4=4*pi ! pi6=6*pi
fill rect xo,yo to xe,ye
t2=t/2 ! xo+=t2 ! yo+=t2 ! xe-=t2 ! ye-=t2
draw color r,g,b ! draw size t
draw arc xo+d,ye-d,d,pi2,pi4,0 ! draw arc xe-d,ye-d,d,pi2,0,1
draw arc xe-d,yo+d,d,0,pi6,1 ! draw arc xo+d,yo+d,d,pi6,pi4,1
draw line xo+d,yo to xe-d,yo ! draw line xo+d,ye to xe-d,ye
draw line xo,yo+d to xo,ye-d ! draw line xe,yo+d to xe,ye-d
end def

def bp(a$) = button_pressed(a$)

Post Reply