none
How can i play a wma file, which is an embedded resource? RRS feed

Answers

  • Hi Tempeck81,

     

    Sorry for I had not noted that the SoundPlayer not support wma format audio.

     

    But we know the WindowsMediaPlayer only support a url (file path) for the audio file. And now we embed the wma file into our application, it store by bytes in the application file. And it is also bytes when we retrieve it from the embed resource.

     

    So we just can extract it out and store it to be the wma file, and then use the WindowsMediaPlayer to play this file, because of we can get the full name of this wma file.

    And by my experience, this method is the only way we can do for this job, now.

    using System.IO;
    using WMPLib;
    
    WindowsMediaPlayer player;
    private void button1_Click(object sender, EventArgs e)
    {
     player = new WindowsMediaPlayer();
     byte[] b = Properties.Resources.ice_Totentanz;
     FileInfo fileInfo = new FileInfo("test.wma");
     FileStream fs = fileInfo.OpenWrite();
     fs.Write(b, 0, b.Length);
     fs.Close();
     player.URL = fileInfo.Name;
     player.controls.play();
    }
    
    

     

    Using the Windows Media Player Control with Microsoft Visual Studio

    You can reference this article to add the windows media player library to your project, and then use it.

     

    Have a nice weekend!

    Mike

     

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com

    -------------------------------------------------------------------

    If(helpful) -> Mark

    *****************************************************

    Welcome to the new world! [All-In-One Code Framework]

    • Marked as answer by Tempeck81 Sunday, November 21, 2010 11:47 AM
    Sunday, November 21, 2010 5:58 AM
    Moderator

All replies

  • player = New WMPLib.WindowsMediaPlayer();

    // Define your audio filename

    player.URL = @"c:\YourFileName.wma";  //use your wma file path

    // Pause track
    player.controls.pause();
    // Next track
    player.controls.next();
    // Play track
    player.controls.play();


    you can add wmp lib from below path

    C:\Windows\System32\wmp.dll

    Wednesday, November 17, 2010 5:58 PM
  • But my wma file is a resource embedded in exe. Is it works?
    Thursday, November 18, 2010 8:37 AM
  • Hi Tempeck81,

     

    Welcome to MSDN Forums!

     

    We embed the audio into our application through adding audio files into the resources of the project, so then we also need to use Properties.Resources to access the embedded audio files.

     

    To add audio files to the solution, open the Resources.resx file shown in the solution explorer. Once open, you will see a combo box that is used to allow you to select the type of resource to add to the project, select the Audio file option from the list and then click on "Add Resource".

     

    Once you have selected the "Add Resource" button, a file browser will open and you can use this file browser to search for audio files and add them to the application resources.

     

    Once the audio files have been added to the application resources, select each item added and set the "Persistence" property to "Embedded in .resx".

     

    At this point, the audio files are added and set; they may now be used within the project.

    using System.Media;
    
    SoundPlayer sndplayr = new SoundPlayer(PlayWavFiles.Properties.Resources.BuzzingBee);
    sndplayr.Play();
    

     

    If you want to know about more details about this skill, then you can click this link to read this article and the sample with it.

    Embedding and Playing WAV Audio Files in a WinForms Application

     

    If there’s anything unclear, please feel free to let me know.

     

    Have a nice weekend!

    Mike

     =================================================

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com

    -------------------------------------------------------------------

    If(helpful) -> Mark

    *****************************************************

    Welcome to the new world! [All-In-One Code Framework]

     

    Third party disclaimer

     

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information is found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    Saturday, November 20, 2010 4:14 PM
    Moderator
  • Thank you for your answer. SoundPlayer and embedded wav is ok but how can i play embedded wma? Soundplayer cannot play wma files.

    Saturday, November 20, 2010 10:25 PM
  • Hi Tempeck81,

     

    Sorry for I had not noted that the SoundPlayer not support wma format audio.

     

    But we know the WindowsMediaPlayer only support a url (file path) for the audio file. And now we embed the wma file into our application, it store by bytes in the application file. And it is also bytes when we retrieve it from the embed resource.

     

    So we just can extract it out and store it to be the wma file, and then use the WindowsMediaPlayer to play this file, because of we can get the full name of this wma file.

    And by my experience, this method is the only way we can do for this job, now.

    using System.IO;
    using WMPLib;
    
    WindowsMediaPlayer player;
    private void button1_Click(object sender, EventArgs e)
    {
     player = new WindowsMediaPlayer();
     byte[] b = Properties.Resources.ice_Totentanz;
     FileInfo fileInfo = new FileInfo("test.wma");
     FileStream fs = fileInfo.OpenWrite();
     fs.Write(b, 0, b.Length);
     fs.Close();
     player.URL = fileInfo.Name;
     player.controls.play();
    }
    
    

     

    Using the Windows Media Player Control with Microsoft Visual Studio

    You can reference this article to add the windows media player library to your project, and then use it.

     

    Have a nice weekend!

    Mike

     

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com

    -------------------------------------------------------------------

    If(helpful) -> Mark

    *****************************************************

    Welcome to the new world! [All-In-One Code Framework]

    • Marked as answer by Tempeck81 Sunday, November 21, 2010 11:47 AM
    Sunday, November 21, 2010 5:58 AM
    Moderator
  • Extremely easy! Thanks ;)
    Friday, May 9, 2014 7:53 PM