No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

music.py 859B

1234567891011121314151617181920212223242526272829303132333435
  1. from __future__ import print_function
  2. import sys
  3. from PySide import phonon
  4. class MusicBox(object):
  5. # default media
  6. media = {}
  7. # state
  8. _media_obj = None
  9. @classmethod
  10. def init(clazz):
  11. clazz._output = phonon.Phonon.AudioOutput(phonon.Phonon.MusicCategory)
  12. clazz._media_obj = phonon.Phonon.MediaObject()
  13. phonon.Phonon.createPath(clazz._media_obj, clazz._output)
  14. @classmethod
  15. def add_music(clazz, name, media_path):
  16. clazz.media[name] = phonon.Phonon.MediaSource(media_path)
  17. @classmethod
  18. def play_music(clazz, name):
  19. try:
  20. clazz._media_obj.setCurrentSource(clazz.media[name])
  21. clazz._media_obj.play()
  22. except KeyError:
  23. print("Warning: Song '%s' is missing, not found in media base" % (name,), file=sys.stderr)
  24. @classmethod
  25. def stop_music(clazz):
  26. # use pause so we don't stop having the device open
  27. clazz._media_obj.pause()