Using WMA codec to play media files directly without using WMP

来源:互联网 发布:大型视频管理平台软件 编辑:程序博客网 时间:2024/04/29 21:46
  •  

    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

     

     

Answers

  •  

    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

  • summarized from http://social.msdn.microsoft.com/forums/en-US/vssmartdevicesnative/thread/7361445b-ab58-4a36-ab94-29d01d698af8/

  •  

原创粉丝点击