locked
Accessing Phone Files RRS feed

  • Question

  • How to access music files stored in Phone memory and play them in our application ? How to do this in Emulator ? Please specify any links if available. Thanks.
    Tuesday, October 4, 2011 2:17 PM

Answers

  • You can use the Waveform Audio API.

    The PlaySound function can be used to play a specific audio file. For example:

    PlaySound (TEXT("\\SOUNDS\\BELLS.WAV"), NULL, SND_SYNC);
    


    -PaulH

    • Proposed as answer by Jesse Jiang Thursday, October 6, 2011 3:10 AM
    • Marked as answer by Jesse Jiang Wednesday, October 12, 2011 10:36 AM
    Tuesday, October 4, 2011 4:34 PM
  • If you use .NETCF you can PInvoke some dlls in the OS

            [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);
    
            [DllImport("coredll.dll", EntryPoint = "PlaySound", SetLastError = true)]
            private extern static int PlaySound(string szSound, IntPtr hMod, int flags);
    


    If your device is WM6 or heigher, then you can play wma or mp3. Otherwise only uncompressed wave file can be played.

            private IntPtr m_Sound = IntPtr.Zero;
    
            public void PlaySound(string soundPath)
            {
                 if (File.Exists(soundPath))
                {
                  if (Device.IsWM5() 
                   || Device.Platform == Device.Platforms.WindowsCE)
                {
                       PlaySound(soundPath, IntPtr.Zero, 1);
                }
                else if (Device.IsWM6())
                {
                    SndOpen(soundPath, ref this.m_Sound);
                    SndPlayAsync(this.m_Sound, 0);
                }
              }
            }
    


     


    Elvis Hsu
    Senior Software Engineer at Barcode Dynamics Australia
    Find me at Linkedin
    • Proposed as answer by Jesse Jiang Thursday, October 6, 2011 3:10 AM
    • Marked as answer by Jesse Jiang Wednesday, October 12, 2011 10:36 AM
    Tuesday, October 4, 2011 10:47 PM

All replies

  • You can use the Waveform Audio API.

    The PlaySound function can be used to play a specific audio file. For example:

    PlaySound (TEXT("\\SOUNDS\\BELLS.WAV"), NULL, SND_SYNC);
    


    -PaulH

    • Proposed as answer by Jesse Jiang Thursday, October 6, 2011 3:10 AM
    • Marked as answer by Jesse Jiang Wednesday, October 12, 2011 10:36 AM
    Tuesday, October 4, 2011 4:34 PM
  • If you use .NETCF you can PInvoke some dlls in the OS

            [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);
    
            [DllImport("coredll.dll", EntryPoint = "PlaySound", SetLastError = true)]
            private extern static int PlaySound(string szSound, IntPtr hMod, int flags);
    


    If your device is WM6 or heigher, then you can play wma or mp3. Otherwise only uncompressed wave file can be played.

            private IntPtr m_Sound = IntPtr.Zero;
    
            public void PlaySound(string soundPath)
            {
                 if (File.Exists(soundPath))
                {
                  if (Device.IsWM5() 
                   || Device.Platform == Device.Platforms.WindowsCE)
                {
                       PlaySound(soundPath, IntPtr.Zero, 1);
                }
                else if (Device.IsWM6())
                {
                    SndOpen(soundPath, ref this.m_Sound);
                    SndPlayAsync(this.m_Sound, 0);
                }
              }
            }
    


     


    Elvis Hsu
    Senior Software Engineer at Barcode Dynamics Australia
    Find me at Linkedin
    • Proposed as answer by Jesse Jiang Thursday, October 6, 2011 3:10 AM
    • Marked as answer by Jesse Jiang Wednesday, October 12, 2011 10:36 AM
    Tuesday, October 4, 2011 10:47 PM