]> gitweb.factorcode.org Git - factor.git/commitdiff
windows.winmm: Add binding to play mp3s.
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 26 Apr 2013 18:06:49 +0000 (11:06 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 26 Apr 2013 18:06:49 +0000 (11:06 -0700)
basis/windows/windows.factor
basis/windows/winmm/authors.txt [new file with mode: 0644]
basis/windows/winmm/winmm.factor [new file with mode: 0644]

index 83a5689cb35be98c2ddeebf5e026137a2e4c9f1a..fff734b0ff966cc09e8bfcce831f3c65d0d64056 100644 (file)
@@ -22,4 +22,5 @@ CONSTANT: MAX_UNICODE_PATH 32768
     { "ole32"       "ole32.dll"          stdcall }
     { "usp10"       "usp10.dll"          stdcall }
     { "psapi"       "psapi.dll"          stdcall }
+    { "winmm"       "winmm.dll"          stdcall }
 } [ first3 add-library ] each
diff --git a/basis/windows/winmm/authors.txt b/basis/windows/winmm/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/basis/windows/winmm/winmm.factor b/basis/windows/winmm/winmm.factor
new file mode 100644 (file)
index 0000000..29908c7
--- /dev/null
@@ -0,0 +1,40 @@
+! Copyright (C) 2013 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: alien.c-types alien.syntax byte-arrays formatting kernel
+math windows.types ;
+IN: windows.winmm
+
+LIBRARY: winmm
+
+TYPEDEF: int MCIERROR
+
+FUNCTION: MCIERROR mciSendStringW (
+  LPCTSTR lpszCommand,
+  LPTSTR lpszReturnString,
+  UINT cchReturn,
+  HANDLE hwndCallback
+) ;
+
+ALIAS: mciSendString mciSendStringW
+
+ERROR: mci-error n ;
+
+: check-mci-error ( n -- )
+    [ mci-error ] unless-zero ;
+
+: open-command ( path -- )
+    "open \"%s\" type mpegvideo alias MediaFile" sprintf f 0 f
+    mciSendString check-mci-error ;
+    
+: play-command ( -- )
+    "play MediaFile" f 0 f mciSendString check-mci-error ;
+
+: pause-command ( -- )
+    "pause MediaFile" f 0 f mciSendString check-mci-error ;
+
+: status-command ( -- bytes )
+    "status MediaFile mode" 128 <byte-array> [ 0 f mciSendString check-mci-error ] keep ;
+
+
+: close-command ( -- )
+    "close MediaFile" f 0 f mciSendString check-mci-error ;
\ No newline at end of file