-
Jan 30th, 2021, 06:38 PM
#1
Thread Starter
Frenzied Member
Help converting code
https://gist.github.com/lukasklein/8...10904fecbed86a
This has c+ (perhaps, I'm not sure) code to read the duration of a flac audio file.
Is it possible to convert this to VB6 or maybe a routine for this already exists ?
-
Jan 30th, 2021, 07:59 PM
#2
Thread Starter
Frenzied Member
Re: Help converting code
I found a sort of solution. It works but flashes up a DOS screen each time.
Code:
Sub FlacDuration()
Debug.Print GetFlacDur4("H:\Flacs\Remo Four\01 - Tommy Quickly & The Remo Four - Tip of My Tongue.flac")
End Sub
Function GetFlacDur4(File) As String
On Error GoTo err_F
Dim ws As String, s As Object, NumSamples As Long, SampleRate As Long, Seconds As Double, min As Integer
ws = "C:\Program Files\FLAC\metaflac.exe --show-total-samples ""__"""
Set s = CreateObject("wscript.shell")
Set s = s.exec(Replace(ws, "__", File))
NumSamples = s.StdOut.ReadAll
ws = "C:\Program Files\FLAC\metaflac.exe --show-sample-rate ""__"""
Set s = CreateObject("wscript.shell")
Set s = s.exec(Replace(ws, "__", File))
SampleRate = s.StdOut.ReadAll
Set s = Nothing
Seconds = (NumSamples / SampleRate)
min = min + Int(Seconds / 60)
Seconds = Seconds Mod 60
GetFlacDur4 = min & ":" & Format(Seconds, "0#")
qq:
On Error GoTo 0
Exit Function
err_F:
GetFlacDur4 = "0:00"
Resume qq
End Function
This is due to running metaflac.exe
Is it possible to hide this window ?
Thanks for any help.
-
Jan 31st, 2021, 04:35 AM
#3
Hyperactive Member
Re: Help converting code
Found this option. Replace in lines:
Code:
Set s = s.exec(Replace(ws, "__", File))
Code:
Set s = s.exec(Replace(ws, "__", File)), 0, false
-
Jan 31st, 2021, 04:50 AM
#4
Re: Help converting code
That is a lot of code, why not let windows do the work. This applies for all supported formats and of course Windows 10.
Code:
Dim X As Currency
With CreateObject("Shell.Application").NameSpace("E:\Music\").items.Item("CD1Track01.flac")
MsgBox .extendedproperty("Bitrate") \ 1000 & " kbps."
X = .extendedproperty("Duration")
MsgBox TimeSerial(0, 0, X / 10000000)
End With
-
Jan 31st, 2021, 04:51 PM
#5
Thread Starter
Frenzied Member
Re: Help converting code
Did that work for you Argus19 ?
I found first it had to be inside the last closing bracket but them gave error Wrong number of arguments or invalid property assignment
Is something else (reference?) required?
-
Jan 31st, 2021, 05:04 PM
#6
Thread Starter
Frenzied Member
Re: Help converting code
Doesn't work for me either Steve
MsgBox .extendedproperty("Bitrate") \ 1000 & " kbps." brings up error 91 Object variable or With block variable not set
I don't know your method here to try and fix (but it looks better than mine!)
-
Feb 1st, 2021, 02:54 AM
#7
Re: Help converting code
Well the Block variable is not set if you don't use all the code. I've just re-checked and the code I posted is correct and complete. No references.
Code:
Obviously the Namespace must point to your Music or other folder where the track is, in my case "E:\Music\". The item points to the track itself, I chose "CD1Track01.flac".
So use all the code and adjust Namespace and Item to point towards your track.
This would be the path shown in explorer for my track. "E:\Music\CD1Track01.flac"
Edit: Hmm the forum keeps removing the backslash at the end of the Namespace I will put code tags around it.
Last edited by Steve Grant; Feb 1st, 2021 at 02:58 AM.
-
Feb 1st, 2021, 04:45 AM
#8
Re: Help converting code
According to the Link in the first post, it's basically reading the StreamInfo-Metadata, and Duration boils down to "total_samples / Sample-Rate"
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Feb 1st, 2021, 04:55 AM
#9
Hyperactive Member
Re: Help converting code
In the "exec command ..... 0, false". "0" means "do not show the window". "false" - "do not wait for execution".
Here's Steve's code that works:
Code:
Option Explicit
Dim Fi As Variant, Fe As Variant
Dim X As Currency
Fi = App.Path & "\"
Fe = "Today farewell.flac"
With CreateObject("Shell.Application").NameSpace(Fi).items.Item(Fe)
MsgBox .extendedproperty("Bitrate") \ 1000 & " kbps."
X = .extendedproperty("Duration")
MsgBox TimeSerial(0, 0, X / 10000000)
End With
-
Feb 1st, 2021, 04:44 PM
#10
Thread Starter
Frenzied Member
Re: Help converting code
Very strange. Doesn't work here still.
But which is .Namespace() ? Steve says it's the Path for the flac file and Argus says it's the application path.
Using App.Path & "" gives error 91. Using the file path results are
.extendedproperty("Bitrate") \ 1000 & " kbps." = 0 kbps
TimeSerial(0, 0, X / 10000000) = 12:00.00 a.m.
>In the "exec command ..... 0, false". "0" means "do not show the window". "false" - "do not wait for execution".
Code:
Set s = s.exec(Replace(ws, "__", File)), 0, false
The line won't compile.
-
Feb 2nd, 2021, 04:11 AM
#11
Re: Help converting code
Alexander the Namespace is the folder where you have your music track with a backslash inside inverted commas inside parenthesis. Example ("E:\Music") < there is a backslash here that the forum keeps removing.
The Item is the actual file name of the track inside inverted commas inside parenthesis. Example ("AlexandersTest-Track1.flac")
You must change these examples to a folder\track that really exists on your PC or you will get the 'Block variable' not set error.
Argus used app.path & "" (< backslash) because that's where he put his test track "Today farewell.flac". Why he had to convert both to variants I am not sure. Sometimes the shell does require variants but I have not needed it.
If you still can't get this working, post a complete path to a track that actually exists on your PC and post the complete code you are using to get the info from that track.
Further Info. I am using Windows 10 - VB6 Professional with SP6 run as admin.
Last edited by Steve Grant; Feb 2nd, 2021 at 04:15 AM.
-
Feb 2nd, 2021, 04:14 AM
#12
Hyperactive Member
Re: Help converting code
Originally Posted by AlexanderBB
Very strange. Doesn't work here still.
But which is .Namespace() ? Steve says it's the Path for the flac file and Argus says it's the application path.
"NameSpace": This is the full path to the folder where the .flac file is located.
".items.Item": file name with extension.
This is a common use for "exec". I have not tried to run this option.
-
Feb 2nd, 2021, 05:58 PM
#13
Thread Starter
Frenzied Member
Re: Help converting code
Steve my VB6 runs under XP. Would this be the problem ? I was putting in the path and file names correctly.
> According to the Link in the first post, it's basically reading the StreamInfo-Metadata, and Duration boils down to "total_samples / Sample-Rate"
Thanks zVoni, I did figure this out eventually and can now read directly from the file to get those values. So I don't need the code in Msg #2 anymore but if the DOS window can be hidden (not flash up) it's be good to make it so.
-
Feb 3rd, 2021, 01:38 AM
#14
Re: Help converting code
The shell extendedproperty method likely wouldn't work on XP. Only Windows 10 has a built in FLAC property handler; even Windows 7 doesn't.
You can install a 3rd party one and then the shell can give you those properties, but it's not a built in shell extension like mp3 on Win7.
-
Feb 3rd, 2021, 01:52 AM
#15
Thread Starter
Frenzied Member
-
Feb 3rd, 2021, 02:06 AM
#16
Re: Help converting code
As 3rd-Party, i'd recommend ffprobe.exe from the ffmpeg-collection.
No idea about shelling it "silently" (a.k.a. no "DOS"-Window), or piping the output.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Feb 3rd, 2021, 05:58 AM
#17
Re: Help converting code
If you're talking about the 3rd party thing I mentioned, ffprobe isn't a shell extension you need something like the AJD FLAC Property Handler
-
Feb 3rd, 2021, 06:46 AM
#18
Re: Help converting code
Or check, if the ffmpeg-collection is already installed, and use ffprobe
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Feb 3rd, 2021, 04:39 PM
#19
Thread Starter
Frenzied Member
Re: Help converting code
Just wondering how you guys might handle this.
You want to read 20 bits from a file starting at a known offset - into a long variable
(This is the sample rate used in Msg #1)
Last edited by AlexanderBB; Feb 3rd, 2021 at 04:43 PM.
-
Feb 4th, 2021, 02:11 AM
#20
Re: Help converting code
It's impossible to read 1 bit (or 20) from the storage as it's impossible to read 1 *byte* (or 20) as the storage is a block device i.e. it can retrieve blocks of 512 bytes (sectors) or bigger 4KB-32Kb clusters.
So to read 20 bits the application has to do what the SSD/HDD driver does when attempting to read 20 bytes from a given offset -- calc *byte* offset and read one (or two) bytes and bit-shift to drop extra bits. And in the case of the driver calculate *sector* offset and read one (or two) sectors and copy bytes directly from I/O buffer.
cheers,
</wqw>
-
Feb 4th, 2021, 02:35 AM
#21
Thread Starter
Frenzied Member
Re: Help converting code
My question may be badly composed as it does seem possible. Here's what I'm doing which works but I'm sure is the wrong approach
Code:
Dim Chunk as string * 3
Dim by as string
Open file for binary as #freefile
Get #ff, Pos, Chunk [Pos is previously known]
For y = 1 To 3
by = by & Format(Hex(Asc(Mid(Chunk, y))), "0#")
Next
by = Left(by, Len(by) - 1)
Answer = CLng("&h" & by)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|