locked
Play mp3 on Window Mobile 6 in C# .Net RRS feed

  • Question

  •  

    Hi All,

     

    Iam new to Window Mobile 6 Programming.

    Iam showing list of mp3 songs in window mobile 6.0. I want that on clicking any of the song, the song starts playing.

    Iam using C# .Net Compact Framework 2.0 (Device Application) and Pocket PC 2003 Edition as Emulator for the same.

    Now I want to know that is there is any plugin or API for playing those mp3 songs in Window Mobile

    Any help for the same will be appreciated.

    Regards
    Navneet Kharbanda

    Friday, April 4, 2008 6:04 AM

Answers

  •  AlexFeinman wrote:
    The URL property is supported. The problem is that many WM devices (including emulator) do not include support for media streaming (other than for Windows Media format). Some ODMs include 3rd party streaming directshow filters. Others include 3rd party streaming software (e.g. Arcsoft Streaming Media Player). The latter won't enable WMP to strea media

     

    Quoted from http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3070906&SiteID=1 

     

    Inferred from the above comment, we know that trying to pay mp3 stream audio without the corresponding filter is vain. I have never used the FMOD before but maybe you'd like to give it a try.

    Thursday, April 10, 2008 2:50 AM
  •  

    You should use the new sound APIs found in windows mobile. The PInvokes look like:

     

    [DllImport("aygshell.dll")]
    static extern uint SndOpen(string pszSoundFile, ref IntPtr phSound);

    [DllImport("aygshell.dll")]
    static extern uint SndPlayAsync(IntPtr hSound, uint dwFlags);

    [DllImport("aygshell.dll")]
    static extern uint SndClose(IntPtr hSound);

    [DllImport("aygshell.dll")]
    static extern uint SndStop(int SoundScope, IntPtr hSound);

    [DllImport("aygshell.dll")]
    static extern uint SndPlaySync(string pszSoundFile, uint dwFlags);

     

    I have a SoundPlayer class that handles the playback of sound files. You can get the code here.

    • Marked as answer by warrentang Tuesday, September 15, 2009 3:14 AM
    Tuesday, July 29, 2008 11:33 PM

All replies

  • Here is an easy way to play mp3 with the wmp.dll.

     

    First add the C:\windows\system32\wmp.dll as a reference of your project. (It's amazing that it works both on desktop and on smart devices.)

     

    Then use the code similar to the following to play the mp3 file:

    Code Block
        WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();
        player.URL = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "
    \\song.mp3";
        player.settings.volume = 100;
        player.controls.play();

     

     

    Best Regards

    Chunsheng Tang

     

    Monday, April 7, 2008 2:26 AM
  •  

    Hi Chunsheng,

     

    Thanks a lot for the reply. I have written following function for  the same

    private void PlayFile(String url)

    {

    player = new WMPLib.WindowsMediaPlayer();

    player.URL=url;

    player.settings.volume = 100;

    player.controls.play();

    }

     

    Problem is that, when I give the url of the mp3 file residing on mobile, it works fine. But when it is from web it will not respond anything.

     

    The same Web URL when I give manually in window media player available in smartDevice, it will get played.

     

    Please suggest me what to do.

     

    Regards

    Navneet

    Monday, April 7, 2008 8:15 AM
  • Yes that approach really has problems playing online files.

     

    Here is an article which shows you how to host the Windows Media Player control in your application:

     Hosting ActiveX Controls in the .NET Compact Framework 2.0

    Unfortunately it's not a trivial work and you need to spend some on it to understand and use it.

     

    In a former discussion Christopher Fairbairn also introduces how to use DirectShow to play mp3:

     http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1566710&SiteID=1&mode=1

    It is written in C++ so there is still some work to do. And DirectShow is really too specific for this forum.

     

    Monday, April 7, 2008 8:49 AM
  • Before you go further, you may also consider letting the shell play the file for you:

     

        string path = "path to the mp3";

        ProcessStartInfo info = new ProcessStartInfo() { FileName = path, UseShellExecute = true};
        Process.Start(info);

    Monday, April 7, 2008 9:11 AM
  •  

    Hi Chunsheng !

     

    thanks for your reply. Shell works for me but the problem in that, it first ask to download the file in mobile memory and then it starts playing it. Its a length and memory consuming process.

     

    I want it to run directly from the url by buffering the stream in to it.

     

    Any suggestion in that direction will be helpful

     

    Regards

    Navneet

    Monday, April 7, 2008 10:58 AM
  • Then how about this?

     

        string path = "path to the audio";
        Process.Start("wmplayer", path);

     

    Also you may have a look at FMOD:
    http://www.codeproject.com/KB/mobile/simple_mp3_player_for_ppc.aspx

    Tuesday, April 8, 2008 3:16 AM
  •  AlexFeinman wrote:
    The URL property is supported. The problem is that many WM devices (including emulator) do not include support for media streaming (other than for Windows Media format). Some ODMs include 3rd party streaming directshow filters. Others include 3rd party streaming software (e.g. Arcsoft Streaming Media Player). The latter won't enable WMP to strea media

     

    Quoted from http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3070906&SiteID=1 

     

    Inferred from the above comment, we know that trying to pay mp3 stream audio without the corresponding filter is vain. I have never used the FMOD before but maybe you'd like to give it a try.

    Thursday, April 10, 2008 2:50 AM
  •  

    You should use the new sound APIs found in windows mobile. The PInvokes look like:

     

    [DllImport("aygshell.dll")]
    static extern uint SndOpen(string pszSoundFile, ref IntPtr phSound);

    [DllImport("aygshell.dll")]
    static extern uint SndPlayAsync(IntPtr hSound, uint dwFlags);

    [DllImport("aygshell.dll")]
    static extern uint SndClose(IntPtr hSound);

    [DllImport("aygshell.dll")]
    static extern uint SndStop(int SoundScope, IntPtr hSound);

    [DllImport("aygshell.dll")]
    static extern uint SndPlaySync(string pszSoundFile, uint dwFlags);

     

    I have a SoundPlayer class that handles the playback of sound files. You can get the code here.

    • Marked as answer by warrentang Tuesday, September 15, 2009 3:14 AM
    Tuesday, July 29, 2008 11:33 PM
  • Chunsheng, this is a great solution and works well within my project.

    Many thanks.

    -- Adriano

    Tuesday, May 12, 2009 8:05 PM
  • Here is an easy way to play mp3 with the wmp.dll.

     

    First add the C:\windows\system32\wmp.dll as a reference of your project. (It's amazing that it works both on desktop and on smart devices.)

     

    Then use the code similar to the following to play the mp3 file:

     

    Code Block
        WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();
        player.URL = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "
    \\song.mp3";
        player.settings.volume = 100;
        player.controls.play();

     

      

    Best Regards

    Chunsheng Tang

      

    My Question :

    Thanks for sharing your nice trick to play audio files like mp3 using it.

    I have a problem with it.

    When i build Project and send it to my phone(it'z W.P 6.5) and after installing it while i run , it says the Following error:

    An unexpected error has occurred in My Player Demo.exe. TypeLoadException

    File or assembly name 'Interop.WMPLib, Version=1.0.0, Culture=neutral,

    PublicKeyToken=null', or one of its dependencies, was not found

    End Question.

    Please Help me ....


    Thursday, July 14, 2011 5:31 PM