General information
Category:
COM/DCOM and OLE Automation
Title:
Ouch, FoxPro let me down - duration = 0.00000
The following code attempts to get the duration in seconds of my entire music collection on my PC. This includes FLAC, MP3 and WMAs. Because VFP let me down I had to write this in C# and the answer was 13,410 songs, 3.2 million seconds or 37.17 days. And I do have a big pile of vinyl, too. Oh, and all of this music was PURCHASED and not stolen using those kind of apps.
On a Windows machine there's the COM or ActiveX or whatever it is called Mediaplayer.Mediaplayer and it's pretty easy to use and has a 'Duration' property that is in seconds with a fractional amount. The code below is simple. And if you put a breakpoint and run it step by step in the FoxPro Debugger you get values for the Duration. But when you just let it rip the Duration is 0.00000.
I tried all the tricks I know - _vfp.AutoYield, Sleep, and VFP's doevents. But no Duration when run at full speed.
**********************************************************
**********************************************************CODE
**********************************************************
select 0
create cursor qsongs (name varchar(100),folder varchar(100),duration b(2))
_vfp.AutoYield = .f.
DECLARE Sleep IN kernel32 INTEGER dwMilliseconds
private poMediaPlayer
poMediaPlayer = CreateObject("Mediaplayer.Mediaplayer")
*process('D:\MyMusic')
process('D:\MyFlacMusic')
release poMediaPlayer
******************************
******************************Process
******************************
procedure process
lparameters tcFolderName
local laDir[1]
local ii
adir(laDir,addbs(tcFolderName) + '*.*','D')
for ii = 1 to alen(laDir,1)
if laDir[m.ii,1] == '.' or laDir[m.ii,1] == '..'
loop
endif
if atc('D',laDir[m.ii,5]) > 0
process(addbs(tcFolderName) + laDir[m.ii,1])
endif
if inlist(justext(laDir[m.ii,1]),'WMA','MP3','FLAC')
processFile(tcFolderName, laDir[m.ii,1])
endif
next
endproc
******************************
******************************ProcessFile
******************************
procedure processFile
lparameters tcFolderName, tcFileName
local lnSeconds
*poMediaPlayer.FileName = addbs(tcFolderName) + tcFileName
poMediaPlayer.open(addbs(tcFolderName) + tcFileName)
doevents
doevents
*sleep(100)
lnSeconds = poMediaPlayer.Duration
doevents
doevents
?'****',poMediaPlayer.FileName,lnSeconds
insert into qsongs (name, folder, duration) values (tcFileName, tcFolderName, lnSeconds)
endproc
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only