October 28, 2020, 05:58:59 AM

Author Topic: [bb] MciSendString by jfk EO-11110 [ 1+ years ago ]  (Read 1665 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] MciSendString by jfk EO-11110 [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : MciSendString
Author : jfk EO-11110
Posted : 1+ years ago

Description : This was written initially by Sswift for a DLL wrapper. I have edited it so it works directly with a winmm.decls userlib.
Quote of Sswift to Coppercircle:
"Hey Coppercircle... Maybe you should post this in the code archives?" ( <a href="http://blitzbasic.com/Community/posts.php?topic=33476" target="_blank">from here[/url] ) , so I think it's ok to post it in the Archive.


Code :
Code: BlitzBasic
  1. ; MCI Wrapper - Written by Shawn C. Swift
  2. ; To use this system to display an AVI, you will need to call mciOpen, then mciWindow, then mciPlay.
  3.  
  4. ; -------------------------------------------------------------------------------------------------------------------------------------
  5. ; This function opens a new mci device.
  6. ;
  7. ; DeviceName$ will be the name which you use to give the device commands later.
  8. ;
  9. ; Device should be one of the following:  
  10. ;
  11. ;       0 = "cdaudio"           - For playing tracks on a CD.
  12. ;       1 = "AVIVideo"          - For playing AVI and other video files.
  13. ;       2 = "sequencer"     - For playing MIDI files.
  14. ;       3 = "waveaudio"         - For playing WAV files.
  15. ;
  16. ; Filename$ is an optional parameter to specify the file you wish to be loaded when the device is created.
  17. ; I don't think the mciLoad command can load audio later though, so for WAV files, you might have to use filename here.
  18. ; -------------------------------------------------------------------------------------------------------------------------------------
  19.  
  20.  
  21. ; partially edited by jfk of csp
  22. ;...
  23.  
  24. ; you need these userlib decls in "winmm.decls" :
  25. ; ***********************************************
  26.  
  27. ;.lib "winmm.dll" ; this is a standard windows file
  28. ;mciExecute%(Text$)
  29. ;mciSendString%(Command$,ReturnString*,ReturnLength%,Callback):"mciSendStringA"
  30.  
  31.  
  32. ; for more infos about MciSendString Commands goto msdn.com and search for "MciSendString"
  33.  
  34.  
  35. Global ScreenWidth=1024
  36. Global ScreenHeight=768
  37.  
  38. Graphics ScreenWidth,ScreenHeight,32,1
  39. SetBuffer FrontBuffer()
  40.  
  41. Global generic_bank=CreateBank(4096) ; used for Mci answers
  42.  
  43.  
  44.  
  45.  
  46.  
  47. device_name$="AVIVideo" +MilliSecs()+Rand(100) ; create a unique handle to allow multiple movies
  48. myHWND=SystemProperty$("AppHWND")
  49.  
  50. mciOpen(device_name$,"csp_intro_2005mp4.avi")
  51. mciWindow(device_name$,myHWND) ; hook movie on blitz frontbuffer (requires fullscreen)
  52.  
  53.  
  54. mciSize(device_name$, 10,10,320,240) ; scale and position as desired
  55. mciSetAudioVolume(device_name$,500) ;0 to 1000... don't works! (only alters the main Volume, instead of movie volume!)
  56.  
  57. mciSet(device_name$,"seek exactly on") ; turn on "seek exactly"
  58. mciSet(device_name$,"time format frames")
  59.  
  60. movie_length=mciStatus(device_name$,"length")
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. mciPlay(device_name$,"repeat") ; start playing, with loop option
  69. t1=MilliSecs()+100000
  70. While (KeyDown(1)=0) And (MilliSecs()<t1)
  71.  Delay 10
  72.  cuf=mciStatus(device_name$,"position") ; get current frame number
  73.  Color 0,0,0
  74.  Rect 0,400,300,30,1
  75.  Color 0,255,0
  76.  Locate 0,400
  77.  Print cuf+" of "+movie_length+" Frames"
  78.  ; you may capture frames using copyrect on the frontbuffer in fullscreen mode...
  79. Wend
  80.  
  81. mciStop(device_name$)
  82. mciClose(device_name$) ; never forget this
  83.  
  84. WaitKey()
  85. End
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. ; -------------------------------------------------------------------------------------------------------------------------------------
  97. Function mciUpdate(DeviceName$,dc)
  98.         mciSendString("update " + DeviceName$ + " hdc "+dc,generic_bank,0,0)
  99. End Function
  100.  
  101.  
  102. ; -------------------------------------------------------------------------------------------------------------------------------------
  103. Function mciOpen(DeviceName$, FileName$="")
  104.        
  105.         Local hWND
  106.         Local DeviceType$
  107.        
  108.         mciSendString("OPEN " + FileName$ + " TYPE AVIVIDEO ALIAS "+DeviceName$+" STYLE POPUP",generic_bank,0,0)
  109.  
  110. End Function
  111.  
  112.  
  113. ; -------------------------------------------------------------------------------------------------------------------------------------
  114. ; This function sets the window which an mci device should display its media in and the display properties for that window.
  115. ; -------------------------------------------------------------------------------------------------------------------------------------
  116. Function mciWindow(DeviceName$, Parent)
  117.        
  118.         Local hWND
  119.        
  120.         hWND = Parent ;QueryObject(Parent, 1)
  121.         mciSendString("window " + DeviceName$ + " handle " + Str$(hWND),generic_bank,0,0)
  122.                
  123. End Function
  124.  
  125.  
  126. ; -------------------------------------------------------------------------------------------------------------------------------------
  127. ; This function loads a file into an mci digital-video or video-overlay device.
  128. ; I don't think it will load waveaudio, which is why I included the optional filename parameter on the mciOpen command.
  129. ; -------------------------------------------------------------------------------------------------------------------------------------
  130. Function mciLoad(DeviceName$, FileName$)
  131.         mciSendString("load " + DeviceName$ + " " + FileName$,generic_bank,0,0)
  132. End Function   
  133.        
  134.  
  135. ; -------------------------------------------------------------------------------------------------------------------------------------
  136. ; This function changes the settings of an mci digital-video device, if said device supports them.
  137. ; (Mine does not.)
  138. ;
  139. ; Here are the settings you can use for Option$:
  140. ;
  141. ;       "brightness" - 0..1
  142. ;       "color"          - 0..1
  143. ;       "contrast"       - 0..1
  144. ;       "tint"           - 0.0 = Blue, 0.25 = Green, 0.5 = Normal, 0.75 = Red, 1.0 = Blue
  145. ;       "sharpness"      - 0..1
  146. ;       "gamma"          - 1.0 = No gamma correction, 2.2 = Windows gamma
  147. ;      
  148. ; -------------------------------------------------------------------------------------------------------------------------------------
  149. Function mciSetVideo(DeviceName$, Option$, Value#=0)
  150.         ;mciSendString("setvideo " + DeviceName$ + " " + Option$ + " to " + Int(Value#*1000.0))
  151.         mciSendString("setvideo " + DeviceName$ + " brightness to 100",generic_bank,0,0)       
  152. End Function   
  153.  
  154.  
  155. ; -------------------------------------------------------------------------------------------------------------------------------------
  156. ; This function changes certain settings of the specified mci device.
  157. ;
  158. ; The following options may be specified.  Multiple options can be seperated with a space.
  159. ;
  160. ;       "audio all off"      -  Turns off audio.
  161. ;       "audio all on"       -  Turns on audio.
  162. ;
  163. ;       "door open"                  -  Opens the cd door.
  164. ;       "door closed"        -  Closes the cd door.
  165. ;
  166. ;       "seek exactly on"    -  Enables seeking to the exact frame specified.
  167. ;       "seek exactly off"   -  When seeking, seeks only to the nearest keyframe. (Presumed to be faster.)
  168. ;
  169. ;       "speed FACTOR"       -  Sets the speed of playback, where FACTOR is the desired multiple of the normal speed multiplied by 1000.
  170. ;                                                       Ie, 1.0, the normal speed, becomes 1000.  2.0, twice normal speed becomes 2000.  And 0.5 becomes 500.
  171. ;                                                       FACTOR must be an integer.  A speed of 0 plays back the video as fast as possible without dropping
  172. ;                                                       frames, but without audio.
  173. ;
  174. ;       "time format FORMAT" -  Sets the format for time used by the seek command.
  175. ;
  176. ;                                                       Where FORMAT is the following:
  177. ;                                                      
  178. ;                                                       For digital-video: "frames" or "milliseconds"
  179. ;
  180. ;                                                       For CD-audio: "msf" or "tmsf" which are in the format:
  181. ;                                                       "minutes:seconds:frames" or "tracks:minutes:seconds:frames" where the max values for each are:
  182. ;                                                       "99:59:74" and "99:99:59:74"
  183. ;                                                      
  184. ;                                                       For wavaudio: "bytes", "milliseconds", or "samples"
  185. ;                                              
  186. ;                                                       For sequencer: "milliseconds"
  187. ;
  188. ; -------------------------------------------------------------------------------------------------------------------------------------
  189. Function mciSet(DeviceName$, Option$)
  190.         mciSendString("set " + DeviceName$ + " " + Option$,generic_bank,0,0)
  191. End Function
  192.  
  193. ; added by jfk:
  194. Function mciSetAudioVolume(DeviceName$, volume,tp$="",nr=0)
  195.     PokeInt generic_bank,0,0
  196.     If volume<  0 Then volume=0
  197.     If volume>1000 Then volume=1000
  198.         mciSendString("setaudio " + DeviceName$ + " volume to " + volume,generic_bank,4,0)
  199.     Return PeekInt(generic_bank,0)
  200. End Function
  201.  
  202.  
  203. ; added by jfk:
  204. Function mciSize(DeviceName$, x,y,w,h)
  205.         mciSendString("put " + DeviceName$ + " destination at " +x+" "+y+" "+w+" "+h,generic_bank,0,0)
  206. End Function
  207.  
  208.  
  209. Function mciCapability(DeviceName$, feature$)
  210.     PokeInt generic_bank,0,0
  211.         mciSendString("capability " + DeviceName$ + " "+feature$,generic_bank,4,0)
  212.     Return PeekInt(generic_bank,0)
  213. End Function
  214.  
  215.  
  216. Function mciGetDeviceType$(DeviceName$)
  217.     For i=0 To 1001
  218.      PokeByte generic_bank,i,0
  219.     Next
  220.         mciSendString("capability " + DeviceName$ + " device type",generic_bank,100,0)
  221.         ret$=""
  222.         Repeat
  223.          pp=PeekByte(generic_bank,c)
  224.      If pp<>0 Then
  225.       ret$=ret$+Chr$(pp)
  226.      EndIf
  227.          c=c+1
  228.         Until (pp=0) Or (c>1000)
  229.     Return ret$
  230. End Function
  231.  
  232. Function mciStatus$(DeviceName$,what$)
  233.     For i=0 To 1001
  234.      PokeByte generic_bank,i,0
  235.     Next
  236.         mciSendString("status " + DeviceName$ + " "+what$,generic_bank,100,0)
  237.         ret$=""
  238.         Repeat
  239.          pp=PeekByte(generic_bank,c)
  240.      If pp<>0 Then
  241.       ret$=ret$+Chr$(pp)
  242.      EndIf
  243.          c=c+1
  244.         Until (pp=0) Or (c>1000)
  245.     Return ret$
  246. End Function
  247.  
  248.  
  249.  
  250.  
  251. ; -------------------------------------------------------------------------------------------------------------------------------------
  252. ; This function plays the specified mci device.
  253. ;
  254. ; Option may be set to the following:
  255. ;
  256. ;       "fullscreen" - Sets the video to full screen.  Uncompressed video will not play in full screen.
  257. ;       "window"         - Sets the video the play back in it's parent window.
  258. ;       "repeat"         - Restarts playback from the beginning once it reaches the end.
  259. ;       "reverse"        - Specifies that the video plays back backwards.
  260. ;
  261. ;   "from POSITION"                                     - Specifies that the video plays back starting at the position specified.  
  262. ;       "from POSITION1 to POSITION2"   - Specifies that the video plays from point A to point B.  (Cannot be used with reverse.)
  263. ;
  264. ; You may specify more than one option at a time if you seperate each with a space.
  265. ; -------------------------------------------------------------------------------------------------------------------------------------
  266. Function mciPlay(DeviceName$, Option$="")
  267.  
  268.         If Option$ <> ""
  269.                 mciSendString("play " + DeviceName$ + " " + Option$,generic_bank,0,0)          
  270.         Else
  271.                 mciSendString("play " + DeviceName$,generic_bank,0,0)
  272.         EndIf  
  273.        
  274. End Function
  275.  
  276.  
  277. ; -------------------------------------------------------------------------------------------------------------------------------------
  278. ; This function pauses the specified mci device.
  279. ; -------------------------------------------------------------------------------------------------------------------------------------
  280. Function mciPause(DeviceName$)
  281.         mciSendString("pause " + DeviceName$,generic_bank,0,0)
  282. End Function
  283.  
  284.  
  285. ; -------------------------------------------------------------------------------------------------------------------------------------
  286. ; This function unpauses the specified mci device.
  287. ; (May not work with all devices?)
  288. ; -------------------------------------------------------------------------------------------------------------------------------------
  289. Function mciResume(DeviceName$)
  290.         mciSendString("resume " + DeviceName$,generic_bank,0,0)        
  291. End Function
  292.  
  293.  
  294. ; -------------------------------------------------------------------------------------------------------------------------------------
  295. ; This function causes the specified mci device to seek to a position and stop.
  296. ;
  297. ; Position$ =
  298. ;       "start"    - Seek to the start of the media.
  299. ;       "end"      - Seek to the end of the media.
  300. ;       "POSITION" - Seek to a specified position in the media, where POSITION is frames, milliseconds, or whatever the
  301. ;                                currently selected time format is.  Ie: "635"
  302. ; -------------------------------------------------------------------------------------------------------------------------------------
  303. Function mciSeek(DeviceName$, Position$)
  304.         mciSendString("seek " + DeviceName$ + " to " + Position$,generic_bank,0,0)
  305. End Function
  306.  
  307.  
  308. ; -------------------------------------------------------------------------------------------------------------------------------------
  309. ; This function causes the specified mci digital-video device to step a specified number of frames forward or back.
  310. ; Frames can be a positive or negative value.
  311. ; -------------------------------------------------------------------------------------------------------------------------------------
  312. Function mciStep(DeviceName$, Frames)
  313.         mciSendString("step " + DeviceName$ + " by " + Str$(Frames),generic_bank,0,0)
  314. End Function
  315.  
  316.  
  317. ; -------------------------------------------------------------------------------------------------------------------------------------
  318. ; This function stops a device.
  319. ; -------------------------------------------------------------------------------------------------------------------------------------
  320. Function mciStop(DeviceName$)
  321.         mciSendString("stop " + DeviceName$,generic_bank,0,0)
  322. End Function
  323.  
  324.  
  325. ; added by jfk
  326. Function mciClose(DeviceName$)
  327.         mciSendString("close " + DeviceName$,generic_bank,0,0)
  328. End Function
  329.  
  330. Function mciCapture(DeviceName$,savepath$) ; didn't work for some reason
  331.     If savepath$<>""
  332.          mciSendString("capture " + DeviceName$+" as "+savepath$,generic_bank,4,0)
  333.         EndIf
  334. End Function
  335.  
  336.  
  337.  
  338. ; -------------------------------------------------------------------------------------------------------------------------------------
  339. ; This function opens a configuration window for the specified mci device.
  340. ; -------------------------------------------------------------------------------------------------------------------------------------
  341. Function mciConfigure(DeviceName$)
  342.         mciSendString("configure " + DeviceName$,generic_bank,0,0)
  343. End Function


Comments :


Litobyte(Posted 1+ years ago)

 Hey , this is cute, because I can finally jump at a specific frame in a video, but I found the problem with this in comparison to ddraw internal blitz commands (or even winmediaplayer)This probably uses old mediaplayer (4 I guess) libraries, which supports system installed codecs but doesnt support a lot of nice features like resampling of the image.Basically, If I stretch my PAL 4:3 (720x576 pixels) video onto a let's say 4:3 1024 x 768 resolution, the video became croppy, with big big pixels, and compression making shit. So basically, is not usable for a real videoplayer.This is a shame, as the super solid blitz commands allow openmovie, closemovie only :-/Bye,


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal