CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2006
    Location
    Timisoara, Romania
    Posts
    123

    Playing an MP3 from a buffer

    Is it possible to play an MP3 from a buffer using MCI commands?

    I know it can be played from a file on disk by specifing a file name in the lpstrElementName member of MCI_OPEN_PARMS but I need to play it directly from a buffer. Our application loads all its resources from a DLL and we don't want to create temporary files on disk at runtime.

    Thank you.

  2. #2
    Join Date
    Oct 2005
    Posts
    230

    Re: Playing an MP3 from a buffer

    I was intrested in this some time ago also, and i did find somthing. Tho from memory it wasnt worth the effort for me and i forgot about it. I have no idea where i found it now but Ill keep looking

  3. #3
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Playing an MP3 from a buffer

    Maybe the following article can help you (I'm not sure if it works with MP3 files):
    How To Use MCI to Play AVI/WAVE Files from Memory
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  4. #4
    Join Date
    Oct 2006
    Location
    Timisoara, Romania
    Posts
    123

    Unhappy Re: Playing an MP3 from a buffer

    Thank you for the link, I tried but I still can't make it work.

    From what I understood only waveaudio and avivideo can be played from memory. I wrote a callback method to open/read/seek on a buffer and installed it. I read a file into that buffer and here is the funny thing: when I read a .wav file and play it like this:

    Code:
    mmioInstallIOProc(mmioFOURCC('M', 'E', 'Y', ' '), (LPMMIOPROC)IOProc, MMIO_INSTALLPROC | MMIO_GLOBALPROC);
    mciSendString("open test.MEY+ type waveaudio alias test", 0, 0, 0);
    mciSendString("play test", NULL, 0, 0);
    it works fine, when I load an .mp3 file and play it with

    Code:
    mmioInstallIOProc(mmioFOURCC('M', 'E', 'Y', ' '), (LPMMIOPROC)IOProc, MMIO_INSTALLPROC | MMIO_GLOBALPROC);
    mciSendString("open test.MEY+ type mpegvideo alias test", 0, 0, 0);
    mciSendString("play test", NULL, 0, 0);
    it doesn't work and I get a "Cannot find the specified file" error. Does anyone know any workaround for this? Or maybe another approach?

  5. #5
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Playing an MP3 from a buffer

    I've never done it myself so I don't know why it is not working.
    Do you have to use MCI?
    Maybe you can use another audio library, for example fmod? Note, I have used fmod before but not for streaming from memory, so I'm not 100% sure if it works, but I think it should work. It's worth a try.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  6. #6
    Join Date
    Oct 2006
    Location
    Timisoara, Romania
    Posts
    123

    Re: Playing an MP3 from a buffer

    I see fmod has a dll which must be shipped with the application, meaning I can't use it (it's not up to me).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured