Skip to content

Commit

Permalink
Volume
Browse files Browse the repository at this point in the history
  • Loading branch information
gundlach committed Aug 18, 2008
1 parent ac460ea commit 33bedeb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
7 changes: 6 additions & 1 deletion mp3play/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ def play(self, start_ms=None, end_ms=None):
else:
return self._clip.play(start_ms, end_ms)

def volume(self, level):
"""Sets the volume between 0 and 100."""
assert level >=0 and level <= 100
return self._clip.volume(level)

def isplaying(self):
"""Returns True if the clip is currently playing. Note that if a
clip is paused, or if you called play() on a clip and playing has
clip is paused, or if you called play() on a clip and playing has
completed, this returns False."""
return self._clip.isplaying()

Expand Down
6 changes: 6 additions & 0 deletions mp3play/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def directsend(self, txt):
# TODO: detect errors in all mci calls
class AudioClip(object):
def __init__(self, filename):
filename = filename.replace('/', '\\')
self.filename = filename
self._alias = 'mp3_%s' % str(random.random())

Expand All @@ -41,6 +42,11 @@ def __init__(self, filename):
err, buf=self._mci.directsend('status %s length' % self._alias)
self._length_ms = int(buf)

def volume(self, level):
"""Sets the volume between 0 and 100."""
self._mci.directsend('setaudio %s volume to %d' %
(self._alias, level * 10) )

def play(self, start_ms=None, end_ms=None):
start_ms = 0 if not start_ms else start_ms
end_ms = self.milliseconds() if not end_ms else end_ms
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup

setup(name='mp3play',
version='0.1.10',
version='0.1.15',
packages=['mp3play'],

description="A simple interface for playing music from an MP3 file.""",
Expand Down Expand Up @@ -41,7 +41,9 @@
Requires Windows XP at the moment, but the goal is to make a
cross-platform module. Feel free to send patches to add Linux and
Mac support!
Mac support! Note that the module's purpose is to be easy_installable
with no other work needed by the user, so things like AVLib are out unless
that can be easy_installed automatically alongside mp3play.
Resources
=========
Expand All @@ -64,7 +66,7 @@
keywords = "mp3 api play music audio python module",

classifiers=[
'Development Status :: 5 - Production/Stable',
'Development Status :: 3 - Alpha',
'Environment :: Win32 (MS Windows)',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
Expand Down
4 changes: 3 additions & 1 deletion upload
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
# isn't one already!

/cygdrive/c/Program\ Files/Python25/python.exe setup.py bdist_egg sdist upload
/cygdrive/c/Program\ Files/Python24/python.exe setup.py bdist_egg upload
# don't do 2.4 because it doesn't work for 2.4 yet -- a couple dumb syntax
# things.
#/cygdrive/c/Program\ Files/Python24/python.exe setup.py bdist_egg upload

0 comments on commit 33bedeb

Please sign in to comment.