question

NazHim-9882 avatar image
0 Votes"
NazHim-9882 asked NazHim-9882 commented

Playing embedded resource mp3 file in C#

hi all

how to Playing embedded resource mp3 file
using C#
i want to play mp3 file from embedded resource

with best regards
NazHim

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NazHim-9882 avatar image
0 Votes"
NazHim-9882 answered TimonYang-MSFT commented

hello
TimonYang-MSFT
thanks

102945-screenshot-2021-06-07-133607.png

102991-screenshot-2021-06-07-134221.png

uninstall NAudio?

with best Regards
NazHim



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

No, I mean uninstall VisioForge.Shared.NAudio.
According to the error message, the reason for the error should be that there is a class called WaveOut in both packages. They both have an Init method but require different parameters.
When we do not use the full path of the class, it uses the VisioForge.Shared.NAudio by default, but what we need is the one in NAudio.
It should be useful to use the full path: NAudio.Wave.WaveOut waveOut = new NAudio.Wave.WaveOut();
But it is better to uninstall the redundant nuget package, in case the same problem occurs unintentionally in the future and causes additional trouble.

0 Votes 0 ·
TimonYang-MSFT avatar image
0 Votes"
TimonYang-MSFT answered NazHim-9882 commented

What problem are you encountering now? Are you not sure how to read this file or are you encountering an exception?

I added MP3 to Resources, and then used the following code to play it, hoping to give you some ideas.

     private void button1_Click(object sender, EventArgs e)
     {
         byte[] fileByte = Properties.Resources.au1_mp3;
         Stream stream = new MemoryStream(fileByte);
         var reader = new NAudio.Wave.Mp3FileReader(stream);
         var waveOut = new WaveOut(); 
         waveOut.Init(reader);
         waveOut.Play();
     }

If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

hello
TimonYang-MSFT

thanks for your fast response

getting error pic at below

 using System.IO;
 using VisioForge.Shared.NAudio.Wave;

102877-screenshot-2021-06-07-122049.png



how i can do it?
with best regards
NazHim

0 Votes 0 ·

I think it might be because we installed different nuget packages, this is the one I installed:

102917-2.png

0 Votes 0 ·
2.png (11.3 KiB)

hello
TimonYang-MSFT

NAudio installed but

getting another error pic at below

102878-screenshot-2021-06-07-124027.png



with regards
NazHim

0 Votes 0 ·

Try change var reader = new NAudio.Wave.Mp3FileReader(stream); to NAudio.Wave.Mp3FileReader reader = new NAudio.Wave.Mp3FileReader(stream);
Has the previous nuget package been uninstalled? If not, please uninstall it.
If it still doesn’t work, hover your mouse over the place where the error occurred so that we can see the error message.
You can use the Snipping Tool that comes with Windows to delay screenshots.

0 Votes 0 ·

hello
TimonYang-MSFT

thanks.
it's working good

with best Regards
NazHim

0 Votes 0 ·