Jump to content

MCISendString Video Playback


Marleys Ghost
 Share

Recommended Posts

I came across this today in my unfinished code archives and decided to finish it and thought I'd share. It works for windowed mode only but will allow a video splash screen to be played in the Leadwerks window. I have tested it using .avi, .mpg and wmv.

 

It makes use of the MCISendString function in windows. The easiest way to test this out is to use the Leadwerks Project Wizard and quickly make a test project.

 

 

Into the root of this test projects folder create a new .bmx file called win32.bmx and copy and paste the following code into it:

 

'=============================================================
'                         Setup Win32
'=============================================================

Import "-lshell32"

Extern "win32"
Function GetActiveWindow()
Function WinExec (lpCmdLine:Byte Ptr, nCmdShow:Int)
Function mciSendString:Int(pstrCommand$z, lpstrReturnStr$z, wReturnLen:Int, CallBack:Int) = "mciSendStringA@16"
End Extern

'=============================================================
'                     Video Splash Screen
'=============================================================


Function VideoSplash:Int(VFileName:String, VSplashX:Int, VSplashY:Int, VSplashW:Int, VSplashH:Int)
Local ReturnCode:Int

Local VFileType:String = ""
If Right$(VFilename,3)= "avi" Then VFileType = "AVI"
If Right$(VFilename,3)= "mpg" Then VFileType = "MPEG"
If Right$(VFilename,3)= "wmv" Then VFileType = "MPEG"

Local hWnd% = GetActiveWindow()
	ReturnCode = mciSendString("open " + Chr(34) + VFilename + Chr(34) + " type " + VFileType + "Video alias Video_Splash",Null,0,0)
If returncode<>0 Then 
	Notify "An error occurred opening device : Video Splash. Error code:" + returncode
	Return False
EndIf
	ReturnCode = mciSendString("window Video_Splash handle " + hWnd%,Null,0,0)
	ReturnCode = mciSendString("put Video_Splash destination at " + VSplashX + " " + VSplashY + " " + VSplashW + " " + VSplashH,Null,0,0)
	ReturnCode = mciSendString("play Video_Splash wait",Null,0,0)
	ReturnCode = mciSendString("Close Video_Splash",Null,0,0)
If returncode<>0 Then 
	Notify "An error occurred when playing the video file. Error code:" + returncode
	Return False
Else
	Return True 
EndIf
End Function


'=============================================================

 

Or download the .bmx here:

 

 

win32.bmx

 

 

In the projects bmx file you should see this:

 

 

'	====================================================================
'	This file was generated by Leadwerks C++/LEO/BlitzMax Project Wizard
'	Written by Rimfrost Software
'	http://www.rimfrost.com 
'	====================================================================

SuperStrict

Framework leadwerks.ENGINE

Local world:TWorld
Local gbuffer:TBuffer
Local camera:TCamera
Local mesh:TMesh
Local light:TLight
Local ground:TMesh
Local material:TMaterial

GCSetMode(2)

RegisterAbstractPath( "D:/Game Development/Leadwerks SDK 2.4" ) 

Graphics(800,600)

world=CreateWorld()
If Not world RuntimeError "Failed to create world."

gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_DEPTH|BUFFER_COLOR0|BUFFER_COL

OR1|BUFFER_COLOR2)

camera=CreateCamera()
PositionEntity camera,[0.0,0.0,-2.0]

material=LoadMaterial("abstract::cobblestones.mat")

mesh=CreateCube()
PaintEntity mesh,material

ground=CreateCube()
ScaleEntity ground,[10.0,1.0,10.0]
PositionEntity ground,[0.0,-2.0,0.0]
PaintEntity ground,material

light=CreateDirectionalLight()

RotateEntity light,[45.0,45.0,45.0]

Repeat

TurnEntity mesh,[AppSpeed()*0.5,AppSpeed()*0.5,AppSpeed()*0.5]

If KeyHit(KEY_ESCAPE) Exit
If AppTerminate() Exit

UpdateAppTime()
UpdateWorld(AppSpeed())

SetBuffer(gbuffer)
RenderWorld()
SetBuffer(BackBuffer())
RenderLights(gbuffer)

Flip(0)

Forever

gbuffer=Null
FreeEntity light
GCCollect()
End

 

 

 

First add the line:

 

Import "win32.bmx"

 

right after the line:

 

Framework leadwerks.ENGINE

 

Then add the line:

 

VideoSplash("Test.avi",0,0,800,600)

 

right after the line:

 

Graphics(800,600)

 

Note that the window resolution matches the last two numbers in the VideoSplash() command. "Test.avi" is the file to be played, this could be test.mpg or test.wmv or not called test at all.

 

The next two numbers represent where the top left of the video will be played in the window, here the very top left, and the last two numbers are the bottom right of the videos picture, here matching the resolution of the open window.

 

You can't use the abstract system with this command, so your video will have to go into the root of the project directory or the full path entered inside the quotes.

 

And thats it, the video should play inside the Leadwrks window, and when finished the spinning cube part of the app will continue as usual.

 

Nothing special, just thought I'd share. I Hope its of some use to someone.

  • Upvote 1

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...