Playing embedded resource mp3 file in C#

NazHim 206 Reputation points
2021-06-06T11:36:56.797+00:00

hi all

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

with best regards
NazHim

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,418 questions
0 comments No comments
{count} votes

Accepted answer
  1. NazHim 206 Reputation points
    2021-06-07T08:14:36.88+00:00

    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 additional answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,606 Reputation points
    2021-06-07T02:57:38.427+00:00

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.