Fmodex.dll библиотека
Пример использования библиотеки
Fmodex.dll для проигрывания mp3 и онлайн звука из сети.
Официальный сайт
http://www.fmod.org/
Вывод тегов mp3 и потокового звука.
Громкость.
Спектроанализатор звука.
Таймер воспроизведения.
Для версии
PureBasic 4.30
В архиве рабочий пример и папка с исходниками (не всё работает)
Скачать архив
Fmodex.dll с исходниками
Один из вариантов рабочего кода:
Enumeration
#Window_0
#play
#open
#stop
#pausa
#trac
#text1
#radio
#im1
#text2
#text3
#_VolUp
#_VolDown
EndEnumeration
IncludeFile "fmodex.pb"
Define channel.l, sound.l, CurrentVolume.f, Frequency.f, FileToPlay.s, Handle, TagCount, i, Tag.FMOD_TAG
Global Val, Dim Arr.f(512), column, width, height, color, pos
Dim Arr.f(512)
gg.s="http://www.abradio.cz/asx/depechemode32.asx"
;{----------------------Параметры спектра-----------------------------------
x=5 ;позиция от начала x
y=5 ;позиция от начала y
column=129 ;колличество столбов
width=2 ;ширина столба
height=55 ;высота столба
h=1 ;ширина между столбами
color=RGB(2, 128, 253) ;цвет
;}----------------------------------------------------------------------------
CreateImage(#im1,width,height) ; спектр
Procedure Spectr() ; спектр
For f=0 To column
StartDrawing(ImageOutput(#im1))
Val= Arr(f)*800
Box(0,0,20,height,RGB(240, 240, 240))
Box(0,height-Val,20,Val,color)
StopDrawing()
SetGadgetState(100+f,ImageID(#im1))
Next f
SetGadgetText(#text2,Str(pos))
EndProcedure
If OpenWindow(#Window_0, 50, 50, 400, 150, "FMOD-плеер", #PB_Window_SystemMenu)
;SetWindowColor(#Window_0,RGB(143, 143, 143))
ButtonGadget(#open, 10, 95,60,20,"Открыть")
ButtonGadget(#stop, 80, 95,60,20,"Стоп")
ButtonGadget(#play, 150,95,60,20,"Играть" )
ButtonGadget(#pausa, 220,95,60,20,"Пауза" )
ButtonGadget(#radio, 290,95,60,20,"Радио" )
ButtonGadget(#_VolUp,270,120,30,20,"+")
ButtonGadget(#_VolDown,230,120,30,20,"-")
TrackBarGadget(#trac, 5, 120, 220, 20, 0,100, #PB_TrackBar_Ticks)
SetGadgetState(#trac, 50)
TextGadget(#text1,10,70,305,20,"")
TextGadget(#text2,320,70,70,20,"")
TextGadget(#text3,320,124,70,20,"50")
For f=0 To column
ImageGadget(100+f,x, y,0,0,ImageID(#im1)) ; вывод спектра
x=x+(width+h)
Next f
Init_FMOD()
FMOD_System_Create(@Handle)
FMOD_System_Init(Handle, 1, #FMOD_INIT_NORMAL, 0)
SetTimer_(WindowID(#Window_0),Event,35,@Spectr())
Repeat
Event = WaitWindowEvent()
Window = EventWindow()
Gadget = EventGadget()
FMOD_Channel_GetSpectrum(channel, Arr(), 512, 0, 0)
FMOD_Channel_GetPosition(channel, @pos, #FMOD_TIMEUNIT_MS)
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #play
FMOD_System_CreateStream(Handle, @FileToPlay, #FMOD_DEFAULT, 0, @sound)
FMOD_System_PlaySound(Handle, 0, sound, 0, @channel)
Vol.f = GetGadgetState(#trac)/100
FMOD_Channel_SetVolume( channel, Vol )
;--------------------тег mp3-------------------------------------------
If FileToPlay.s
FMOD_System_CreateStream(Handle,@File$,#FMOD_DEFAULT,#Null,@Sound)
FMOD_Sound_GetNumTags(Sound,@TagCount,#Null)
Debug "Number of tags: " + Str(TagCount)
For i=0 To TagCount-1
FMOD_Sound_GetTag(Sound,0,i,@Tag)
;Debug "TAG Struct:"
;Debug Tag\type
;Debug Tag\datatype
;Debug Tag\name
;Debug Tag\_data
;Debug Tag\datalen
;Debug Tag\udated
Debug PeekS(Tag\_data, Tag\datalen)
Next
FMOD_Sound_GetTag(Sound,0,0,@Tag)
text.s=PeekS(Tag\_data, Tag\datalen)
FMOD_Sound_GetTag(Sound,0,1,@Tag)
name.s =PeekS(Tag\_data, Tag\datalen)
SetGadgetText(#text1, name.s +" "+ text.s)
EndIf
;----------------------------------------------------------------------------
Case #pausa
pausa = pausa ! 1
If pausa =1
FMOD_Channel_SetPaused (channel, 1)
Else
FMOD_Channel_SetPaused (channel, 0)
EndIf
Case #open
FileToPlay.s= OpenFileRequester("Choose a soundfile", GetClipboardText(), "*.*|*.*", 0)
Case #stop
FMOD_Channel_Stop(channel)
Case #trac
Vol.f = GetGadgetState(#trac)/100
FMOD_Channel_SetVolume( channel, Vol )
FMOD_Channel_GetVolume( channel,@CurrentVolume.f )
SetGadgetText(#text3, Str(CurrentVolume.f*100))
Case #radio
Onlain.s= "http://195.5.125.6:8000/"
FMOD_System_CreateStream(Handle, @Onlain, #FMOD_DEFAULT, 0, @sound)
FMOD_System_PlaySound(Handle, 0, sound, 0, @channel)
Vol.f = GetGadgetState(#trac)/100
FMOD_Channel_SetVolume( channel, Vol )
;-----------------тег fm-----------------------------------------------------
If Onlain.s
FMOD_System_CreateStream(Handle,@File$,#FMOD_DEFAULT,#Null,@Sound)
FMOD_Sound_GetNumTags(Sound,@TagCount,#Null)
Debug "Number of tags: " + Str(TagCount)
For i=0 To TagCount-1
FMOD_Sound_GetTag(Sound,0,i,@Tag)
;Debug "TAG Struct:"
;Debug Tag\type
;Debug Tag\datatype
;Debug Tag\name
;Debug Tag\_data
;Debug Tag\datalen
;Debug Tag\udated
Debug PeekS(Tag\_data, Tag\datalen)
Next
FMOD_Sound_GetTag(Sound,0,3,@Tag)
text.s=PeekS(Tag\_data, Tag\datalen)
FMOD_Sound_GetTag(Sound,0,2,@Tag)
name.s =PeekS(Tag\_data, Tag\datalen)
SetGadgetText(#text1, name.s +" "+ text.s)
EndIf
;-----------------------------------------------------------------------------
Case #_VolUp
FMOD_Channel_GetVolume( channel,@CurrentVolume.f )
SetGadgetText(#text3, Str(CurrentVolume.f*100))
SetGadgetState(#trac, CurrentVolume.f*100)
Select CurrentVolume.f
Case 0 To 0.3
FMOD_Channel_SetVolume( channel, CurrentVolume+0.02 )
Case 0.31 To 0.5
FMOD_Channel_SetVolume( channel, CurrentVolume+0.05 )
Case 0.51 To 1.0
If (CurrentVolume+0.08)>1.0
FMOD_Channel_SetVolume( channel, 1.0 )
Else
FMOD_Channel_SetVolume( channel, CurrentVolume+0.08 )
EndIf
EndSelect
Case #_VolDown
FMOD_Channel_GetVolume( channel,@CurrentVolume.f )
SetGadgetText(#text3, Str(CurrentVolume.f*100))
SetGadgetState(#trac, CurrentVolume.f*100)
Select CurrentVolume.f
Case 0 To 0.3
If (CurrentVolume-0.02)<0
FMOD_Channel_SetVolume( channel, 0 )
Else
FMOD_Channel_SetVolume( channel, CurrentVolume-0.02 )
EndIf
Case 0.31 To 0.5
FMOD_Channel_SetVolume( channel, CurrentVolume-0.05 )
Case 0.51 To 1.0
FMOD_Channel_SetVolume( channel, CurrentVolume-0.08 )
EndSelect
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
FMOD_Sound_Release(sound)
FMOD_System_Close(Handle)
FMOD_System_Release(Handle)