Here is the MCI code to play .MPG or .VOB video files in your game screen and with positioning and resizing code. It's does what the old dshow code (which still works) did but as you can see simpler and better. If for any reason you can't see video but can hear it then you will need an mpeg codec - i myself am using an old KLITE-Codec Pack. Also thanks to DODICAT for his help and code too so i could put this together :)
Code: Select all
#include "Windows.bi"
#include "win/mmsystem.bi"
screencontrol(103,"GDI") 'use GDI driver else video flickers badly in Win10 with directx
screenres 800,600,32
declare sub playvid(param as any ptr)
dim shared as string vtp 'once vtp is not NULL the thread automatically plays the vid till it ends or a new vid takes over
dim shared as integer terminate,flag
dim shared as any ptr thread
thread=threadcreate(@playvid,0)
sleep 100 'can be omitted as only needed for this test
vtp="yourvid.mpg" 'will trigger vid to play vid with dir specified in thread if needed
sleep
terminate=1
threadwait(thread)
sub playvid(param as any ptr)
dim windo as hwnd
screencontrol(2,cast(integer,windo))
dim as uinteger w,h,hor,ver,vw,vh
dim as zstring*20 vfp
screeninfo w,h 'get current resolution width & height
vw=w/5 'just code to put the video area centred horizontally and just below centre
vh=h/5
hor=w/2-vw/2
ver=h/2
while (1) 'never understood this but it was in the example so used it and works
do
if terminate then
mciSendString("close vid",NULL,0,0)
exit sub
end if
if flag then
mciSendString("status vid mode",@vfp,20,0) 'sends max 20 character message to string vfp that's either 'playing'
if vfp="stopped" then 'if vid has ended or 'stopped'
mciSendString("close vid",NULL,0,0) 'needed as won't play next vid otherwise
line(hor-2,ver-2)-(hor+vw+2,ver+vh+2),&h000000,bf 'get rid of white border + last frame of vid
flag=0 'so no checking a vid that isn't running
end if
end if
sleep_ 50 'thread safe sleep
loop while vtp=""
'vtp=curdir+"\vid\"+vtp 'add the path to the video file (not needed if all vids in the program dir)
line(hor-2,ver-2)-(hor+vw+2,ver+vh+2),&hc0c0c0,b 'just a border round the video
line(hor-1,ver-1)-(hor+vw+1,ver+vh+1),&hc0c0c0,b '2 lines thick
mciSendString("open "+Chr(34)+vtp+Chr(34)+" type mpegvideo alias vid",NULL,0,0) 'vid now holds device\path\filename
mciSendString("window vid handle "&windo,0,0,0) 'this makes vid appear in your program screen
mciSendString("put vid destination at "+str(hor)+" "+str(ver)+" "+str(vw)+" "+str(vh),0,0,0) 'everything is strings!
mciSendString("play vid",NULL,0,0)
vtp="" 'null vtp so it's back in loop waiting for next vid
flag=1 'so it can start to find out when the video has finished playing
wend
end sub
First of all I just wanna say I can not believe that NO-ONE has posted code to simply just play a common mpeg file. There are plenty MP3 and sound but none for video and the useless examples given with FB just don't work.
Anyway... in WinXP I put together some code that actually worked albeit with problems but it did the job. Now, i'm using Win10 ver 10.0.018362 and of course I can't play video in FB now. Actually the video plays but you just get sound and no video. The code that worked in XP (and Win7/8) and worked well is below for you to try (just run it and it will play the video till end and sleep till you hit a key but can ESC anytime). I have heard that they dropped DSHOW in win10 as DirectX does not contain it anymore but not sure if this has anything to do with my problem as the vid plays and you can hear it just no actual video can be seen.
Anyway hope someone out there can help or just provide NEW code to simple just play a damn vid in FB. Oh yer using FB v1.01 but have tried latest versions even 64bit FB but no diff.
Code: Select all
#include once "win/dshow.bi"
screencontrol(103,"GDI") 'use GDI driver else video flickers badly in Win10 with directx
screenres 800,600,32
declare sub playvid(param as any ptr)
dim shared as string vid
dim shared as integer terminate,flag,t=48
dim shared HWND as hwnd
screencontrol(2,cast(integer,hwnd))
dim shared as any ptr thread,p
thread=threadcreate(@playvid,0)
sleep 100
'p=imagecreate(160,120)
vid="C:\Users\Name\Videos\somevideo.mpg" 'insert your video file here (.mpg or .vob)
sleep
terminate=1
threadwait(thread)
'imagedestroy(p)
sub playvid(param as any ptr)
dim as any ptr evCode,param1,param2
dim as uinteger sh,sw,hor,ver,wid,hei,flag2,pevc,pp1,pp2,vidon
sw=800
sh=600
evCode=@pevc
param1=@pp1
param2=@pp2
if sh<601 then
hor=sw/2-80
wid=160
hei=120
else
hor=sw/2-160
wid=320
hei=240
end if
ver=sh/2+92
vid="dummy" 'needed else exits with error if ESC before vid plays
dim as IGraphBuilder Ptr pGraph
dim as IMediaEvent Ptr pEvent
dim as IMediaControl Ptr pControl
dim as IVideoWindow Ptr vidwindow
while (1)
do
if terminate then
IMediaControl_Stop(pControl)
IBasicVideo_Release(pEvent)
IBasicVideo_Release(pControl)
IBasicVideo_Release(pGraph)
IBasicVideo_Release(vidwindow)
CoUninitialize()
exit sub
end if
if flag2=1 then
sleep_ 50
IMediaEvent_GetEvent(pEvent,evCode,param1,param2,0)
if pevc=1 then 'if vid has ended
line(hor-2,ver-2)-(hor+wid+2,ver+hei+2),&h000000,bf 'line(350,474)-(674,718),&h000000,bf
vidon=0
flag2=2 'so only calls IMediaEvent after a vid is played
end if
if flag then 'for when you blank it out with text
IVideoWindow_put_visible(vidwindow,oafalse)
IVideoWindow_put_visible(vidwindow,oatrue)
end if
end if
sleep_ 50
loop while vid=""
vidon=1
if flag2 then
line(hor-2,ver-2)-(hor+wid+2,ver+hei+2),&hc0c0c0,b
line(hor-1,ver-1)-(hor+wid+1,ver+hei+1),&hc0c0c0,b
IMediaControl_Stop(pControl)
IBasicVideo_Release(pEvent)
IBasicVideo_Release(pControl)
IBasicVideo_Release(pGraph)
IBasicVideo_Release(vidwindow)
CoUninitialize()
end if
if flag2 then
dim as IGraphBuilder Ptr pGraph
dim as IMediaEvent Ptr pEvent
dim as IMediaControl Ptr pControl
dim as IVideoWindow Ptr vidwindow
end if
dim pasta as any ptr
dim msg as integer
pasta=@msg
Var hr=CoInitialize(0)
hr=CoCreateInstance(@CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,@IID_IGraphBuilder,@pGraph)
hr=IGraphBuilder_QueryInterface(pGraph,@IID_IMediaEvent,@pEvent)
hr=IGraphBuilder_QueryInterface(pGraph,@IID_IMediaControl,@pControl)
hr=IGraphBuilder_QueryInterface(pGraph,@IID_IVideoWindow,@vidwindow)
IGraphBuilder_RenderFile(pGraph,vid,NULL)
'IVideoWindow_put_FullScreenMode(vidwindow,oatrue) 'puts in fullscreen mode
IVideoWindow_put_Owner(vidwindow,cast(integer,hwnd))
'take this next line out then it draws in your screen but in window (full screen only)
IVideoWindow_put_WindowStyle(vidwindow,WS_CHILD or WS_CLIPSIBLINGS or WS_CLIPCHILDREN)
IVideoWindow_SetWindowPosition(vidwindow,cast(uinteger,hor),cast(uinteger,ver),cast(uinteger,wid),cast(uinteger,hei))
IMediaControl_Run(pControl)
vid=""
'IMediaEvent_WaitForCompletion(pEvent,-1,pasta)
flag2=1
wend
end sub