locked
How can I play an .mp3 audio file?

    Question

  • I want to play some audio in my app.  I see that I can use XAudio2 to play .wav files, but it does not appear to handle .mp3 files.  There is the MediaElement class which can play .mp3 files, but it is tied to a visual element which must be placed on my page in order for the play to work.  What I want is a way to play an .mp3 file without tying it to any specific page.  Is this possible?

    Thanks.

    Wednesday, July 18, 2012 10:54 PM

All replies

  • Hello,

    You can use XAudio2 to play the mp3 file, but you will use the MediaEngine. Please check this thread.
    http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/9eaaa495-feed-4bb1-ae7e-4be086af1d14/

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, July 19, 2012 9:16 AM
  • Thanks for the link, however,  I have already looked at that post and the links it contains, and I have now taken a closer look.  The XAudio2 sample does not appear to support .mp3 playback.  The MediaEngine may, but the sample in the link is for displaying video (not playing audio).  I have tried to create a IMFMediaEngine instance for playing audio, but I cannot figure out what attributes I need to set to successfully create one.  No mater what I try, I always get a MF_E_ATTRIBUTENOTFOUND error.  Can you point me to an example that shows how to play an .mp3 file using the MediaEngine?

    Thanks.


    Friday, July 20, 2012 3:26 AM
  • You need to implement IMFMediaEngineNotify  interface and set MF_MEDIA_ENGINE_CALLBACK mandatory attribute

    MFCreateAttributes(&spAttributes, 1)

    spAttributes->SetUnknown(MF_MEDIA_ENGINE_CALLBACK, (

    IUnknown*) this)

    Thursday, January 10, 2013 8:32 AM