james james - 1 year ago 129
Vb.net Question

Pause/Play button in vb 2010

I am new to stackoverflow and the programming world. I have a basic program i'm making that will play a song in the background.

I already have that part working, it auto starts a launch of program.

However, I would like to have a button that pauses, then resumes the audio.

(I am trying to avoid making it a media player and using the media player control) Song was add as a resource.

My.Computer.Audio.Stop (works to stop it.)

But how can I implement the pause,resume? by adding a boolean or something?

(I would like pause and resume feature to be within the same button)

Answer Source

I used reflector and the internal implementation of Audio.Play uses the SoundPlayer:

Public Sub Play(ByVal location As String, ByVal playMode As AudioPlayMode)
    Me.ValidateAudioPlayModeEnum(playMode, "playMode")
    Dim sound As New SoundPlayer(Me.ValidateFilename(location))
    Me.Play(sound, playMode)
End Sub

So unless you make your own or derive from the SoundPlayer class your options appear to be quite limited (ref Audio methods dont have pause or resume: http://msdn.microsoft.com/en-us/library/cf1shcah(v=vs.90).aspx).

May I suggest giving up on this class, it doesn't support the pause/resume methods you want. Instead focus your time on How can I pause an MP3 file using C#? - the CodeProject Playing MP3s using MCI or alternatively look into methods like this: http://alvas.net/alvas.audio.aspx

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download