Skip to content

Instantly share code, notes, and snippets.

@omz
Created April 7, 2014 16:40
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save omz/10023837 to your computer and use it in GitHub Desktop.
Save omz/10023837 to your computer and use it in GitHub Desktop.
Sound Demo
# 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