Created
October 18, 2013 20:32
-
-
Save tshirtman/7047781 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MediaPlayer(object): | |
''' | |
MediaPlayer object is used to avoid keeping multiple sound files in memory | |
''' | |
def __init__(self): | |
self._media_player = None | |
def play_sound(self, soundfile, volume): | |
if not soundfile.startswith('/'): | |
soundfile = join(getcwd(), 'sounds', soundfile) | |
if platform == 'android': | |
if self._media_player: | |
if self._media_player.isPlaying(): | |
self._media_player.stop() | |
self._media_player.release() | |
self._media_player = media_player = MP() | |
media_player.setDataSource(soundfile) | |
media_player.prepare() | |
# XXX | |
media_player.setVolume(float(volume), float(volume)) | |
media_player.start() | |
return media_player | |
else: | |
print "XXX play_sound not implemented on %s" % platform | |
play_sound = MediaPlayer().play_sound |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment