VB.NET 2005 - how to play a wav in an app for a windows mobile 5 application

misdevelopment
misdevelopment used Ask the Experts™
on
VB.NET 2005 - how to play a wav in an app for a windows mobile 5 application

Really struggling with this - I'm guessing the playsound wrapper isn't available..... anyone any ideas on the most efficient way of playing a wav on an ipaq?

Thanks,

Jc
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
By playsound wrapper I'm assuming your refering to my.Computer.Audio.Play("c:\my.wav")??

Author

Commented:
Yes, we don't seem to have this available to us, even though we've looked to reference and import anything that looked like it might do the job.... I guessed that with it being for a mobile device that the classes weren't valid...
i've made a class that plays wav files asynchronously from your resources. you just need to insert the wav file in the sound resources, select Embedded in ResX for both the resource, and the file in the Solution Explorer too, in the resources folder.

Imports System
Imports System.Media
Imports System.Resources
Imports System.Reflection
Imports System.IO

Public Class Sound
    Public Shared Sub PlayWavResource(ByVal wav As String)

        ' get the namespace
        Dim strNameSpace As String = Assembly.GetExecutingAssembly().GetName().Name.ToString()
        Dim tempSpace As String = "CSCM"

        ' get the resource into a stream
        Dim resourceStream As Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(tempSpace + "." + wav)
        If resourceStream Is Nothing Then Exit Sub

        With New SoundPlayer(resourceStream)
            .Play()
        End With
    End Sub

End Class
just replace
Dim tempSpace As String = "CSCM"

with
Dim tempSpace As String = [your root namespace]

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial