New Music Player in the works? (Maybe)
#1
Even though they've had FLAC in QB64pe for a while I'm just now getting into it. Which is weird because I love FLAC files. The majority of my music library is FLAC format because I'm a big audiophile. Anyways, I decided to look into the FLAC format for tags and such as well as the embedded album art stuff. Turns out, super easy to grab data from a FLAC file. Here's the test code I've used:

Code: (Select All)
Option Explicit
$NoPrefix
$Console

Dim As String file: file = "07 - Project 86 - Team Black.flac"

Dim As Long hfile: hfile = FreeFile
Open "B", hfile, file
Dim As String rawdata: rawdata = Space$(LOF(hfile))
Get hfile, , rawdata
Close

Dim As String SOI: SOI = Chr$(&HFF) + Chr$(&HD8)
Dim As String EOI: EOI = Chr$(&HFF) + Chr$(&HD9)

Dim As String lyrics: lyrics = Mid$(rawdata, InStr(rawdata, "LYRICS=") + Len("LYRICS=")): lyrics = Mid$(lyrics, 1, InStr(lyrics, Chr$(0)) - 2)
Dim As Long tracknumber: Dim As String track: track = Mid$(rawdata, InStr(rawdata, "TRACKNUMBER=") + Len("TRACKNUMBER=")): track = Mid$(track, 1, InStr(track, Chr$(0))): tracknumber = Val(track)
Dim As String songtitle: songtitle = Mid$(rawdata, InStr(rawdata, "TITLE=") + Len("TITLE=")): songtitle = Mid$(songtitle, 1, InStr(songtitle, Chr$(0)) - 2)
Dim As String albumtitle: albumtitle = Mid$(rawdata, InStr(rawdata, "ALBUM=") + Len("ALBUM=")): albumtitle = Mid$(albumtitle, 1, InStr(albumtitle, Chr$(0)) - 2)
Dim As String artist: artist = Mid$(rawdata, InStr(rawdata, "ARTIST=") + Len("ARTIST=")): artist = Mid$(artist, 1, InStr(artist, Chr$(0)) - 2)
Dim As String albumdate: albumdate = Mid$(rawdata, InStr(rawdata, "DATE=") + Len("DATE=")): albumdate = Mid$(albumdate, 1, InStr(albumdate, Chr$(6)) - 1)

Dim As String image: image = Mid$(rawdata, InStr(rawdata, SOI)): image = Mid$(image, 1, InStr(image, EOI) + Len(EOI))
If Len(image) > 0 Then
    Dim As Long hpic: hpic = FreeFile
    If FileExists("cover.jpg") Then Kill "cover.jpg"
    Open "B", hpic, "cover.jpg"
    Put hpic, , image
    Close
    Dim As Long i: i = LoadImage("cover.jpg", 32)
    If i < -1 Then Screen i Else Beep
    rawdata = ""
    Echo lyrics
    Print "Artist:", artist
    Print "Album :", albumtitle
    Print "Track :", tracknumber
    Print "Title :", songtitle
    Print "Date  :", albumdate
    Title artist + " - " + songtitle
    ConsoleTitle Title$ + " lyrics"
    Dim As Long snd: snd = SndOpen(file, "stream")
    If snd Then SndPlay snd
End If

And a test video:


I hope to make me a new project with the code. Obviously a point-and-click GUI. Probably Win32. I will have a trackbar for changing song position as well as a popup window for the lyrics and such. If I get really ambitious then I'll see about making me a tag editor for FLAC/MP3/WAV/etc files.
To download the song for testing: Project 86 - Team Black
Ask me about Windows API and maybe some Linux stuff
Reply
#2
Here's some code that is a little more cleaned up and sizes the picture down a bit:

Code: (Select All)
Option Explicit
$NoPrefix
$Console

Dim As String file: file = "07 - Project 86 - Team Black.flac"

Dim As Long hfile: hfile = FreeFile
Open "B", hfile, file
Dim As String rawdata: rawdata = Space$(LOF(hfile))
Get hfile, , rawdata
Close

Dim As String SOI: SOI = Chr$(&HFF) + Chr$(&HD8)
Dim As String EOI: EOI = Chr$(&HFF) + Chr$(&HD9)

Dim As String lyrics: lyrics = Mid$(rawdata, InStr(rawdata, "LYRICS=") + Len("LYRICS=")): lyrics = Mid$(lyrics, 1, InStr(lyrics, Chr$(0)) - 2)
Dim As Long tracknumber: Dim As String track: track = Mid$(rawdata, InStr(rawdata, "TRACKNUMBER=") + Len("TRACKNUMBER=")): track = Mid$(track, 1, InStr(track, Chr$(0))): tracknumber = Val(track)
Dim As String songtitle: songtitle = Mid$(rawdata, InStr(rawdata, "TITLE=") + Len("TITLE=")): songtitle = Mid$(songtitle, 1, InStr(songtitle, Chr$(0)) - 2)
Dim As String albumtitle: albumtitle = Mid$(rawdata, InStr(rawdata, "ALBUM=") + Len("ALBUM=")): albumtitle = Mid$(albumtitle, 1, InStr(albumtitle, Chr$(0)) - 2)
Dim As String artist: artist = Mid$(rawdata, InStr(rawdata, "ARTIST=") + Len("ARTIST=")): artist = Mid$(artist, 1, InStr(artist, Chr$(0)) - 2)
Dim As String albumdate: albumdate = Mid$(rawdata, InStr(rawdata, "DATE=") + Len("DATE=")): albumdate = Mid$(albumdate, 1, InStr(albumdate, Chr$(6)) - 1)

Dim As String image: image = Mid$(rawdata, InStr(rawdata, SOI)): image = Mid$(image, 1, InStr(image, EOI) + Len(EOI))
If Len(image) > 0 Then
    Dim As Long hpic: hpic = FreeFile
    If FileExists("cover.jpg") Then Kill "cover.jpg"
    Open "B", hpic, "cover.jpg"
    Put hpic, , image
    Close
    Dim As Long i: i = LoadImage("cover.jpg", 32)
    If i < -1 Then Screen NewImage(640, 640, 32) 'for testing
    Dest 0
    Source i
    rawdata = ""
    Echo lyrics
    Title artist + " - " + songtitle
    ConsoleTitle Title$ + " lyrics"
    Dim As Long snd: snd = SndOpen(file, "stream")
    If snd Then SndPlay snd
    Do
        Cls
        PutImage
        Print "Artist:", artist
        Print "Album :", albumtitle
        Print "Track :", tracknumber
        Print "Title :", songtitle
        Print "Date  :", albumdate
        Print SndGetPos(snd)
        Display
        Limit 60
    Loop Until InKey$ <> ""
End If
Ask me about Windows API and maybe some Linux stuff
Reply
#3
Good luck, you can d it, and remember, don't take any FLAC from anybody.

Pete
Reply




Users browsing this thread: 2 Guest(s)