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

  • SEARCH
  • Home
  • 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 3228476
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:41:49+00:00 2026-05-17T16:41:49+00:00

According to my last post in here one of friends suggested this code: using

  • 0

According to my last post in here one of friends suggested this code:

using System;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;

namespace TeaTimer
{
    /// <summary>
    /// MCIPlayer is based off code by Slain.
    /// Found here: http://www.sadeveloper.net/Articles_View.aspx?articleID=212
    /// </summary>
    public class MCIPlayer
    {
        private static readonly string sAlias="TeaTimerAudio";

        [DllImport("winmm.dll")]
        private static extern long mciSendString(string strCommand,StringBuilder strReturn,int iReturnLength, IntPtr hwndCallback);
        [DllImport("Winmm.dll")]
        private static extern long PlaySound(byte[] data, IntPtr hMod, UInt32 dwFlags);

        public static void Play(string sFile)
        {
            _Open(sFile);
            _Play();
        }
        public static void Stop() 
        {
            _Close();
        }

        private static void _Open(string sFileName)
        {
            if(_Status()!="")
                _Close();

            string sCommand = "open \"" + sFileName + "\" alias "+sAlias;
            mciSendString(sCommand, null, 0, IntPtr.Zero);
        }

        private static void _Close()
        {
            string sCommand = "close "+sAlias;
            mciSendString(sCommand, null, 0, IntPtr.Zero);
        }

        private static void _Play()
        {
            string sCommand = "play "+sAlias;
            mciSendString(sCommand, null, 0, IntPtr.Zero);
        }

        private static string _Status()
        {
            StringBuilder sBuffer = new StringBuilder(128);
            mciSendString("status "+sAlias+" mode", sBuffer, sBuffer.Capacity, IntPtr.Zero);
            return sBuffer.ToString();
        }
    }
}

It works fine, but now the problem is, I can not repeat my MIDI file.
I saw some code but I don’t know why it doesn’t work.
I tried:

Scommand = "play "+sAlias+" repeat "; 
mciSendString(Scommand, null, 0, IntPtr.Zero);
  • 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-17T16:41:50+00:00Added an answer on May 17, 2026 at 4:41 pm

    Why do you think “repeat” is a supported command?
    According to MSDN I cannot see that it is supported.

    The solution that I see is to use notify flag.

    Here is sample working for me:

    public class MCIPlayer
    {
        private class Form2: Form
        {
            public Form2()
            {
                if (!IsHandleCreated) CreateHandle();
            }
    
            private const int MM_MCINOTIFY = 953;
    
            protected override void WndProc(ref Message m)
            {
                base.WndProc(ref m);
                if (m.Msg == MM_MCINOTIFY)
                    MCIPlayer.Play(file);
            }
    
            public string file;
        }
    
        private static Form2 f = new Form2();
    
        private static readonly string sAlias = "TeaTimerAudio";
    
        [DllImport("winmm.dll", SetLastError = true)]
        private static extern int mciSendString(string strCommand, 
                        StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);
        [DllImport("Winmm.dll")]
        private static extern long PlaySound(byte[] data, IntPtr hMod, UInt32 dwFlags);
    
        public static void Play(string sFile)
        {
            _Open(sFile);
            _Play();
        }
    
        public static void PlayTwice(string sFile)
        {
            _Open(sFile);
            f.file = sFile;
            _PlayTwice();
        }
    
        public static void Stop()
        {
            _Close();
        }
    
        private static void _Open(string sFileName)
        {
            if (_Status() != "")
                _Close();
    
            string sCommand = "open \"" + sFileName + "\" alias " + sAlias;
            mciSendString(sCommand, null, 0, IntPtr.Zero);
        }
    
        private static void _Close()
        {
            string sCommand = "close " + sAlias;
            mciSendString(sCommand, null, 0, IntPtr.Zero);
        }
    
        private static void _Play()
        {
            string sCommand = "play " + sAlias;
            mciSendString(sCommand, null, 0, IntPtr.Zero);
        }
    
        private static void _PlayTwice()
        {
            string sCommand = "play " + sAlias + " notify";
            mciSendString(sCommand, null, 0, f.Handle);
        }
    
        private static string _Status()
        {
            StringBuilder sBuffer = new StringBuilder(128);
            mciSendString("status " + sAlias + " mode", sBuffer, 
                                  sBuffer.Capacity, IntPtr.Zero);
            return sBuffer.ToString();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, here is the code: <form action=FirstServlet method=Post> Last Name: <input type=text name=lastName size=20>
I am using this to sort according to last name: usort($fb_friends['data'], "custom_sort"); function custom_sort($a,
I am using the Maven-Shade-Plugin to create a runnable Uber-jar. According to the last
According to this SO post: How to check the TEMPLATE_DEBUG flag in a django
According to this post , IDEA uses Osmorc to run OSGi frameworks. It, in
According to this post in Recursive Descent vs. LALR , any LALR(k) can be
Hi according to my last question here I try to write a sql editor
Possible Duplicate: Can we post on Google plus from android application? According to this
According MSDN, FxCop is an application that analyzes managed code assemblies (code that targets
According this article , generic JPA DAO(Data Access Object) is a pretty nice pattern.

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.