Hi. I am new to DaniWeb so I hope I am doing this right. I am an amateur VB programmer. I wrote a VB6 program that featured a fruit machine with changing letters in the windows. To add sound I used the code line (e.g.) MediaPlayer5.Play. My recollection is that I set up all the parameters for the MediaPlayer object in the properties window for the appropriate Media Player object at design time. This would have included the relevant sound file. It all worked beautifully, and I also used the same technique for playing a video clip. At the time I had Media Player 9 on my PC. Now I have returned to working on the program and VB 6 appears not to recognise the method. I now have Media Player 10 on my PC, but I have also tried my existing program after rolling back to Media Player 9, and it still does not work. All the code is the original code that worked fine. What has changed ? It was such a simple method to use. Thanks if you can help. Mikecc2691.

Hi. Many thanks for that suggestion. I haven't used APIs yet - this will be a useful way of getting to know about them. I would still like to know what has changed since I wrote my original code. There is no doubt that it worked, over a long period of development now it doesn't - so something must have changed. VB tells me it does not recognise the method. And the strange thing is that no publication seems to mention the method MediaPlayer1. Play. I suspect it is Media Player itself that has changed, as I can no longer see a suitable place in the properties box to enter the file I wish to play. Anyway, your suggestion has the advantage of forcing me to learn about APIs which will clearly be useful beyond the immediate program. Regards. Mike.

Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Const SND_ASYNC = &H1
Const SND_LOOP = &H8
Const SND_MEMORY = &H4
Const SND_NODEFAULT = &H2
Const SND_NOSTOP = &H10
Const SND_SYNC = &H0

Private Sub cmdPlay_Click()
Dim Result As Long
Dim SoundFile As String

'  set file name
SoundFile = "C:\DÖNALd.wav"

'  Play wave file 
Result = sndPlaySound(SoundFile, SND_ASYNC)

End Sub

Hi. Many thanks for this code. I am still learning VB, so pointing me in the right direction like this is a real help. Mikecc2691.

you're welcome. don't forget to mark this thread solved. :)
happy coding friend :)

Comments
helpfull people
This article has been dead for over six months. Start a new discussion instead.