New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Play wav audio until position #175
Comments
You can use a timer that checks if you've reached a certain point which is ok in some circumstances but not accurate. A better approach would be to use |
Edit i found an example here : http://markheath.net/post/naudio-play-extract However i have a problem, when i use that example, then later i try to read another chunk of the audio file by doing this : trimmed.SkipOver = TimeSpan.FromSeconds(25); It doesn't do anything, no sound played. TL;DR plays only one chunk of the file then when i try to read other chunk, doesn't work |
Any help please, i'm stuck |
For this use, I'd make a |
Do you mean i copy WaveFileReader file and rename it ? I've checked the Read method of the WaveFileReader but i don't quite see how i'd tell it to stop at position i want. Could you provide an example ? |
No, you create a custom class that inherits from |
I'm sorry but i'm not sure how do i play the sound then after creating a WaveOffsetStream instance with the startTime and length i want. Atm i'm using this code to play a sound :
then
where does the WaveOffsetStream object go in this code ? Edit : I found a way like this :
but now my question is if i want to read another part of the audio, do i have to init the waveOutEvent with a new WaveOffsetStream ? If so how do i do that because i get an error when i try to Init the waveOutEvent again after the first time. |
use it instead of offsetSampleProvider
On Thu, 4 May 2017 at 13:24 Herz3h ***@***.***> wrote:
I'm sorry but i'm not sure how do i play the sound then after creating a
WaveOffsetStream instance with the startTime and length i want. Atm i'm
using this code to play a sound :
WaveOutEvent waveOutEvent = new WaveOutEvent();
AudioFileReader wavFileReader = new AudioFileReader(audioPath);
OffsetSampleProvider trimmed = new OffsetSampleProvider(wavFileReader);
waveOutEvent.Init(trimmed);
then
waveOutEvent.Play()
where does the WaveOffsetStream object go in this code ?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#175 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAJA1PTDkOun_NURSxNzzMRcNGKero0mks5r2cNqgaJpZM4MjKs->
.
--
Mark Heath
http://markheath.net
|
Ok i managed to read part of the audio. But i have this issue where i have to delete old waveOutEvent and create a new one to play another part of the audio. I feel like i'm doing it wrong here. Am i supposed to delete WaveOutEvent object and create new one each time i want to play an audio part? |
yes, if you're going to play audio at a completely different sample rate / bit depth, but you don't have to otherwise. you can use a |
Ok i just keep WaveOffsetStream as it does what i need. Thanks for the help !! Just have one issue. I run a thread that fetches the audio position and sends it to callback but the currentTime/Position doesn't update as fast as i want. For instance i have this : Position CurrentTime It skips position 00:00:11.57 to 00:00:11:70, any way i can set how fast is the position updated? Or is this due to the lock here : https://github.com/naudio/NAudio/blob/master/NAudio/Wave/WaveStreams/WaveOffsetStream.cs#L145 |
it's based on the latency and size of buffers the audio card is using. You'd need to plug into the |
Do you mean i'd have to make my own WaveOutEvent which inherits IWavePosition and implement GetPosition in a different way ? Because atm, trying to do waveOutEvent.GetPosition() also has big gaps like my previous post (doesn't update as often) |
|
Hello,
I followed tutorial on this page and managed to successfully play a wav file. However i'd like to play the audio until a position in time is reached (say for ex until 3rd sec then pause or stop), how do i go about this ?
The only idea i have is to use a thread which checks position of the audio and pause it when it reaches the position i want but not sure if thats how it should be done.
Thanks in advance
The text was updated successfully, but these errors were encountered: