Created
April 7, 2014 16:40
-
-
Save omz/10023837 to your computer and use it in GitHub Desktop.
Sound Demo
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
# Simple demo of playing a looping sound using the (currently undocumented) sound.Player class | |
import sound | |
import os | |
from scene import * | |
class MyScene (Scene): | |
def setup(self): | |
self.player = sound.Player(os.path.expanduser('~/Pythonista.app/Beep.caf')) | |
self.player.number_of_loops = -1 #repeat forever | |
self.playing = False | |
def draw(self): | |
background(0, 0, 0) | |
x, y = self.size.w * 0.5, self.size.h * 0.5 | |
text('Touch to play/pause', 'Helvetica', 30, x, y) | |
def touch_began(self, touch): | |
if self.playing: | |
self.player.stop() | |
else: | |
self.player.play() | |
self.playing = not self.playing | |
run(MyScene()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment