1. 看看这两个贴子:
http://www.csdn.net/expert/Topic/395/395059.shtm
http://www.csdn.net/expert/Topic/364/364382.shtm2. 用软件 Resource Builder 1.1.0 加入 MIDI 数据, 在汉化新世纪下载3. http://homemidi.myetang.com/midiyy/nuxing/zbz/zbz.htm
http://www.csdn.net/expert/Topic/395/395059.shtm
http://www.csdn.net/expert/Topic/364/364382.shtm2. 用软件 Resource Builder 1.1.0 加入 MIDI 数据, 在汉化新世纪下载3. http://homemidi.myetang.com/midiyy/nuxing/zbz/zbz.htm
解决方案 »
- 这样会内存泄漏吗?
- 遇到奇怪的问题,百思不解
- 马上就要失业了,大家知不知道那个公司要招人呀!!!
- 很奇怪的一个问题,某函数的一个参数为pchar类型的,做成dll调用有问题,而把这个函数放在unit1.pas里面,与dll无关系,使用就没有问题
- 两个关于assign,nil,show的简单问题
- 大家認為我的多線程訪問oralce是用ADO ,還是BDE?
- 各位老大们,我得sql server200 为什么会慢的出奇呢,有什么好办法!!
- 在dbgrid中用图标显示某个逻辑字段时,通过双击改变该字段内容,如何避免True或False被显示出来
- 我的程序是Delphi+Access,在执行SQL语句时出现天大的怪问题
- 有在东莞工作的朋友吗?进来领分。
- 在线等待!!!Printer.TextOut输出时的位置问题!
- 浮动窗口问题,高手请进
procedure Tdhmenuform.MediaPlayer1Notify(Sender: TObject);
begin
if mediaplayer1.Position = mediaplayer1.Length then
begin
mediaplayer1.Rewind ;
mediaplayer1.Play;
end;2,参考一下(这是wav,基本一样):
1)编写.RC文件
..RC文件是资源的源文件,编译器也就编译这个文件,生成.RES的资源文件
首先在我们的项目子目录中建立一个纯文本文件,起名叫Sound.rc,文件中
有一行,内容为:
SOUND1 WAV SOUND.WAV
其中SOUND.WAV为一个Windows下普通的声音文件
2)编译它
在DOS的提示符下打 BRCC SOUND.RC 硬盘哗啦啦转一会儿后,就编译完了
3)制作程序
这也是最复杂,最灵活的一步,首先启动Windows, 再启动Delphi, 并且将项目
中的文件保存到我们的项目中的子目录中。 在Unit1.pas中找这么一行
{$R *.DFM}
把我们的资源文件就声明在后面
{$R SOUND.RES}
然后,在Form1中声明两个全局变量
PtrSound : PChar;
hRes : THandle; {handle to the loaded resource
if 0 indicates nothing playing}
再在Form1的Create事件中写下如下代码
procedure TForm1.FormCreate(Sender: TObject);
var hResInfo : THandle;
begin
hResInfo := FindResource(HInstance, 'SOUND1', 'WAVE');
hRes := LoadResource(HInstance, hResInfo);
if hRes > 32 then {its a good load}
begin {lock the resource}
ptrSound:=LockResource(hRes);
end;
end;
然后在Form1中放一个按钮Button1,写如下代码:
procedure TForm1.Button1Click(Sender: TObject);
begin
sndplaysound(ptrSound,snd_async or snd_Memory);
end; 3,爱莫能助了
{
HMIDISTRM handle;
MIDIHDR midiHdr;
unsigned long err, tempo;
MIDIPROPTIMEDIV prop;
MMTIME time; /* Open default MIDI Out stream device */
err = 0;
if (!(err = midiStreamOpen(&handle, &err, 1, 0, 0, CALLBACK_NULL)))
{
time.wType = TIME_MS; //define the time division type
/* Set the stream device's Time Division to milliseconds*/
prop.cbStruct = sizeof(MIDIPROPTIMEDIV);
prop.dwTimeDiv = 0xE728; //millisecondes : voir midi file spec (key word : E7 28)
midiStreamProperty(handle, (LPBYTE)&prop, MIDIPROP_SET|MIDIPROP_TIMEDIV);/* Store pointer to our stream (ie, buffer) of messages in MIDIHDR */
midiHdr.lpData = (LPBYTE)&Phrase[0];/* Store its size in the MIDIHDR */
midiHdr.dwBufferLength = midiHdr.dwBytesRecorded = sizeof(Phrase);/* Flags must be set to 0 */
midiHdr.dwFlags = 0;/* Prepare the buffer and MIDIHDR */
midiOutPrepareHeader((HMIDIOUT)handle, &midiHdr, sizeof(MIDIHDR));midiStreamOut(handle, &midiHdr, sizeof(MIDIHDR));
midiStreamRestart(handle); // actually play MIDIeventsmidiOutUnprepareHeader((HMIDIOUT)handle, &midiHdr, sizeof(MIDIHDR));
midiStreamClose(handle); 方法 3 需要对 MIDI 格式有一定的了解。
你好,我决定用第一种方法,但有几点问题!
1、如何装入RES资源?(请给出步骤)
2、如何把RES中的MID数据建立一个临时文件,如建到C:盘根目录下
3、请问如何把文件删除?在DELPHI中有关文件删除以及COPY的函数是什么?
谢谢了!:)
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, MPlayer;type
TForm1 = class(TForm)
MediaPlayer1: TMediaPlayer;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
ARStream: TResourceStream;
TempFile: string;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}
{$R MID.RES} // 你建立的资源文件procedure TForm1.FormDestroy(Sender: TObject);
begin
DeleteFile(TempFile); // 删除临时文件
ARStream.Free;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
ARStream := TResourceStream.Create(HInstance, 'MUSIC', 'MIDI'); // 找资源
TempFile := 'C:\TEMP.MID';
ARStream.SaveToFile(TempFile);
MediaPlayer1.FileName := TempFile;
MediaPlayer1.Open;
end;//////////////////////////////////////////////////////////////////////
// 复制文件函数procedure CopyFile(const FileName, DestName: string;
OverwriteReadOnly, ShellDialog: Boolean; ProgressControl: TControl);
var
CopyBuffer: Pointer;
Source, Dest: Integer;
Destination: TFileName;
FSize, BytesCopied, TotalCopied: Longint;
Attr: Integer;
const
ChunkSize: Longint = 8192;
begin
{$IFDEF WIN32}
if NewStyleControls and ShellDialog then begin
CopyMoveFileShell(FileName, DestName, not OverwriteReadOnly,
False, False);
Exit;
end;
{$ENDIF}
Destination := DestName;
if HasAttr(Destination, faDirectory) then
Destination := NormalDir(Destination) + ExtractFileName(FileName);
GetMem(CopyBuffer, ChunkSize);
try
TotalCopied := 0;
FSize := GetFileSize(FileName);
Source := FileOpen(FileName, fmShareDenyWrite);
if Source < 0 then
raise EFOpenError.CreateFmt(ResStr(SFOpenError), [FileName]);
try
if ProgressControl <> nil then begin
SetProgressMax(ProgressControl, FSize);
SetProgressMin(ProgressControl, 0);
SetProgressValue(ProgressControl, 0);
end;
ForceDirectories(ExtractFilePath(Destination));
if OverwriteReadOnly then begin
Attr := FileGetAttr(Destination);
if (Attr >= 0) and ((Attr and faReadOnly) <> 0) then
FileSetAttr(Destination, Attr and not faReadOnly);
end;
Dest := FileCreate(Destination);
if Dest < 0 then
raise EFCreateError.CreateFmt(ResStr(SFCreateError), [Destination]);
try
repeat
BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize);
if BytesCopied = -1 then
raise EReadError.Create(ResStr(SReadError));
TotalCopied := TotalCopied + BytesCopied;
if BytesCopied > 0 then begin
if FileWrite(Dest, CopyBuffer^, BytesCopied) = -1 then
raise EWriteError.Create(ResStr(SWriteError));
end;
if ProgressControl <> nil then
SetProgressValue(ProgressControl, TotalCopied);
until BytesCopied < ChunkSize;
FileSetDate(Dest, FileGetDate(Source));
finally
FileClose(Dest);
end;
finally
FileClose(Source);
end;
finally
FreeMem(CopyBuffer, ChunkSize);
if ProgressControl <> nil then
SetProgressValue(ProgressControl, 0);
end;
end;