audio file info added, fixed right click selecting.

This commit is contained in:
2026-02-23 19:05:57 -05:00
parent a6b476399e
commit 16060023bb
23 changed files with 798 additions and 134 deletions
+17 -6
View File
@@ -7,12 +7,15 @@ import (
)
// getTrackDuration returns the duration of an audio file in
// milliseconds. For MP3 files it uses a fast header-only parser
// (Xing/VBRI/CBR); for other formats it falls back to a full
// decode via beep which is already O(1) for FLAC, OGG, and WAV.
// milliseconds together with its audio stream properties. For MP3
// files it uses a fast header-only parser (Xing/VBRI/CBR); for FLAC
// it reads the StreamInfo block; for other formats it falls back to
// beep which is already O(1) for OGG and WAV.
//
// The file position is undefined after this call.
func getTrackDuration(f *os.File) (int64, error) {
func getTrackDuration(
f *os.File,
) (int64, *AudioProperties, error) {
ext := filepath.Ext(f.Name())
switch ext {
@@ -26,7 +29,9 @@ func getTrackDuration(f *os.File) (int64, error) {
// (reads headers/metadata only, no full audio decode).
streamer, format, err := DecodeFile(f)
if err != nil {
return 0, fmt.Errorf("error decoding file: %w", err)
return 0, nil, fmt.Errorf(
"error decoding file: %w", err,
)
}
lengthMillis := int64(
@@ -35,5 +40,11 @@ func getTrackDuration(f *os.File) (int64, error) {
)
_ = streamer.Close()
return lengthMillis, nil
props := &AudioProperties{
SampleRate: int(format.SampleRate),
BitDepth: format.Precision * 8,
Channels: format.NumChannels,
}
return lengthMillis, props, nil
}