rodio icon indicating copy to clipboard operation
rodio copied to clipboard

how to pass a reference to sink append

Open alexzanderr opened this issue 3 years ago • 5 comments

i have this code image

i saw that i cannot append more than once the same sink because source it doesnt have copy trait.

but how do i pass a reference to source or use multiple times ?

because i want to play the same sound multiple times. this way the program will be more efficient, instead of loading the file from disk everytime i want to the the audio file.

load once, play multiple times.

how can i achieve this ?

thanks in advance.

alexzanderr avatar Mar 28 '22 21:03 alexzanderr

I have the same question. How can I reuse file data if all methods take it by value and move it?

VladasZ avatar Apr 10 '22 21:04 VladasZ

~i guess clone is a temporary solution~

nope. Decoder doesnt implement Clone trait, see the source in docs

so i guess the solution would be to create a new instance of Decoder every new audio file (or for the same file?)

alexzanderr avatar Jul 19 '22 16:07 alexzanderr

Create a new source based on rodio::static_buffer::StaticSamplesBuffer which, instead of accepting a &'static [S], accepts an Arc<Vec<S>> which allows you to load a file from disk once, decode it into a Vec<S> by taking advantage that all sources (including Decoders) are iterators, then wrap that Vec in an Arc which allows it to be read efficiently but not written from as many different sources at a time as you want.

Keithcat1 avatar Aug 25 '22 19:08 Keithcat1

So I proposed a workaround with buffered sources and clones. But the downside is that the types become painfully long as per the example : Buffered<TakeDuration<SkipDuration<Buffered<Decoder<BufReader<File>>>>>>

And also, the data is copied and not referenced. Unfortunately.

Ownezx avatar Oct 28 '22 15:10 Ownezx

I believe the solution in #141 applies to this. It worked well in my case.

RottenFishbone avatar Feb 04 '23 03:02 RottenFishbone