none
mciSendString waveaudio play pause resume - Pause not working. RRS feed

  • Question

  • I have a basic recorder with one label and three buttons, Record, Pause/Resume, and Save. The record and save work but not pause. When I click Pause it continues to record.

    I'm using Visual Studio 2010 Pro in VB.net. The project is a Windows Form App using .NET 4.From what I can find on various forums it should "just work." - but doesn't. No errors reported.

    EDIT: I'm running under Windows 7 SP1 - in a Domain if that matters.

    mciSendString always returns 0


    Is there something I forgot to import?

    Here is what I have so far:

    Imports System.Runtime.InteropServices
    Imports System.Text
    Public Class Form1
        Dim sb As New StringBuilder
        Dim err As Integer
        Dim NotPaused As Boolean = True
        Dim sMyRecordingFile As String = "D:\Company\Audio.wav"
    
        <DllImport("winmm.dll")> _
        Private Shared Function mciSendString(ByVal command As String, ByVal buffer As StringBuilder, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer
        End Function
    
        Private Sub btnRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecord.Click
    
            Try
                err = mciSendString("open new type waveaudio alias MyRecording", Nothing, 0, 0)
                Console.WriteLine("open new type waveaudio alias MyRecording " & err)
                err = mciSendString("record MyRecording", Nothing, 0, 0)
                Console.WriteLine("record MyRecording " & err)
                Me.Label1.Text = "Recording"
            Catch ex As Exception
                Console.WriteLine(ex.Message)
            End Try
    
        End Sub
    
        Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
    
            Try
                err = mciSendString("save MyRecording " & sMyRecordingFile, Nothing, 0, 0)
                Console.WriteLine("save MyRecording " & sMyRecordingFile & err)
                err = mciSendString("close MyRecording", Nothing, 0, 0)
                Console.WriteLine("close MyRecording " & err)
                Me.Label1.Text = "Idle"
            Catch ex As Exception
                Console.WriteLine(ex.Message)
            End Try
    
        End Sub
    
        Private Sub btnPauseResume_Click(sender As Object, e As System.EventArgs) Handles btnPauseResume.Click
    
            If NotPaused Then
                Try
                    err = mciSendString("pause MyRecording", Nothing, 0, 0)
                    Console.WriteLine("pause MyRecording " & err)
                Catch ex As Exception
                    Console.WriteLine(ex.Message)
                End Try
                NotPaused = False
                Me.btnPauseResume.Text = "Resume"
                Me.Label1.Text = "Paused"
    
            Else
                Try
                    err = mciSendString("resume MyRecording", Nothing, 0, 0)
                    Console.WriteLine("resume MyRecording " & err)
                Catch ex As Exception
                    Console.WriteLine(ex.Message)
                End Try
                NotPaused = True
                Me.btnPauseResume.Text = "Pause"
                Me.Label1.Text = "Recording"
    
            End If
    
        End Sub
    
    End Class


    • Edited by Vin82 Tuesday, July 30, 2019 4:06 PM Add OS environment
    Friday, July 26, 2019 4:15 PM

Answers

  • I'm only interested in recording - I want to Pause/Resume recording.

    I'm looking to record audio coming from a radio - no playback involved in the program.

    The way I test it is that I talk in one radio while it is recorded off of another.

    I do a ten count like so:

    "1 2 3 P 4 5 6 R 7 8 9" with P = Pause, R = Resume. What I'm expecting to hear is

    "1 2 3 7 8 9" What I'm getting is "1 2 3 4 5 6 7 8 9".

    Am I able to do this using mciSendString or do I need to use another interface?

    Still looking for assistance.

    Vin,

    Your pause example above was working for Castor and I just used it to record with pause using mediaplayer playing an mp3 on the computer speakers.

    Does the example work for you to record with pause media player as we do?

    "The way I test it is that I talk in one radio while it is recorded off of another. "

    How do you record off another? Use a microphone plugged into the microphone jack of the computer to record the radio speaker? Or how is that done?

    From the docs:

    "CD audio, digital-video, MIDI sequencer, VCR, videodisc, and waveform-audio devices recognize this command."

    https://docs.microsoft.com/en-us/windows/win32/multimedia/pause

    So does that mean your "radio" setup? What is that exactly?

    I don't have a microphone to try it with.




    I use a transformer from the radio to the Line-in on the computer. similar to using a mic.

    The record does work - not the pause.

    Again no play-back is involved with this software.

    EDIT:

    After having been away from it for a months (other projects) I recompiled it and now it's working with Pause/Resume.

    Thank you tommytwotrain for your patience.

    • Edited by Vin82 Friday, September 6, 2019 1:59 PM
    • Marked as answer by Vin82 Friday, September 6, 2019 2:00 PM
    Friday, September 6, 2019 12:09 PM

All replies

  • I cant reproduce the problem. The example works for me.

    Start a song playing on media player, click record, click pause, click resume, click save, stop running. Saves wav with gap where paused.

    :)

    Friday, July 26, 2019 10:49 PM
  • It also works for me (Windows 10, VS 2015)

    Otherwise, you can use other methods like WASAPI

    I tested with WASAPI (IAudioCaptureClient), the wav file is better quality, but it needs more code (P/Invoke for interfaces)...

    Sunday, July 28, 2019 10:44 AM
  • EDIT:
    tommytwotrain:

    What OS? What do you mean by "a gap?" Was the gap blank recording or some of the source material was missing?

    When I try recording something, using Windows Media Player as the source, the recorder gives me an error 328. roughly meaning no input device. My source is the MIC input on the computer .


    • Edited by Vin82 Wednesday, July 31, 2019 1:27 PM
    Tuesday, July 30, 2019 4:08 PM
  • Castorix31:

    I'm going to look into your suggestion of using WASAPI. I'll let you know the outcome.

    • Edited by Vin82 Wednesday, July 31, 2019 1:29 PM
    Wednesday, July 31, 2019 1:28 PM
  • EDIT:
    tommytwotrain:

    What OS? What do you mean by "a gap?" Was the gap blank recording or some of the source material was missing?

    When I try recording something, using Windows Media Player as the source, the recorder gives me an error 328. roughly meaning no input device. My source is the MIC input on the computer .


    Vin,

    I am using win 7 with the above recording code.

    Its been a while here are definitions from memory:

    Playback is play sound (audio) on the system and sound comes out the speakers (or other if you have it and set it).  ie When control panel playback is on Speakers/Headphones you playback from a mp3 on your hard drive or a cd in the cd player and sound comes out the computer speakers. If you have other devices installed in your computer you can select those for playback in the control panel Playback tab. Possibly other options if you have additional hardware to use.

    Record is record what is playing on the speakers (or other playback devices).

    To record playback from the system using media player playing a mp3 from your hard drive you select the Stereo Mix device to record from on the Sound dialog Recording tab. That's what you should be set on to record a song playing on media player and playback on the speakers.

    First you have to set a device for playback, then a device to record:

          Control Panel - Sound - Manage Audio Devices

          Sound Dialog - Playback tab - Set on Speakers/Headphones 

          Sound Dialog - Recording tab - Set on Stereo Mix for media player playback.

                 (you may have other hardware options installed to choose)

    Set control panel recording device on Line In to record an external device like line out from another recorder plugged into the line in plug on your computer sound card. Or a mixer line out or keyboards etc. Or if control panel on Microphone you would record sound picked up from mic. So your control panel playback device must be set on what you are using to make audio come out the speakers plugged into the computer. In your case set record device on Stereo Mix for using Media Player playback from mp3 song.

    So our code above is controlling recording. Not playback.

    If you want to control playback then you have to control the playback device in your case media player. So you need to use code for that. Then you can pause playback with the code. Similar to the control recording code but it controls the playback device. 

    When the pause playback button is pressed then no sound will play on the system and no sound comes out the speakers.

    When the Pause Recording button is pressed then nothing is recorded. Playback continues normally. When Resume Recording is pressed then playback is recorded.

    So if you played the song Row row row your boat and you pressed pause after the second row and pressed resume after your you would hear row row boat in the recorded file. So there is a gap in the music at the words row your. You dont hear them words. You hear row row boat. Not a blank time of no playback row row blank boat. A skip maybe is a better word. You skip row boat.

    But now you say you cant record? I thought recording was working? How do you know pause does not work if you cant record?

    :)

    Do you mean you want to pause playback?

    Why dont you tell us what you want to do first. Then if you are using the correct device tell us what you cant get to work?

    Also tell us your skill level beginner to sounds on computer? and programming? Expert with computer audio but beginner programmer? We don't know all we can do is guess.

    Finally what OS are you using?



    Wednesday, July 31, 2019 2:24 PM
  • tommytwotrain:

    But now you say you cant record? I thought recording was working?

    I can initiate a recording. Record + Save are working for me.

    How do you know pause does not work if you cant record?

    :)

    Do you mean you want to pause playback?

    I'm only interested in recording - That I want to Pause/Resume.

    Why don't you tell us what you want to do first. Then if you are using the correct device tell us what you cant get to work?

    I'm looking to record audio coming from a radio - no playback involved in the program.

    The way I test it is that I talk in one radio while it is recorded off of another.

    I do a ten count like so:

    "1 2 3 P 4 5 6 R 7 8 9" with P = Pause, R = Resume. What I'm expecting to hear is

    "1 2 3 7 8 9" What I'm getting is "1 2 3 4 5 6 7 8 9".

    Thursday, August 1, 2019 7:38 PM
  • I'm only interested in recording - I want to Pause/Resume recording.

    I'm looking to record audio coming from a radio - no playback involved in the program.

    The way I test it is that I talk in one radio while it is recorded off of another.

    I do a ten count like so:

    "1 2 3 P 4 5 6 R 7 8 9" with P = Pause, R = Resume. What I'm expecting to hear is

    "1 2 3 7 8 9" What I'm getting is "1 2 3 4 5 6 7 8 9".

    Am I able to do this using mciSendString or do I need to use another interface?

    Still looking for assistance.

    Thursday, September 5, 2019 7:54 PM
  • I'm only interested in recording - I want to Pause/Resume recording.

    I'm looking to record audio coming from a radio - no playback involved in the program.

    The way I test it is that I talk in one radio while it is recorded off of another.

    I do a ten count like so:

    "1 2 3 P 4 5 6 R 7 8 9" with P = Pause, R = Resume. What I'm expecting to hear is

    "1 2 3 7 8 9" What I'm getting is "1 2 3 4 5 6 7 8 9".

    Am I able to do this using mciSendString or do I need to use another interface?

    Still looking for assistance.

    Vin,

    Your pause example above was working for Castor and I just used it to record with pause using mediaplayer playing an mp3 on the computer speakers.

    Does the example work for you to record with pause media player as we do?

    "The way I test it is that I talk in one radio while it is recorded off of another. "

    How do you record off another? Use a microphone plugged into the microphone jack of the computer to record the radio speaker? Or how is that done?

    From the docs:

    "CD audio, digital-video, MIDI sequencer, VCR, videodisc, and waveform-audio devices recognize this command."

    https://docs.microsoft.com/en-us/windows/win32/multimedia/pause

    So does that mean your "radio" setup? What is that exactly?

    I don't have a microphone to try it with.




    Friday, September 6, 2019 12:22 AM
  • I'm only interested in recording - I want to Pause/Resume recording.

    I'm looking to record audio coming from a radio - no playback involved in the program.

    The way I test it is that I talk in one radio while it is recorded off of another.

    I do a ten count like so:

    "1 2 3 P 4 5 6 R 7 8 9" with P = Pause, R = Resume. What I'm expecting to hear is

    "1 2 3 7 8 9" What I'm getting is "1 2 3 4 5 6 7 8 9".

    Am I able to do this using mciSendString or do I need to use another interface?

    Still looking for assistance.

    Vin,

    Your pause example above was working for Castor and I just used it to record with pause using mediaplayer playing an mp3 on the computer speakers.

    Does the example work for you to record with pause media player as we do?

    "The way I test it is that I talk in one radio while it is recorded off of another. "

    How do you record off another? Use a microphone plugged into the microphone jack of the computer to record the radio speaker? Or how is that done?

    From the docs:

    "CD audio, digital-video, MIDI sequencer, VCR, videodisc, and waveform-audio devices recognize this command."

    https://docs.microsoft.com/en-us/windows/win32/multimedia/pause

    So does that mean your "radio" setup? What is that exactly?

    I don't have a microphone to try it with.




    I use a transformer from the radio to the Line-in on the computer. similar to using a mic.

    The record does work - not the pause.

    Again no play-back is involved with this software.

    EDIT:

    After having been away from it for a months (other projects) I recompiled it and now it's working with Pause/Resume.

    Thank you tommytwotrain for your patience.

    • Edited by Vin82 Friday, September 6, 2019 1:59 PM
    • Marked as answer by Vin82 Friday, September 6, 2019 2:00 PM
    Friday, September 6, 2019 12:09 PM

  • I use a transformer from the radio to the Line-in on the computer. similar to using a mic.

    The record does work - not the pause.

    Again no play-back is involved with this software.

    Vin,

    Did you see this thread. Maybe it should be "type mpegvideo" instead of waveaudio???

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/39b40b77-4d09-4adb-a728-18eb4397a155/play-multiple-audio-files-at-once-visual-basic?forum=vbgeneral

    I wanted you to try to pause recording from the soundcard audio device like castor and I can do and make sure your pause works there just to be sure you know how to run the software and click a button. No offense but I have seen funnier things stop the show. You have to click the pause button and release. Then click it again and release to resume.

    Can you record and pause using a normal microphone?

    I suspect maybe what you have is not a controllable "waveform-audio device". ie you send a pause comand but it does not pause the mic input or line in.

    When you send pause to a cd audio or the soundcard the device pauses playback? Is that how it works.

    Perhaps your line in device does not have the caps to record pause you could check it?

    https://docs.microsoft.com/en-us/windows/win32/multimedia/waveform-audio-input-data-types

    If that is how it works I don't know I am guessing.

    Or perhaps you need a different set of commands to use pause.

    https://docs.microsoft.com/en-us/windows/win32/multimedia/recording-waveform-audio

    Perhaps open is the wrong message

    https://docs.microsoft.com/en-us/windows/win32/multimedia/using-window-messages-to-manage-waveform-audio-recording


    Perhaps it needs an event handler set up?

    "The callback function for waveform-audio input devices is supplied by the application."

    https://docs.microsoft.com/en-us/windows/win32/multimedia/mm-wim-close

    Perhaps one records  the entire thing and then removes the pause from the memory file when resume is begun later?

    Maybe ask on another forum if no one else responds.

    PS this shows how to set up a callback if that should be needed. 

    http://www.vbforums.com/showthread.php?794183-RESOLVED-How-can-I-repeat-or-loop-a-music-file-played-with-MCISendString


    Friday, September 6, 2019 12:57 PM
  • Vince, 

    That you would use this for MP3, I can think about. However, for Wav. 

    The soundplayer is so easy to use. 

    https://docs.microsoft.com/en-us/dotnet/api/system.media.soundplayer?view=netframework-4.8


    Success
    Cor

    Friday, September 6, 2019 1:12 PM