Link to home
Start Free TrialLog in
Avatar of G Scott
G ScottFlag for United States of America

asked on

Windows Mobile 6.1 Play Sound

Howdy. I have seen a few solutions for playing a sound file on a mobile device that is running WM6+.  One of the common denominators is this line:

Import System.Media

What do I have to do to get that option? I type that and it doesn't allow me to do that. I am very green in .NET (well versed in VBA).

I am using an Intermec CK3, if that matters. I just want to play a sound so that the user knows everything is ok or not ok. (ding/buzz, respectively)

Can someone help me out with this?  I only know/use VB..C Sharp/++ scares me.

Thanks for any help you can give me.
Avatar of asfahani
asfahani

The .NET Compact Framework version 3.5 supports the SoundPlayer class, which provides an intuitive API for playing sounds in applications such as casual games. To enable casual game development, the .NET Compact Framework pushes each SoundPlayer object through WaveOut, which is the audio rendering filter in Windows Embedded CE and Windows Mobile powered devices. This filter enables the device to mix sounds.

The .NET Compact Framework 3.5 supports the following types:

SoundPlayer

SystemSound

SystemSounds

For a code example that demonstrates how to use this feature, see SoundPlayer.

The differences between the .NET Compact Framework implementation and the desktop implementation of SoundPlayer include the following:

The .NET Compact Framework supports only PCM-encoded files (uncompressed sound).

On a device, more than one sound can play at the same time. On the desktop, only the last sound plays.

On a device, the application will not terminate until playback is completed. If a sound is playing in the application loop, the application will never exit. To avoid this situation, you can explicitly terminate playback by calling the Stop or Dispose method on the SoundPlayer object.

Reference From:


An alternative way to play Beeps is to use the "coredll.dll" and a file you place at your device.

Dim ExePath As String

Private Declare Function PlaySound Lib "coredll.dll" Alias "PlaySound" _
(ByVal lpszName As String, _
ByVal hMod As IntPtr, _
ByVal hwFlags As Integer) As Integer
Private Sub Beep_Test()
PlaySound(ExePath + "test.wav", IntPtr.Zero, &H1 Or &H20000)
End Sub
btw, the system.media interface is not presented in the .Net Compact Framework
Avatar of Nasir Razzaq
>What do I have to do to get that option? I type that and it doesn't allow me to do that.

Have you added a reference to system.media?

@asfahani
Are you negating your first comment? SoundPlayer, SystemSound, and SystemSounds classes are within System.Media namespace.
no i mean .Net Compact Framework 2.0
If you are using .Net CF 3.5 then you have no problem.
What visual studio are you using?
Avatar of G Scott

ASKER

I am using VS2008 with CF3.5. When I try to add a reference the .NET list is very short:

User generated image
I don't see anything with the word Media, or similar to that at all.

asfahani - I tried your code but I am still just getting a beep instead of the wav file that I want to have played.
ASKER CERTIFIED SOLUTION
Avatar of asfahani
asfahani

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of G Scott

ASKER

I installed a few SDKs from Intermec, but was never able to find that DLL. However, the other solution you gave worked great!! Thank you so much; I truly appreciate it.
glad to help you, welcome anytime!