summaryrefslogtreecommitdiffstats
path: root/Modules/winsound.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-02-02 15:14:37 (GMT)
committerGuido van Rossum <guido@python.org>1999-02-02 15:14:37 (GMT)
commit2cc340d1221bc74de49b5557a06a6905b5306f5e (patch)
tree8507bffa2441eb579c496153d6dafa0443f2af75 /Modules/winsound.c
parent246bc17a8b680fd08af7aeb405e8d0feed3fb9f5 (diff)
downloadcpython-2cc340d1221bc74de49b5557a06a6905b5306f5e.zip
cpython-2cc340d1221bc74de49b5557a06a6905b5306f5e.tar.gz
cpython-2cc340d1221bc74de49b5557a06a6905b5306f5e.tar.bz2
Windows sound playing module, by Fredrik Lundh.
Diffstat (limited to 'Modules/winsound.c')
-rw-r--r--Modules/winsound.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/Modules/winsound.c b/Modules/winsound.c
new file mode 100644
index 0000000..d3f747f
--- /dev/null
+++ b/Modules/winsound.c
@@ -0,0 +1,71 @@
+/*
+ * SOUND
+ * $Id$
+ *
+ * play sound on a windows platform
+ *
+ * history:
+ * 99-02-02 fl created
+ *
+ * Copyright (c) 1999 by Secret Labs AB.
+ * Copyright (c) 1999 by Fredrik Lundh.
+ *
+ * fredrik@pythonware.com
+ * http://www.pythonware.com
+ *
+ * --------------------------------------------------------------------
+ * Permission to use, copy, modify, and distribute this software and
+ * its associated documentation for any purpose and without fee is
+ * hereby granted. This software is provided as is.
+ * --------------------------------------------------------------------
+ */
+
+#include "Python.h"
+
+#include "windows.h"
+#include "mmsystem.h"
+
+static PyObject*
+_play(PyObject* self, PyObject* args)
+{
+ int result;
+
+ /* first argument is a string that should contain the contents of
+ a WAV file. second argument should be non-zero to wait for the
+ sound to complete. */
+
+ char *data = NULL;
+ int bytes;
+ int wait = 0;
+ if (!PyArg_ParseTuple(args, "|s#i", &data, &bytes, &wait))
+ return NULL;
+
+ result = PlaySound(data, NULL, (SND_MEMORY|SND_NOWAIT|SND_NODEFAULT) |
+ (wait ? 0 : SND_ASYNC));
+
+ return Py_BuildValue("i", result);
+}
+
+static PyObject*
+_stop(PyObject* self, PyObject* args)
+{
+ if (!PyArg_NoArgs(args))
+ return NULL;
+
+ return Py_BuildValue("i", PlaySound(NULL, NULL, 0));
+}
+
+static PyMethodDef _functions[] = {
+ {"play", _play, 1},
+ {"stop", _stop, 0},
+ {NULL, NULL}
+};
+
+void
+#ifdef WIN32
+__declspec(dllexport)
+#endif
+initwinsound()
+{
+ Py_InitModule("winsound", _functions);
+}