music.rb 895 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Models music (an audio stream) that has been loaded from disk
  2. # and kept in storage
  3. class Music < Store
  4. extend Store::Forward
  5. # Loads music/audio stream.
  6. # Supports .ogg, .it, .mod, .s3m and .xm files.
  7. def self.load(name, vpath, buffer_count=8, samples=8000)
  8. load_something(forward_name(name), vpath, self) do | nid |
  9. Eruta::Store.load_audio_stream(nid, vpath, buffer_count, samples)
  10. end
  11. end
  12. # Returns true if music is playing, false if not
  13. def self.playing?
  14. return Eruta::Audio.music_playing?
  15. end
  16. # Plays this music as the current music starting from the beginning
  17. # without transition
  18. def play!
  19. Eruta::Audio.music_id = @id
  20. return Eruta::Audio.play_music
  21. end
  22. # Stops playing the music immediately
  23. def self.stop!
  24. Eruta::Audio.stop_music
  25. end
  26. # Stops playing the music immediately
  27. def stop!
  28. Music.stop!
  29. end
  30. end