Created
September 3, 2014 20:52
-
-
Save chozabu/b97daecbaaa5a2209286 to your computer and use it in GitHub Desktop.
crash testing kivy audio
This file contains hidden or 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
''' | |
Audio example | |
============= | |
altered to loop. set several sounds playing and wibble volume to induce crash | |
All the sounds are from the http://woolyss.com/chipmusic-samples.php | |
"THE FREESOUND PROJECT", Under Creative Commons Sampling Plus 1.0 License. | |
''' | |
import kivy | |
kivy.require('1.0.8') | |
from kivy.app import App | |
from kivy.uix.button import Button | |
from kivy.uix.boxlayout import BoxLayout | |
from kivy.core.audio import SoundLoader | |
from kivy.properties import StringProperty, ObjectProperty, NumericProperty | |
from glob import glob | |
from os.path import dirname, join, basename | |
class AudioButton(Button): | |
filename = StringProperty(None) | |
sound = ObjectProperty(None, allownone=True) | |
volume = NumericProperty(1.0) | |
def on_press(self): | |
if self.sound is None: | |
self.sound = SoundLoader.load(self.filename) | |
self.sound.loop = True | |
# stop the sound if it's currently playing | |
if self.sound.status != 'stop': | |
self.sound.stop() | |
else: | |
self.sound.volume = self.volume | |
self.sound.play() | |
def release_audio(self): | |
if self.sound: | |
self.sound.stop() | |
self.sound.unload() | |
self.sound = None | |
def set_volume(self, volume): | |
self.volume = volume | |
if self.sound: | |
self.sound.volume = volume | |
class AudioBackground(BoxLayout): | |
pass | |
class AudioApp(App): | |
def build(self): | |
root = AudioBackground(spacing=5) | |
for fn in glob(join(dirname(__file__), '*.wav')): | |
print fn | |
btn = AudioButton( | |
text=basename(fn[:-4]).replace('_', ' '), filename=fn, | |
size_hint=(None, None), halign='center', | |
size=(128, 128), text_size=(118, None)) | |
root.ids.sl.add_widget(btn) | |
return root | |
def release_audio(self): | |
for audiobutton in self.root.ids.sl.children: | |
audiobutton.release_audio() | |
def set_volume(self, value): | |
for audiobutton in self.root.ids.sl.children: | |
audiobutton.set_volume(value) | |
if __name__ == '__main__': | |
AudioApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment