Re: Media player problems...
If you're just playing a short WAV sound then you're better off using the PlaySound API function. If you want to use WMP without an interface, i.e. without adding the control to your form, then I'd suggest not using the ActiveX control but rather an instance of the WMPLib.WindowsMediaPlayer class, which is intended to be used that way. More than that I can't really say as I don't have much experience in that regard.
Re: Media player problems...
Quote:
Originally Posted by Ruku
Anyone mind telling me what's wrong in this code?
VB Code:
REM Play a sound
Public Function PlaySound(ByVal Filename As String, Optional ByVal optPlayCount As Integer = 1, Optional ByVal optVolume As Integer = 100) As Boolean
Dim x As New AxWMPLib.AxWindowsMediaPlayer
Try
x.URL = Filename
x.settings.playCount = optPlayCount
x.settings.volume = optVolume
x.Ctlcontrols.play()
Catch ex As Exception
'An error occured
Return False
Exit Function
End Try
'Sound played successfully
Return True
End Function
Hi Ruku,
I think you forgot to declare some functions.
That is how I play a sound with Playsound, try it:
VB Code:
Const SND_ASYNC As Integer = &H1
Const SND_FILENAME As Integer = &H20000
Const SND_NODEFAULT As Integer = &H2
Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Integer, ByVal dwFlags As Integer) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PlaySound("c:\1.mp3"), 0, SND_NODEFAULT Or SND_ASYNC Or SND_FILENAME)
End Sub
Hope it helps,
sparrow1
Re: Media player problems...
Quote:
Originally Posted by sparrow1
I think you forgot to declare some functions.
Not...
I just wanted to use integrated .net functions instead, but I guess I'll resolve to API...
bah well, thx guys...
Re: Media player problems...
The WMP control is COM anyway so it's not really .NET anway. Note that .NET 2.0 has a SoundPlayer component. Also, you may like to follow the Mentalis.org link in my signature. They have two classes that wrap certan API functions to make playing WAV and other sound files easier. When you get right down to it, that's all the .NET SoundPlayer will do anyway.
Re: Media player problems...
Meh, I guess I'll just resolve to API anyhow... :p