For Windows only, Play Avi or Wave files from "Ram"
Posted: Fri Apr 01, 2016 12:49 am
Hi,
i found here a 10 years old code to play a wave file from ram with the mci commands. I have changes the code to play an avi file in a purebasic window from ram too.
P.S. I think the idea of the code can be used to make a streaming video over internet...
Greetings Michael
Old Wavecode
New Avi Code
i found here a 10 years old code to play a wave file from ram with the mci commands. I have changes the code to play an avi file in a purebasic window from ram too.
P.S. I think the idea of the code can be used to make a streaming video over internet...
Greetings Michael
Old Wavecode
Code: Select all
;
;Don't forget, the wav is already loaded in memory (ReadData()).
Global *mm_Data, mm_size.l, mm_4.l, mm_opn
Declare P_mm_IO(*lpM.MMIOINFO,mesg.l,param1.l,param2.l)
*mm_Data = ?Inc
mm_size = ?ExitProc - ?Inc
;*mm_Data is pointer to the memory location of the loaded wav-file
;mm_size is the file size
mm_4.l=mmioStringToFOURCC_("ABC",#MMIO_TOUPPER)
;could be anything other than "ABC", but not more than 3.
mm_opn=0
;Now the private IOroutine is being loaded:
mmioInstallIOProc_(mm_4,@P_mm_IO(),#MMIO_INSTALLPROC)
;Now an almost normal mci open command: but note the 'filename':
;..it's the extension "ABC+" which makes mci to use your private
;..routine P_mm_IO() for IO with wav at memory address *mm_Data:
uu.l=mciSendString_("open Sound.ABC+ type waveaudio alias test",0,0,0)
;from here on, you do mci commands (play [from], pause, status,..) as usual!
;...
mciSendString_("play test",0,0,0)
Delay (40000)
;...
;when finished, close this way:
mciSendString_("close test",0,0,0)
mmioInstallIOProc_(mm_4,#Null,#MMIO_REMOVEPROC)
;and here the routine:
Procedure P_mm_IO(*lpM.MMIOINFO,mesg.l,lparam1.l,lparam2.l)
Select mesg
Case #MMIOM_OPEN
If mm_opn=1: ProcedureReturn 0: EndIf
mm_opn=1
*lpM\lDiskOffset = 0:ProcedureReturn 0
Case #MMIOM_CLOSE: ProcedureReturn 0
Case #MMIOM_READ
CopyMemory(*mm_Data + *lpM\lDiskOffset,lParam1, lParam2)
*lpM\lDiskOffset + lParam2;
ProcedureReturn lParam2
Case #MMIOM_SEEK
Select lParam2
Case #SEEK_SET
*lpM\lDiskOffset = lParam1
Case #SEEK_CUR
*lpM\lDiskOffset + lParam1
Case #SEEK_END
*lpM\lDiskOffset = fileSize - 1 - lParam1;
EndSelect
ProcedureReturn *lpM\lDiskOffset;
Default
ProcedureReturn -1
EndSelect
ProcedureReturn
EndProcedure
DataSection
Inc:
IncludeBinary "F:\FanFare3.wav"
ExitProc:
EndDataSection
;../tomio
Code: Select all
;
;Don't forget, the wav is already loaded in memory (ReadData()).
Global *mm_Data, mm_size.l, mm_4.l, mm_opn
Declare P_mm_IO(*lpM.MMIOINFO,mesg.l,param1.l,param2.l)
width = 400
height = 260
hw1=OpenWindow(0, 100, 100,width , height, "PureBasicWindow", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
*generic_bank=AllocateMemory(4096)
*mm_Data = ?Inc
mm_size = ?ExitProc - ?Inc
;*mm_Data is pointer to the memory location of the loaded wav-file
;mm_size is the file size
mm_4.l=mmioStringToFOURCC_("ABC",#MMIO_TOUPPER)
;could be anything other than "ABC", but not more than 3.
mm_opn=0
;Now the private IOroutine is being loaded:
mmioInstallIOProc_(mm_4,@P_mm_IO(),#MMIO_INSTALLPROC)
;Now an almost normal mci open command: but note the 'filename':
;..it's the extension "ABC+" which makes mci to use your private
;..routine P_mm_IO() for IO with wav at memory address *mm_Data:
uu.l=mciSendString_("open film.ABC+ type AVIVideo alias test",0,0,0)
uu.l=mciSendString_("window test handle " + Str(hw1),0,0,0) ; Put Film in Purebasic Windows
;uu.l=mciSendString_("put test destination at 0 0 "+Str(width/2)+" "+Str(height/2),0,0,0) ; show the film in a Part of the Windows
;from here on, you do mci commands (play [from], pause, status,..) as usual!
;...
;...
;when finished, close this way:
mciSendString_("play test",0,0,0)
;mciSendString_("play test fullscreen",0,0,0) ; <- fullscreenmode
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
EndIf
Until Quit = 1
mciSendString_("close test",0,0,0)
mmioInstallIOProc_(mm_4,#Null,#MMIO_REMOVEPROC)
FreeMemory (*generic_bank)
;and here the routine:
Procedure P_mm_IO(*lpM.MMIOINFO,mesg.l,lparam1.l,lparam2.l)
Select mesg
Case #MMIOM_OPEN
If mm_opn=1: ProcedureReturn 0: EndIf
mm_opn=1
*lpM\lDiskOffset = 0:ProcedureReturn 0
Case #MMIOM_CLOSE: ProcedureReturn 0
Case #MMIOM_READ
CopyMemory(*mm_Data+*lpM\lDiskOffset,lParam1, lParam2)
*lpM\lDiskOffset + lParam2;
ProcedureReturn lParam2
Case #MMIOM_SEEK
Select lParam2
Case #SEEK_SET
*lpM\lDiskOffset = lParam1
Case #SEEK_CUR
*lpM\lDiskOffset + lParam1
Case #SEEK_END
*lpM\lDiskOffset = fileSize - 1 - lParam1;
EndSelect
ProcedureReturn *lpM\lDiskOffset;
Default
ProcedureReturn -1
EndSelect
ProcedureReturn
EndProcedure
;../tomio
DataSection
Inc:
IncludeBinary "f:\Urlaub\P1000230_AVI.avi"
ExitProc:
EndDataSection