TMediaPlayer 调用资源的问题我搞不懂,1. 可以在 OnNotify 事件中: if Mode = pmStoped then Play
或
用定时器,根据mid的长度设置定时器的间隔;
2. 可以用 别的办法.......................
3. http://homemidi.myetang.com/midiyy/nuxing/zbz/zbz.htm祝你好运
或
用定时器,根据mid的长度设置定时器的间隔;
2. 可以用 别的办法.......................
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
Timer3->Interval = MediaPlayer1->Length ;void __fastcall TForm1::Timer3Timer(TObject *Sender)
{
MediaPlayer1->Open();
MediaPlayer1->Play();
}
这样就行了
{
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;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;