this post was submitted on 03 Sep 2023
19 points (100.0% liked)

Rust Programming

8134 readers
1 users here now

founded 5 years ago
MODERATORS
 

Hello, I really need help figuring out Rodio audio playback for a rust project. I need to play a short audio clip of a casino wheel turning a certain amount of times in a loop. When I run the main function, the program plays the audio clip once and then stops completely. If anybody who has used Rodio can give me help it would be greatly appreciated. Also, I have tried using a longer duration in the play_sound function but it doesn't change anything. Thank you

you are viewing a single comment's thread
view the rest of the comments
[–] boring_bohr@feddit.de 5 points 1 year ago* (last edited 1 year ago)

You say you've tried longer durations, but you're only sleeping for microseconds here... I'd assume you're simply playing the sound 30 times in 30 microseconds and as such only hear the last iteration. If you want the whole file to play every time, you could replace play_raw with play_once and use the returned Sink to simply sleep_until_end() instead of your own delay.

Edit: I just saw that you wrote that the clip played once and then quit, that doesn't make a lot of sense (with that sleep duration, it should quit pretty much immediately). It's been a while since I played around with Rodio and things seem to have changed a little. From quickly looking into it, I'd probably only call your play_sound function once and edit it to create a Sink in there (see the example in the documentation). You can then append an infinitely repeating source to that sink and sleep for you total desired duration.