none
Using WMA codec to play media files directly without using WMP RRS feed

  • Question

  • hi,

    i wish to know if anyone has any experience in integrating a wma decoder with smartphone to be able to play music files directly without using WMP(windows media player)

    I dont want to use WMP since  i want to play protected content on my smartphone

    regards

    shailu155

    Thursday, March 1, 2007 11:46 AM

Answers

  • Hi,

     

    Depending upon the version of the operating system used by the devices you want to support you may be able to make use of the DirectShow APIs. These APIs are documented here http://msdn2.microsoft.com/en-us/library/ms879877.aspx

     

    Using an example found here http://msdn2.microsoft.com/en-us/library/ms783787.aspx I came up with the following function:

     

    #include <dshow.h>

    void PlayFile(HWND hwndOwner, LPCTSTR lpszFileName)

    {

         IGraphBuilder *pGraph = NULL;

         IMediaControl *pControl = NULL;

         IMediaEvent *pEvent = NULL;

     

         // Initialize the COM library.

         HRESULT hr = CoInitialize(NULL);

         if (FAILED(hr))

         {

              printf("ERROR - Could not initialize COM library");

              return;

         }

     

         // Create the filter graph manager and query for interfaces.

         hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,

         IID_IGraphBuilder, (void **)&pGraph);

         if (FAILED(hr))

         {

              printf("ERROR - Could not create the Filter Graph Manager.");

              return;

         }

     

         hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);

         hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

         hr = pGraph->RenderFile(lpszFileName, NULL);

         if (SUCCEEDED(hr))

         {

              // Run the graph.

              hr = pControl->Run();

              if (SUCCEEDED(hr))

              {

                   // Wait for completion.

                   long evCode;

                   pEvent->WaitForCompletion(INFINITE, &evCode);

                   // Note: Do not use INFINITE in a real application, because it

                   // can block indefinitely.

              }

         }

     

         pControl->Release();

         pEvent->Release();

         pGraph->Release();

         CoUninitialize();

    }

    Also add "strmiids.lib" to the additional libraries list within the linker properties of your project.

     

    This also has the ability to play video files as well. It's use is fairly simple, as demonstrated below and it should be able to play essentially any file that the built in WMP app will (including protected WMA files according to http://www.microsoft.com/windows/windowsmedia/player/windowsmobile/faq.aspx#5_4 - I have no experience with this since I have no protected WMA files to test with)

     

    PlayFile(hWnd, _T(\\windows\\menupop.wav));

    The menupop.wav file is a file included in almost every shipping Windows Mobile device and is the default sound you hear when the menu pops up. The DirectShow APIs are quite powerful and can be used to not only play back audio/visual files but also capture them if suitable hardware is found on your device. The documentation is well worth a read.

     

    Hope this helps,

    Christopher Fairbairn

    Monday, May 7, 2007 11:48 AM

All replies

  • Hi,

     

    Depending upon the version of the operating system used by the devices you want to support you may be able to make use of the DirectShow APIs. These APIs are documented here http://msdn2.microsoft.com/en-us/library/ms879877.aspx

     

    Using an example found here http://msdn2.microsoft.com/en-us/library/ms783787.aspx I came up with the following function:

     

    #include <dshow.h>

    void PlayFile(HWND hwndOwner, LPCTSTR lpszFileName)

    {

         IGraphBuilder *pGraph = NULL;

         IMediaControl *pControl = NULL;

         IMediaEvent *pEvent = NULL;

     

         // Initialize the COM library.

         HRESULT hr = CoInitialize(NULL);

         if (FAILED(hr))

         {

              printf("ERROR - Could not initialize COM library");

              return;

         }

     

         // Create the filter graph manager and query for interfaces.

         hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,

         IID_IGraphBuilder, (void **)&pGraph);

         if (FAILED(hr))

         {

              printf("ERROR - Could not create the Filter Graph Manager.");

              return;

         }

     

         hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);

         hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

         hr = pGraph->RenderFile(lpszFileName, NULL);

         if (SUCCEEDED(hr))

         {

              // Run the graph.

              hr = pControl->Run();

              if (SUCCEEDED(hr))

              {

                   // Wait for completion.

                   long evCode;

                   pEvent->WaitForCompletion(INFINITE, &evCode);

                   // Note: Do not use INFINITE in a real application, because it

                   // can block indefinitely.

              }

         }

     

         pControl->Release();

         pEvent->Release();

         pGraph->Release();

         CoUninitialize();

    }

    Also add "strmiids.lib" to the additional libraries list within the linker properties of your project.

     

    This also has the ability to play video files as well. It's use is fairly simple, as demonstrated below and it should be able to play essentially any file that the built in WMP app will (including protected WMA files according to http://www.microsoft.com/windows/windowsmedia/player/windowsmobile/faq.aspx#5_4 - I have no experience with this since I have no protected WMA files to test with)

     

    PlayFile(hWnd, _T(\\windows\\menupop.wav));

    The menupop.wav file is a file included in almost every shipping Windows Mobile device and is the default sound you hear when the menu pops up. The DirectShow APIs are quite powerful and can be used to not only play back audio/visual files but also capture them if suitable hardware is found on your device. The documentation is well worth a read.

     

    Hope this helps,

    Christopher Fairbairn

    Monday, May 7, 2007 11:48 AM
  • Hi,

     

    I have a Smartphone WM5.0 device. It plays the .WMA files in the native Windows Media Player.

    But when I try to play the .WMA file using DShow in the same device, RenderFile() returns with the error VFW_E_CANNOT_RENDER.

    Can anybody tell me what could be the reason?

     

    Regards,

    Karthik.

    Wednesday, May 30, 2007 10:49 AM
  • Hi all,

    I have a similar problem: IGraphBuilder::RenderFile() returns VFW_E_CANNOT_RENDER when I try to play an .mp3 file on WM6 emulator or device. On the other hand this .mp3 file plays on WMP successfully. Moreover, IGraphBuilder::RenderFile() succeeds when I try to play an .amr or just .wav file.

    Does it means that WMP don't use the Direct Show?
    And, PLEASE help!

    Tuesday, December 4, 2007 3:47 AM
  • Hi
    Is there any way we can play a smaller file format (smaller in terms of size) on WM 6.
    I believe we need to write our own codec.
    It would be helpful if I can get some help in eiher of the two (the codec or trick to play a smaller size file format)

    Thanks and regards,
    Varun Prakash Shrivastava
    Monday, May 26, 2008 1:41 PM