Is there a way to play a song with Gosu without start the main loop
Something like this:
song = Gosu::Song.new("file.mp3")
break unless song.playing?
And why i get this error that works with
song = Gosu::Simple.new("file.mp3") # => RuntimeError: File contains data in an unknown format.
Thanks a lot! :)
I am not sure if you can use
Gosu::Song on a background thread; Gosu is designed to be used on the main thread (for now). However, there is a
Gosu::Song.update method that should be pretty much what you are looking for, if you have a way of regularly calling it from the main thread.
The MP3 loading bug should have been fixed in Gosu 0.14.3. If you are still experiencing this issue, can you please attach the MP3 file to your post?
There is definitely still a difference in the file type detection between Song and Sample. I have just tried to reproduce this with an MP3 file on my desktop, and it only worked in Sample(!). Turns out this file is actually an M4A file with the wrong extension... Not sure why Song can't stream the file. It might be a macOS-specific error too, because I use Apple's AudioToolbox for file loading on macOS and iOS.
I have opened an issue here: https://github.com/gosu/gosu/issues/484
i upload the mp3 file and update my gosu gem and now i can't play any sound, this does not works:
class MW < Gosu::Window
super 640, 480
@song = Gosu::Song.new("alert2.mp3")
window = MW.new
Well, in my project i'm using gosu to load image, no drawing, this is just an IA comparing images and i wanted use Gosu to play a sond when my IA found something, i'm using win32-sound gem(converting my mp3 to wav) now. I used a Thread just like a example because i'm using gosu in the main thread without calling a Gosu::Window of course:
if compare_img(img) == :face
@song.play, sorry i forgot it.
tone = Gosu::Sample.new("alert2.mp3").play
# Prevent program from exiting instantly
This will play your tone every 2.5 seconds without needing a window. (Note the replacement of Song with Sample, Song would cut out after a few hundred milliseconds and not reliably play again.)
A playing Song/Sample does not appear to block, resulting in the program exiting before it even starts playing, hence the while loop here.
Thanks! your code works for me and i happy now, when I update gosu, stopped playing sounds, the error that I mentioned before but after I restart everything is fixed.
Great to hear. So
alert2.mp3 works both as a Sample and Song now?
Right! 100% working :)
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill