Solved

About playing midi in background

Posted on 1998-12-10
4
279 Views
Last Modified: 2010-04-04
How to play midi in background?
I mean like BGSOUND/EMBED in HTML, or like in SpeedDisk/
Norton Disk Doctor? And I want to loop that playing
until user out of program.
I don't want to use TMediaPlayer since it has its own
display. I don't want any display on my form.

Like usual, needs some guidance...

:-)

Stinger
0
Comment
Question by:stinger_60284
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 1350453
hi,
you could always use tmedia and set visible property to false;
0
 
LVL 2

Accepted Solution

by:
Thaddy earned 20 total points
ID: 1350454
To play it, load a wave file in memory and call:

SndPlaySound(PointertoWave, SND_ASYNC or SND_MEMORY or SND_LOOP);


to stop it call the same routine, but with the pointer set to nil:

SndPlaySound(nil,0);


0
 
LVL 2

Expert Comment

by:Thaddy
ID: 1350455
Sorry, I misread the question this code is for waves,
here's code for midifiles, put it in a thread and you're away:
(btw:I didn't write this, but I forgot who did)
unit midi;

interface

uses
  Windows, mmsystem, Classes, SysUtils;

type
  TUMidi = class(TComponent)
  private
    { Private declarations }
    DeviceId:integer;
    fname:string;
  protected
    { Protected declarations }
  public
    { Public declarations }
    function Open:integer;
    function Play(fff,ttt:integer):integer;
    function Close:integer;
    function ErrStr(i:integer):String;
  published
    { Published declarations }
    property MidiFile: string read fname write fname;
  end;

procedure Register;

implementation

function TUMidi.Open:integer;
var
open_s:TMCI_OPEN_PARMS;
set_s:TMCI_SEQ_SET_PARMS;
a:array[0..512] of char;
begin
with open_s do
   begin
   lpstrDeviceType:=LPCSTR(MCI_DEVTYPE_SEQUENCER);
   lpstrElementName:=StrPCopy(a,fname);
   end;
with set_s do
   begin
   dwTimeFormat:=MCI_FORMAT_MILLISECONDS;
   end;
result:=mciSendCommand(0,MCI_OPEN,
                       MCI_OPEN_TYPE or MCI_OPEN_TYPE_ID or MCI_OPEN_ELEMENT,
                       DWORD(@open_s));
DeviceId:=open_s.wDeviceId;
if result<>0 then exit;
result:=mciSendCommand(DeviceId,MCI_SET,
                       MCI_SET_TIME_FORMAT,
                       DWORD(@set_s));

if result<>0 then self.close;
end;

function TUMidi.Play(fff,ttt:integer):integer;
var
play_s:TMCI_PLAY_PARMS;
begin
with play_s do
   begin
   dwFrom:=fff;
   dwTo:=ttt;
   end;
result:=mciSendCommand( DeviceID,MCI_PLAY,MCI_FROM or MCI_TO,
                        DWORD(@play_s));
end;

function TUMidi.Close:integer;
var
close_s:TMCI_GENERIC_PARMS;
begin
result:=mciSendCommand(DeviceId,MCI_CLOSE,
                       0,
                       DWORD(@close_s));
end;

function TUMidi.ErrStr(i:integer):string;
var s:array [0..256] of char;
begin
if mciGetErrorString(i,s,256)=false then
   result:='Undefined error code'
else
   result:=strpas(s);
end;


procedure Register;
begin
  RegisterComponents('Mid', [TMidi]);
end;

end.

0
 

Author Comment

by:stinger_60284
ID: 1350456
Thanks Thaddy!!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question