Moin Leute,
Hier ein Kleiner Quellcode,
er besteht aus 3 Teilen.
1. Meine Musikplayer Routine
2. Inaries OGG Tag loader
3. Vertex sein MP3 Idv 1 Tag Loader
eine Ogg zum testen:
http://eastwestgames.de/file.php?id=324
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN] Graphics 1024,768,32,2 SetBuffer BackBuffer() Global BGMusikChannel% Global BGMusikPlaying.BGMusikFile Global BGMusikFileName$ Global BGMusikDir$ = CurrentDir$() Global BGMusikPan#=0,BGMusikPitch%=0,BGMusikVolume#=1
Type BGMusikFile Field Pfad$ Field InPlaylist% End Type
BGMusikFind(CurrentDir()) Repeat t1=MilliSecs() Cls Text 0,0,t1-t2 Text 0,15,BGMusikFileName$ BGMusikUpdate() If KeyHit(57) Then BGMusikNextSong() Flip 0 Delay 100 t2=t1 Until KeyHit(1) End
Function BGMusikSetdir(Dir$) BGMusikDir$ = Dir$ End Function
Function BGMusikFree() BGMusikNextSong() For BGMusikPlaying.BGMusikFile = Each BGMusikFile Delete BGMusikPlaying Next BGMusikPlaying = Null End Function
Function BGMusikNextSong() StopChannel BGMusikChannel% End Function
Function BGMusikPitch(Frequenz%) BGMusikPitch%= Frequenz% ChannelPitch BGMusikChannel%,BGMusikPitch% End Function
Function BGMusikPan(Ballance#) BGMusikPan#=Ballance# ChannelPan BGMusikChannel%,BGMusikPan# End Function
Function BGMusikVolume(Volume#) BGMusikVolume#=Volume# ChannelVolume BGMusikChannel%,BGMusikVolume# End Function
Function BGMusikUpdate() Local H%,G%,LTS% If BGMusikPlaying = Null Then BGMusikFind(BGMusikDir$ ) BGMusikPlaying = First BGMusikFile EndIf If Not ChannelPlaying(BGMusikChannel%) Then BGMusikChannel%=0 If Not BGMusikChannel% BGMusikChannel%=PlayMusic(BGMusikPlaying\Pfad$) If BGMusikPitch% <> 0 Then BGMusikPitch(BGMusikPitch%) BGMusikPan(BGMusikPan#) BGMusikVolume(BGMusikVolume#) G=1 Repeat H=G+1 LTS=G G=Instr(BGMusikPlaying\Pfad$,"\",H) Until G=0 BGMusikFileName$=Mid(BGMusikPlaying\Pfad$,LTS+1,Len(BGMusikPlaying\Pfad$)-LTS) BGMusikInfos() If BGMusikPlaying = Last BGMusikFile Then BGMusikPlaying = First BGMusikFile Else BGMusikPlaying = After BGMusikPlaying EndIf EndIf End Function
Function BGMusikFind(Pfad$) Local Verzeichniss Local Datei$ Local Aus%,Ein% Local File.BGMusikFile Verzeichniss=ReadDir(Pfad$) Datei$=NextFile$(Verzeichniss) Repeat If FileType(Pfad$+Datei$) = 2 Then If datei$ <> "." And datei$ <> ".." BGMusikFind(Pfad$+Datei$+"\") EndIf Else Ein%=0 If Upper(Right(Datei$,3))="RAW" Then Ein%=1 If Upper(Right(Datei$,3))="MOD" Then Ein%=1 If Upper(Right(Datei$,3))="S3M" Then Ein%=1 If Upper(Right(Datei$,2))="XM" Then Ein%=1 If Upper(Right(Datei$,2))="IT" Then Ein%=1 If Upper(Right(Datei$,3))="MID" Then Ein%=1 If Upper(Right(Datei$,3))="RMI" Then Ein%=1 If Upper(Right(Datei$,3))="WAV" Then Ein%=1 If Upper(Right(Datei$,3))="MP2" Then Ein%=1 If Upper(Right(Datei$,3))="MP3" Then Ein%=1 If Upper(Right(Datei$,3))="OGG" Then Ein%=1 If Upper(Right(Datei$,3))="WMA" Then Ein%=1 If Upper(Right(Datei$,3))="ASF" Then Ein%=1 If ein% File = New BGMusikFile File\Pfad$ = Pfad$+Datei$ File\InPlaylist% = True EndIf End If Datei$=NextFile$(Verzeichniss) If Datei$="" Then Aus=1 Until Aus CloseDir Verzeichniss End Function
Function BGMusikInfos() Local Info% If Upper(Right(BGMusikFileName$,3))="MP3" Then info=Get_ID3v1_Info(BGMusikPlaying\Pfad$) BGMusikFileName$=Get_ID3v1_Interpreter$(Info)+" : "+Get_ID3v1_Titel$(Info) ElseIf Upper(Right(BGMusikFileName$,3))="OGG" BGMusikFileName$=Ini_Ogg_Parse(bgmusikplaying\pfad$) EndIf If Trim(BGMusikFileName$) = Trim("Unknown : Unknown") BGMusikFileName$= BGMusikPlaying\Pfad$ EndIf End Function
Function Get_ID3v1_Info(File$) Local datei = ReadFile(File$) Local Info = CreateBank(127) Local B,ID3$,TAG$ SeekFile datei,FileSize(File$) - 128 For B = 0 To 126 PokeByte Info,B,ReadByte(datei) Next For B = 0 To 2 TAG$ = TAG$ + Chr$(PeekByte(Info,B)) Next If TAG$ <> "TAG" Then CloseFile datei FreeBank Info Return False EndIf CloseFile datei Return Info End Function
Function Get_ID3v1_Titel$(Info) Local B,Byte,Titel$ For B = 3 To 3 + 29 Byte = PeekByte(Info,B) If Byte <> 0 Then Titel$ = Titel$ + Chr$(Byte) Next If Len(Titel$) > 0 Then Return Trim$(Titel$) Else Return "Unknown" EndIf
End Function
Function Get_ID3v1_Interpreter$(Info) Local B,Byte,Interpreter$ For B = 33 To 32 + 30 Byte = PeekByte(Info,B) If Byte <> 0 Then Interpreter$ = Interpreter$ + Chr$(Byte) Next If Len(Interpreter$) > 0 Then Return Trim$(Interpreter$) Else Return "Unknown" EndIf
End Function
Function Ini_Ogg_Parse$(file$) Local txt$, Datei% = ReadFile(File$) Local b%, st$, verndor$, count%, i%, com$ Local artist$, title$, tracknumber%, date$, location$, genre$ Repeat b = ReadByte(datei) St$ = st + Chr(b) If Right(st,6) = "vorbis" Select Asc(Mid(st,Len(st)-6,1)) Case 1 Case 3 vendor$ = ReadString(datei) DebugLog vendor count = ReadInt(datei) DebugLog count For i = 1 To count com$ = ReadString(datei) If Util_GetParas(com$) Select Lower(paras[0]) Case "artist" If Len(artist$)>0 Then artist$ = artist$ + ";" artist$ = artist$ + paras[1] Case "title" If Len(title$)>0 Then title$ = title$ + ";" title$ = title$ + paras[1] Case "tracknumber" tracknumber%= paras[1] Case "date" date$ = paras[1] Case "location" location$ = paras[1] Case "description" description$= paras[1] Case "genre" If Len(genre$)>0 Then genre$ = genre$ + ";" genre$ = genre$ + paras[1] End Select EndIf Next Case 5 Exit End Select EndIf Until Eof(Datei) CloseFile datei If artist<>"" Then txt$ = txt + artist + ": " If title<>"" Then txt = txt + "'" + title + "' " If tracknumber Then txt = txt + tracknumber + " " If genre Then txt = txt + "(" + genre + ") " If date Or location Then txt = txt + "recorded " If location Then txt = txt + "in " + location + " " If date Then txt = txt + date + " " If description Then txt = txt + description Return txt$ End Function
Function Get_Ogg_Info(File$) Local datei = ReadFile(File$) Local Info = CreateBank(8) Local B,ID3$,TAG$ SeekFile datei,10*4 PokeInt Info,0,ReadInt(datei) SeekFile datei,12*4 PokeInt Info,4,ReadInt(datei)
CloseFile datei
Return Info End Function
Function Get_OGG_Artist$(File$) Local txt$,Datei%=ReadFile(File$) Local g%,Out$,i% Repeat txt$=ReadLine(Datei%) g= Instr(txt$,"ARTIST=") Until Eof(Datei) Or g > 0 If g > 0 Then i%=g Repeat g= Asc(Mid(txt$,i,1)) i=i+1 Out$=Out$+Chr(g) Until g=0 Out$=Left(Out$,Len(Out$)-2) Else Out$="Unknown" EndIf
CloseFile Datei% Return out$ End Function
Function Get_OGG_Title$(File$) Local txt$,Datei%=ReadFile(File$) Local g%,Out$,i% Repeat txt$=ReadLine(Datei%) g= Instr(txt$,"TITLE=") Until Eof(Datei) Or g > 0 If g > 0 Then i%=g Repeat g= Asc(Mid(txt$,i,1)) i=i+1 Out$=Out$+Chr(g) Until g=0 Out$=Left(Out$,Len(Out$)-2) Else Out$="Unknown" EndIf
CloseFile Datei% Return out$ End Function
Global paras$[1] Function Util_GetParas(txt$,trenn$="=") tpos = Instr(txt$,trenn$) If tpos>0 paras[0] = Trim(Left(txt$,tpos-1)) paras[1] = Trim(Right(txt$,Len(txt$)-tpos)) DebugLog "Para1: "+paras[0]+" Para2: "+paras[1] Return 1 EndIf End Function
|