Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6844959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:26:29+00:00 2026-05-27T00:26:29+00:00

I’m trying to play a MIDI file in my VB.NET (VB 2010 Express) and

  • 0

I’m trying to play a MIDI file in my VB.NET (VB 2010 Express) and things work well with the code from this other question here on Stack Overflow, which I translated from C to VB.

However, I also need to PAUSE, while that code is only for open and stop. I edited the code like this:

Imports System.Runtime.InteropServices
Imports System.IO
''' <summary>
''' MCIPlayer is based off code by Slain.
''' Found here: http://www.sadeveloper.net/Articles_View.aspx?articleID=212
''' </summary>
Public Class MCIPlayer
    Private Shared ReadOnly sAlias As String = "TeaTimerAudio"

    <DllImport("winmm.dll")> _
    Private Shared Function mciSendString(ByVal strCommand As String, ByVal strReturn As StringBuilder, ByVal iReturnLength As Integer, ByVal hwndCallback As IntPtr) As Long
    End Function

    Public Shared Sub Open(ByVal sFileName As String)
        If _Status() <> "" Then
            _Close()
        End If
        Dim sCommand As String = "open """ & sFileName & """ alias " & sAlias
        mciSendString(sCommand, Nothing, 0, IntPtr.Zero)
    End Sub

    Public Shared Sub Close()
        Dim sCommand As String = "close " & sAlias
        mciSendString(sCommand, Nothing, 0, IntPtr.Zero)
    End Sub

    Public Shared Sub Pause()
        Dim sCommand As String = "pause " & sAlias
        mciSendString(sCommand, Nothing, 0, IntPtr.Zero)
    End Sub

    Public Shared Sub Play()
        Dim sCommand As String = "play " & sAlias
        mciSendString(sCommand, Nothing, 0, IntPtr.Zero)
    End Sub

    Public Shared Function Status() As String
        Dim sBuffer As New StringBuilder(128)
        mciSendString("status " & sAlias & " mode", sBuffer, sBuffer.Capacity, IntPtr.Zero)
        Return sBuffer.ToString()
    End Function
End Class

And I call it like this:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    MCIPlayer.Open("C:\Users\User\Desktop\aqua-roses_are_red.mid")
End Sub

Private Sub PlayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayButton.Click
    MCIPlayer.Play()
End Sub

Private Sub PauseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PauseButton.Click
    MCIPlayer.Pause()
End Sub

Private Sub StopButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopButton.Click
    MCIPlayer.Close()
End Sub

The problem is that, for some reason, if I click play, then pause, then play again, the file actually resumes playing from where it was left, but the instruments are completely different. The melody switches back to the default piano, while before pressing pause it was a complete different sound.

Can you help me on this?

I’m on Win7x64

Thanks a lot! Best

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:26:30+00:00Added an answer on May 27, 2026 at 12:26 am

    OK, I figured out how to do it. Here is the code, loosely inspired to the freebasic.net link I mentioned in the comment above, but a lot simpler:

    Public Shared Sub ResumeAfterPause()
        MsgBox(CLng(_Status()))   'Just to make sure the status is the position, see below
        Dim sCommand As String = "play " & sAlias & " from " & CLng(_Status())
        mciSendString(sCommand, Nothing, 0, IntPtr.Zero)
    End Sub
    

    And the status procedure is modified like this:

    Public Shared Function _Status() As String
        Dim sBuffer As New StringBuilder(128)
        mciSendString("status " & sAlias & " position", sBuffer, sBuffer.Capacity, IntPtr.Zero)
        Return sBuffer.ToString()
    End Function
    

    I guess that, when a song is played from the beginning, the player reads instrument info. When it starts from a different position, you need to let the device driver know that he’s starting from a different position, so that he can retrieve the previous instrument settings.

    Anyway, all’s well what ends well (although it’s not the end yet… When my app is done, I need to test it on other platforms too and see if it works the same).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.