naudio / NAudio

Audio and MIDI library for .NET
MIT License
5.38k stars 1.09k forks source link

The audioFileReader object is not responding, causing it to be unable to play #1072

Open Super-Badmen-Viper opened 9 months ago

Super-Badmen-Viper commented 9 months ago

When playing FLAC lossless and higher-quality audio formats, setting the playback progress of a song using audioFileReader.CurrentTime = newTime; has a very high chance of causing the audioFileReader object to become unresponsive.

When there is an issue with "audioFileReader.CurrentTime = newTime;" in the code, the Debug debugger does not allow debugging of any code after "audioFileReader.CurrentTime = newTime;." Instead, it simply skips all subsequent code within the function containing this line and exits, without providing any error messages.

Please note that at this point, you cannot use Dispose() to release memory for the audioFileReader; the only way to release memory is by setting it to null. If "audioFileReader.CurrentTime = newTime;" is executed on the UI thread, the UI interface will freeze, rendering it unresponsive to user interactions.

Super-Badmen-Viper commented 9 months ago

When playing FLAC lossless and higher-quality audio formats, setting the playback progress of a song using audioFileReader.CurrentTime = newTime; has a very high chance of causing the audioFileReader object to become unresponsive.

When there is an issue with "audioFileReader.CurrentTime = newTime;" in the code, the Debug debugger does not allow debugging of any code after "audioFileReader.CurrentTime = newTime;." Instead, it simply skips all subsequent code within the function containing this line and exits, without providing any error messages.

Please note that at this point, you cannot use Dispose() to release memory for the audioFileReader; the only way to release memory is by setting it to null. If "audioFileReader.CurrentTime = newTime;" is executed on the UI thread, the UI interface will freeze, rendering it unresponsive to user interactions.

My application scenario is a. NET WPF desktop application, and the Naudio version is the latest version. The testing scenario is my open source music project MoZhiMusic

markheath commented 9 months ago

Hmm, that is very strange. Under the hood it is using Media Foundation. But this has generally been very reliable over the years, so not sure what exactly might be causing the problem. Have you tried repositioning with Position instead and see if that exhibits the same issue?

Super-Badmen-Viper commented 9 months ago

Hmm, that is very strange. Under the hood it is using Media Foundation. But this has generally been very reliable over the years, so not sure what exactly might be causing the problem. Have you tried repositioning with Position instead and see if that exhibits the same issue?

I have made changes to the code based on your suggestions and used the 'Position' attribute to track the progress of audio playback. However, this issue remains the same as before, especially when playing audio in FLAC format, setting the audio playback position may cause the 'audioFileReader' object to not respond. This is the code I updated:

image image

In this annotated code snippet, I integrated the FFPEG extension of CsCore Use NAudio to play FLAC format audio. And add my FFPmpegAudioReaderClass to initialize FLAC format audio and use my MediaElement_ Song class for playback and other operations. The FFmpeg extension of CsCore is working properly and can seamlessly integrate with NAudio's "audioFileReader" and equalizer. NAudio is an important component of mine because it has many functions that I rely on. Combining the FFmpeg extension of CsCore with NAudio can help solve common FLAC playback and equalizer settings issues I encounter when implementing with NAudio. Thank you for your reply

yueyinqiu commented 4 months ago

perhaps my discussion #1130 is related to this issue?

Super-Badmen-Viper commented 4 months ago

perhaps my discussion #1130 is related to this issue?

After my personal verification, NAudio can indeed be used with ffmpeng to support all formats that ffmpeng can support (such as flac). You can refer to my code, but I'm not sure if Naudio plans to support ffmpeng