JustAdotNETUser 11-02-2004, 10:38 PM I'm using Direct X to play sound files (mp3) and everything is fine. I'm using for example:
Imports Microsoft.DirectX
Imports Microsoft.DirectX.AudioVideoPlayback
Private SoundPlayer As Audio
Everythings ok except I don't know what event, if any, is fired when the song finishes. I play using: SoundPlayer = New Audio(FileName, True) and I could set up a loop straight after till the sound finishes but that's not really what I want to do.
I prefer, like in mediaplayer, to have a certain event fired when the sound/sound file is finished.
Thanks
Iceplug 11-03-2004, 06:58 AM Microsoft.DirectX.AudioVideoPlayback.Audio object raise a Stopping event when they reach the end of the file. :)
So, you may be able to do:
Private WithEvents Boombox As Audio
:)
JustAdotNETUser 11-03-2004, 10:04 AM Microsoft.DirectX.AudioVideoPlayback.Audio object raise a Stopping event when they reach the end of the file. :)
So, you may be able to do:
Private WithEvents Boombox As Audio
:)
Hmm, don't quite get what you mean, can't seem to fathom it out......
Iceplug 11-03-2004, 07:20 PM If you declare your Audio class WithEvents, then you should be able to select the Audio class you are using from the left combobox at the top of the code window, and then select the Stopping event from the right menu. :)
JustAdotNETUser 11-03-2004, 08:12 PM If you declare your Audio class WithEvents, then you should be able to select the Audio class you are using from the left combobox at the top of the code window, and then select the Stopping event from the right menu. :)
I don't know what to say mate, that's cool and thank you very much. I had: Private SoundPlayer As Audio and using your suggestion changed it to Private WithEvents SoundPlayer As Audio and that instantly opened up 5 events that I was after, excellent. I've been programming for quite a while but usually just 'code' stuff, forms and modules, actually using class forms in their own right e.t.c. can be quite cool, cheers.
JustAdotNETUser 11-03-2004, 09:21 PM I'm trying all different things here and just getting in a muddle.
I'm getting the correct events e.t.c in my class form but need it in my real form (Form1) so can I have the events fired straight back to my Form1? Not sure, tried refiring an event from class to form1 with raiseevent but can't seem to get anything to work.
Iceplug 11-04-2004, 06:57 AM The form does not raise these events. If you declare the Audio class in your 'real form', then you'll receive the events from the audio class and that's what you select from the comboboxes in the top of your code window. If your class will receive the events and that's what you declare on the form, then your class will raise the event and that's what you should be searching for in the code window. Don't forget to declare the class WithEvents. :)
JustAdotNETUser 11-04-2004, 12:51 PM Imports Microsoft.DirectX
Imports Microsoft.DirectX.AudioVideoPlayback
Public Class DXSoundPlayer
Public WithEvents SoundPlayer As Audio
Public Sub PlaySound(ByVal FileName As String)
SoundPlayer = New Audio(FileName, True)
End Sub
Public Sub StopSound()
If Not SoundPlayer Is Nothing Then SoundPlayer.Stop()
End Sub
Private Sub SoundPlayer_Ending(ByVal sender As Object, ByVal e As System.EventArgs) Handles SoundPlayer.Ending
'This Fires When Song Ends..... (cool)
End Sub
End Class
All works fine. All I want to do now is this. The 'SoundPlayer_Ending' routine is in my class, when the sound ends I need to be in my Form1 as I need it to do stuff there, I can't seem to access this event it from Form1, how can I have it (SoundPlayer_Ending) in Form1, or get to re-fire another event in Form1?
From 'Form1' I use 'Private DX As New DXSoundPlayer' then DX.'whatever', was trying the same with the above event but getting nowhere, bloody thing is driving me mad...... ;-)
Iceplug 11-04-2004, 08:00 PM You'll have to raise an event yourself for that.
Public Event SoundEnd As EventHandler
Then, when your class receives the Ending event from the Audio class, you raise the event.
RaiseEvent SoundEnd(Me, New EventArgs)
Your class will have to be declared WithEvents for you to find the SoundEnd event with your class in the top right combobox. :)
JustAdotNETUser 11-05-2004, 05:46 AM You'll have to raise an event yourself for that.
Public Event SoundEnd As EventHandler
Then, when your class receives the Ending event from the Audio class, you raise the event.
RaiseEvent SoundEnd(Me, New EventArgs)
Your class will have to be declared WithEvents for you to find the SoundEnd event with your class in the top right combobox. :)
OK the first lines seem ok, it's your last line that throws me..... How do I declare my class 'WithEvents'? If I add a 'WithEvents' to: Public Class DXSoundPlayer and make it: Public Class WithEvents DXSoundPlayer it shows a syntax error, also tried Public WithEvents Class DXSoundPlayer. Don't seem to get anything from my main form, grrrrr, bloody classes.
Iceplug 11-05-2004, 07:01 AM Public Class DXSoundPlayer
is not the class declaration. It is the class itself.
A class declaration is where you are using:
Private Something As DXSoundPlayer
This is what you declare WithEvents:
Private WithEvents Something As DXSoundPlayer
This declaration should already be in the form. :)
JustAdotNETUser 11-05-2004, 07:10 AM Thanks for replying still, bet ya getting sick of me......
Yes, I have Private DX As New DXSoundPlayer already in Form1 but as soon as I add the withevents statement it give me a syntax error, same if I remove the 'new'.
Iceplug 11-05-2004, 07:19 AM A Syntax error? How did you type the line?
This works for me. :)
JustAdotNETUser 11-05-2004, 07:33 AM My class is posted above. My Form1 is like this:
Public Class Form1
Inherits System.Windows.Forms.Form
Private DX As New DXSoundPlayer
'Windows Form Designer generated code'
Private Sub Play()
DX.PlaySound("C:\test.mp3")
End Sub
End Class
It's on this form I need to raise an event.
As you can see I have the Private DX As New DXSoundPlayer, it wont let me add a 'WithEvents' to it......
Iceplug 11-05-2004, 07:53 AM What error do you get when you type the line?
JustAdotNETUser 11-05-2004, 08:07 AM When I change the:
Private DX As New DXSoundPlayer
to
Private WithEvents DX As New DXSoundPlayer
it places a blue squiggle under DX, trying to run it tells me 'WithEvents does not raise any events'
Iceplug 11-05-2004, 08:09 AM Did you declare the Public Event in the DXSoundPlayer class?
JustAdotNETUser 11-05-2004, 08:30 AM Hooooooooooooooooooorayyyyyyyyyyyyyyyyyyy!!!!!!!!!!!!
lol
Well I done something like that earlier, didn't seem to do it, obviously I did something wrong.
It now works, cool, and cheers for sticking with me mate.
|