WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Boxes Examples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Cute Music Player

Keywords:   boxes functions music player mp3 mid wav rmi

if winexist("Music Player")
	winactivate("Music Player")
	exit
endif
addextender("wwsop32i.dll")

debugmode=0

if debugmode
	time=TimeYmdHms()
	debugfile=strcat(filepath(intcontrol(1004,0,0,0,0)),strreplace(time,":",""),".txt")
	debugtrace(1,debugfile)
	xtend=strcat(filepath(intcontrol(1004,0,0,0,0)),"WWZIP32I.DLL")
	zip=strcat(filepath(intcontrol(1004,0,0,0,0)),"DebugTrace.zip")
endif

IntControl(33,0,0,0,0)
 
index=0
playlist=""
list=""

PLFormat=`WWWDLGED,5.0`

PLCaption=`Playlist Viewer`
PLX=36
PLY=54
PLWidth=150
PLHeight=101
PLNumControls=9

PL01=`2,2,144,68,ITEMBOX,playlist2,DEFAULT`
PL02=`2,72,36,DEFAULT,PUSHBUTTON,DEFAULT,"Play",1`
PL03=`38,72,36,DEFAULT,PUSHBUTTON,DEFAULT,"Remove",2`
PL04=`74,72,36,DEFAULT,PUSHBUTTON,DEFAULT,"Add file...",3`
PL05=`38,84,36,DEFAULT,PUSHBUTTON,DEFAULT,"Move Up",4`
PL06=`74,84,36,DEFAULT,PUSHBUTTON,DEFAULT,"Move Down",5`
PL07=`2,84,36,DEFAULT,PUSHBUTTON,DEFAULT,"Close",6`
PL08=`110,72,36,DEFAULT,PUSHBUTTON,DEFAULT,"Open...",7`
PL09=`110,84,36,DEFAULT,PUSHBUTTON,DEFAULT,"Save As...",8`


Loadbox=4
bin=BinaryAlloc(128)
intcontrol(12,5,0,0,0)
mainbox=1
timebox=2
infobox=3

if RegexistValue(@REGCurrent,"Control Panel\Colors[ButtonFace]")
   bcd=Regqueryvalue(@REGCurrent,"Control Panel\Colors[ButtonFace]")
else
   bcd="192,192,192"
endif


hwnd=DllHwnd(winname())
sysmenu=DllCall(strcat(DirWindows(1),"USER32.DLL"),long:"GetSystemMenu",long:hwnd,long:0)
DllCall(strcat(DirWindows(1),"USER32.DLL"),long:"RemoveMenu",long:sysmenu,long:61488,long:0)
DllCall(strcat(DirWindows(1),"USER32.DLL"),long:"RemoveMenu",long:sysmenu,long:61440,long:0)
decimals(3)
x=1024.000/WinMetrics(0)
y=768.000/WinMetrics(1)
decimals(0)
x1=50*x
x2=400*x
y1=50*x
y2=375*x


WinPlaceSet(@normal,winname(),strcat(x1," ",y1," ",x2," ",y2))
boxopen("","")

Boxupdates(1,0)
BoxColor(mainbox,bcd,0)
BoxDrawRect(mainbox, "0,0,1000,1000",2)
wintitle(winname(),"Music Player")

BoxNew(timebox,"20,20,300,280", 1)
BoxColor(timebox,"0,0,128",0)
BoxDrawRect(timebox, "0,0,1000,1000", 1)
BoxTextColor(timebox,"255,255,255")
BoxTextFont(timebox, "Times New Roman", 600, 40, 0|0)

BoxDataTag(timebox, "clear")
BoxDrawText(timebox, "0,0,1000,1000", "0:00",1, 5)


if Regexistvalue(@REGCurrent,"Control Panel\Colors[Window]")
   win=Regqueryvalue(@REGCurrent,"Control Panel\Colors[Window]")
else
   win="255,255,255"
endif
if Regexistvalue(@REGCurrent,"Control Panel\Colors[WindowText]")
   txt=Regqueryvalue(@REGCurrent,"Control Panel\Colors[WindowText]")
else
   txt="0,0,0"
endif
BoxNew(infobox,"20,300,980,980", 1)
BoxColor(infobox,win,0)
BoxDrawRect(infobox, "0,0,1000,1000", 1)
BoxTextFont(infobox, "MS Sans Serif", 10, 40, 0|0)
BoxTextColor(infobox,txt)
boxdatatag(infobox,"clear")


BoxButtonDraw(mainbox,1,">/||","320,20,414,150")
BoxButtonDraw(mainbox,2,"|<","414,20,509,150")
BoxButtonDraw(mainbox,3,">|","509,20,603,150")
BoxButtonDraw(mainbox,5,"Open","603,20,791,150")
BoxButtonDraw(mainbox,6,"Exit","791,20,980,150")
BoxButtonDraw(mainbox,4,"[]","320,150,414,280")
BoxButtonDraw(mainbox,7,"<<","414,150,509,280")
BoxButtonDraw(mainbox,8,">>","509,150,603,280")
BoxButtonDraw(mainbox,9,"Playlist","603,150,980,280")
Boxupdates(1,2)

filetypes="All supported types|*.wav; *.mid; *.rmi; *.mp3; *.m3u|MP3 Music (*.mp3)|*.mp3|Wave Sound (*.wav)|*.wav|MIDI Music (*.mid; *.rmi)|*.mid; *.rmi|Playlists (*.m3u)|*.m3u"

autoplay=0
if param0>0
	if !fileexist(param1)
		Message("Error",strcat("Can not find '",param1,"'."))
		goto waiting
	endif
	if param0>1
		if strupper(param2)=="/PLAY" then autoplay=1
	endif
	file=param1
	goto reopen
endif

:waiting
can="waiting"

while !BoxButtonStat(mainbox,5)
if BoxButtonStat(mainbox,6) then goto close
BoxButtonStat(mainbox,1)
BoxButtonStat(mainbox,2)
BoxButtonStat(mainbox,3)
BoxButtonStat(mainbox,4)
BoxButtonStat(mainbox,7)
BoxButtonStat(mainbox,8)
if BoxButtonStat(mainbox,9) then goto pl
endwhile

file=askfilename("Open","",filetypes,"",1)

:reopen
if strupper(fileextension(file))=="M3U"
	boxdataclear(infobox,"clear")
	Boxdrawtext(infobox, "20,20,980,980", "Please wait... loading playlist." ,1, 16)
	dirchange(filepath(file))
	fs=filesize(file)
	fr=fileopen(file,"READ")
	read=0
	list=""
	read=fileread(fr)
	aStatusBar(0,"Music Player","Opening playlist",fs,0)
	plpos=0
	while read!="*EOF*"
		plpos=plpos+strlen(read)+2
		aStatusBar(1,"Music Player","Opening playlist",fs,plpos)
		if strsub(read,1,1)=="\" then read=strcat(strsub(dirget(),1,2),read)
		if strsub(read,2,1)!=":" then read=strcat(dirget(),read)
		ext=strupper(fileextension(read))
		if !(fileexist(read)&&(ext=="MP3"||ext=="WAV"||ext=="MID"||ext=="RMI")) then goto tag1
		device="sequencer"
		if ext=="MP3" then device="mpegvideo"
		if ext=="WAV" then device="waveaudio"
		errormode(@off)
		pm=PlayMedia(strcat("open ",device,"!",filenameshort(read)," alias music"))
		if pm=="" then goto tag1
		errormode(@cancel)
		Playmedia("close music")
		list=iteminsert(read,-1,list,"	")
		:tag1
		read=fileread(fr)
	endwhile
	aStatusBar(2,"Music Player","Opening playlist",fs,plpos)
	fileclose(fr)
else
	list=file
	device="sequencer"
	ext=strupper(fileextension(file))
	if ext=="MP3" then device="mpegvideo"
	if ext=="WAV" then device="waveaudio"
	errormode(@off)
	pm=PlayMedia(strcat("open ",device,"!",filenameshort(file)," alias music"))
	if pm==""
		Message("Error","This file can not be played.")
		list=""
		filecount=itemcount(list,"	")
		errormode(@cancel)
		goto waiting
	endif
	errormode(@cancel)
	Playmedia("close music")
endif


filecount=itemcount(list,"	")

if filecount==0
	Message("Error","No valid files can be played.")
	goto waiting
endif

playlist=""
for n=1 to filecount
	entry=itemextract(n,list,"	")
	entrytitle=fileroot(entry)
	if strupper(fileextension(entry))=="MP3"
		BinaryReadEx(bin,0,entry,filesize(entry)-128,128)
		if BinaryPeekStr(bin,0,3)=="TAG"
			title=strtrim(BinaryPeekStr(bin,3,30))
			artist=strtrim(BinaryPeekStr(bin,33,30))
			entrytitle=strcat(artist," - ",title)
		endif
	endif
	playlist=iteminsert(strcat(n,". ",entrytitle),-1,playlist,"	")
next


index=1
aft="stop"
if autoplay
	aft="play"
	autoplay=0
endif
gosub initialize

:stopped
	can="stopped"
	if winstate(winname())==@icon
		if winname()!=strcat("Music Player - ",title) then wintitle(winname(),strcat("Music Player - ",title))
	else
		if winname()!="Music Player" then wintitle(winname(),"Music Player")
	endif
	t=PlayMedia("status music position")
	decimals(0)
	t=t/1000
	t=TimeAdd("1:1:1:0:0:0",strcat("0:0:0:0:0:",t))
	m=itemextract(5,t,":")+0
	s=itemextract(6,t,":")
	t=strcat(m,":",s)
		if t!=pt
		boxdataclear(timebox,"clear")
		BoxDrawText(timebox, "0,0,1000,1000", t,1, 5)
		pt=t
	endif

	if BoxButtonStat(mainbox,1) then goto play
	aft="stop"
	if BoxButtonStat(mainbox,3) then goto adv
	if BoxButtonStat(mainbox,2) then goto rev
	BoxButtonStat(mainbox,4)
	if BoxButtonStat(mainbox,5) then goto openfile
	if BoxButtonStat(mainbox,6) then goto close
	if BoxButtonStat(mainbox,7) then gosub seekback
	if BoxButtonStat(mainbox,8) then gosub seekfor
	mode=playmedia("status music mode")
	if BoxButtonStat(mainbox,9) then goto PL
goto stopped

:playing
	can="playing"
	if PlayMedia("status music mode")=="stopped"
		Boxdataclear(timebox,"clear")
		BoxDrawText(timebox, "0,0,1000,1000", "0:00",1, 5)
		if index==filecount then goto stop
		goto adv
	endif
	if winstate(winname())==@icon
		if winname()!=strcat("Music Player (",t,") - ",title) then wintitle(winname(),strcat("Music Player (",t,") - ",title))
	else
		if winname()!="Music Player" then wintitle(winname(),"Music Player")
	endif

	t=PlayMedia("status music position")
	decimals(0)
	t=t/1000
	t=TimeAdd("1:1:1:0:0:0",strcat("0:0:0:0:0:",t))
	m=itemextract(5,t,":")+0
	s=itemextract(6,t,":")
	t=strcat(m,":",s)
		if t!=pt
		boxdataclear(timebox,"clear")
		BoxDrawText(timebox, "0,0,1000,1000", t,1, 5)
		pt=t
	endif

	if BoxButtonStat(mainbox,1) then goto paus
	aft="play"
	if BoxButtonStat(mainbox,3) then goto adv
	if BoxButtonStat(mainbox,2)
		if PlayMedia("status music position")<1000 then goto rev
		Playmedia("seek music to start")
		Playmedia("play music")
	endif
	if BoxButtonStat(mainbox,4) then goto stop
	if BoxButtonStat(mainbox,5) then goto openfile
	if BoxButtonStat(mainbox,6) then goto close
	if BoxButtonStat(mainbox,7) then gosub seekback
	if BoxButtonStat(mainbox,8) then gosub seekfor
	mode=playmedia("status music mode")
	if BoxButtonStat(mainbox,9) then goto PL
goto playing

:paused
	can="paused"
	if winstate(winname())==@icon
		if winname()!=strcat("Music Player (",t,") - ",title) then wintitle(winname(),strcat("Music Player (",t,") - ",title))
	else
		if winname()!="Music Player" then wintitle(winname(),"Music Player")
	endif

	t=PlayMedia("status music position")
	decimals(0)
	t=t/1000
	t=TimeAdd("1:1:1:0:0:0",strcat("0:0:0:0:0:",t))
	m=itemextract(5,t,":")+0
	s=itemextract(6,t,":")
	t=strcat(m,":",s)
		if t!=pt
		boxdataclear(timebox,"clear")
		BoxDrawText(timebox, "0,0,1000,1000", t,1, 5)
		pt=t
	endif

	if BoxButtonStat(mainbox,1) then goto play
	aft="pause"
	if BoxButtonStat(mainbox,3) then goto adv
	if BoxButtonStat(mainbox,2)
		if PlayMedia("status music position")<1000 then goto rev
		Playmedia("seek music to start")
		Playmedia("pause music")
	endif
	if BoxButtonStat(mainbox,4) then goto stop
	if BoxButtonStat(mainbox,5) then goto openfile
	if BoxButtonStat(mainbox,6) then goto close
	if BoxButtonStat(mainbox,7) then gosub seekback
	if BoxButtonStat(mainbox,8) then gosub seekfor
	mode=playmedia("status music mode")
	if BoxButtonStat(mainbox,9) then goto PL
goto paused

:initialize
BoxDataClear(timebox,"clear")
BoxDrawText(timebox, "0,0,1000,1000", "0:00",1, 5)
play=itemextract(index,list,"	")
type=strupper(fileextension(play))
if type=="MP3" then device="mpegvideo"
if type=="WAV" then device="waveaudio"
if type=="MID" then device="sequencer"
if type=="RMI" then device="sequencer"
pt=""
 
errormode(@off)
pm=PlayMedia(strcat("open ",device,"!",filenameshort(play)," alias music"))
if pm==""
	BoxButtonStat(mainbox,1)
	BoxButtonStat(mainbox,2)
	BoxButtonStat(mainbox,3)
	BoxButtonStat(mainbox,4)
	if BoxButtonStat(mainbox,5) then goto openfile
	if BoxButtonStat(mainbox,6) then goto close
	if iferror=="reverse" then goto rev
	if iferror=="advance" then goto adv
endif
errormode(@cancel)
Playmedia("set music time format ms")
l=Playmedia("status music length")/1000
l=TimeAdd("1:1:1:0:0:0",strcat("0:0:0:0:0:",l))
m=itemextract(5,l,":")+0
s=itemextract(6,l,":")
l=strcat("Length: ",m,":",s)
boxdataclear(infobox,"clear")
Boxdrawtext(infobox, "20,800,980,980", l ,1, 16)
BinaryReadEx(bin,0,play,filesize(play)-128,128)
	if BinaryPeekStr(bin,0,3)=="TAG"
	title=strtrim(BinaryPeekStr(bin,3,30))
	artist=strtrim(BinaryPeekStr(bin,33,30))
	album=strtrim(BinaryPeekStr(bin,63,30))
	year=BinaryPeekStr(bin,93,4)
	tag=strcat(title,@crlf,artist,@crlf,album,@crlf,year)
else
	tag=fileroot(play)
	title=tag
endif
Boxdrawtext(infobox, "20,20,980,790",strcat(index,". ",tag) ,1, 16)
playmedia(strcat(aft," music"))
return

:adv
iferror="advance"
stat=playmedia("status music mode")
if index==filecount then goto %stat%
index=index+1
playmedia("close music")
gosub initialize
stat=playmedia("status music mode")
goto %stat%

:rev
iferror="reverse"
stat=playmedia("status music mode")
if index==1 then goto %stat%
index=index-1
playmedia("close music")
gosub initialize
stat=playmedia("status music mode")
goto %stat%


:play
playmedia("play music")
goto playing

:paus
playmedia("pause music")
goto paused

:stop
playmedia("close music")
index=1
aft="stop"
gosub initialize
goto stopped

:close
errormode(@off)
playmedia("close music")
errormode(@cancel)
if debugmode
	debugtrace(0,"")
	Addextender(xtend)
	zZipFiles("D g",zip,debugfile)
	errormode(@off)
	filedelete(debugfile)
	errormode(@cancel)
endif
exit

:openfile
ifcan=1
file=askfilename("Open","",filetypes,"",1)
playmedia("close music")
goto reopen

:seekback
pos=playmedia("status music position")
seek=max(0,pos-1000)
playmedia(strcat("seek music to ",seek))
playmedia(strcat(aft," music"))
return

:seekfor
pos=playmedia("status music position")
seek=min(playmedia("status music length"),pos+1000)
playmedia(strcat("seek music to ",seek))
playmedia(strcat(aft," music"))
return

:CANCEL
goto %can%
exit

:PL
iferror="advance"
playlist2=playlist
BP=Dialog("PL")
if bp==1
	if playlist2==""
		Message("Error","No track selected.")
		goto pl
	endif
	errormode(@off)
	playmedia("close music")
	errormode(@cancel)
	index=itemlocate(playlist2,playlist,"	")
	aft="play"
	gosub initialize
	goto playing
endif
if bp==2
	if playlist2==""
		Message("Error","No track selected.")
		goto pl
	endif
	ind=itemlocate(playlist2,playlist,"	")
	if ind


Article ID:   W14833
File Created: 2001:11:08:12:40:12
Last Updated: 2001:11:08:12:40:12