blob: d3f747f863d711ae0832de9f077a105b4aa1c6b8 [file] [log] [blame]
Guido van Rossum2cc340d1999-02-02 15:14:37 +00001/*
2 * SOUND
3 * $Id$
4 *
5 * play sound on a windows platform
6 *
7 * history:
8 * 99-02-02 fl created
9 *
10 * Copyright (c) 1999 by Secret Labs AB.
11 * Copyright (c) 1999 by Fredrik Lundh.
12 *
13 * fredrik@pythonware.com
14 * http://www.pythonware.com
15 *
16 * --------------------------------------------------------------------
17 * Permission to use, copy, modify, and distribute this software and
18 * its associated documentation for any purpose and without fee is
19 * hereby granted. This software is provided as is.
20 * --------------------------------------------------------------------
21 */
22
23#include "Python.h"
24
25#include "windows.h"
26#include "mmsystem.h"
27
28static PyObject*
29_play(PyObject* self, PyObject* args)
30{
31 int result;
32
33 /* first argument is a string that should contain the contents of
34 a WAV file. second argument should be non-zero to wait for the
35 sound to complete. */
36
37 char *data = NULL;
38 int bytes;
39 int wait = 0;
40 if (!PyArg_ParseTuple(args, "|s#i", &data, &bytes, &wait))
41 return NULL;
42
43 result = PlaySound(data, NULL, (SND_MEMORY|SND_NOWAIT|SND_NODEFAULT) |
44 (wait ? 0 : SND_ASYNC));
45
46 return Py_BuildValue("i", result);
47}
48
49static PyObject*
50_stop(PyObject* self, PyObject* args)
51{
52 if (!PyArg_NoArgs(args))
53 return NULL;
54
55 return Py_BuildValue("i", PlaySound(NULL, NULL, 0));
56}
57
58static PyMethodDef _functions[] = {
59 {"play", _play, 1},
60 {"stop", _stop, 0},
61 {NULL, NULL}
62};
63
64void
65#ifdef WIN32
66__declspec(dllexport)
67#endif
68initwinsound()
69{
70 Py_InitModule("winsound", _functions);
71}