R
rhythmofrain
Unregistered / Unconfirmed
GUEST, unregistred user!
以前做了个程序,试了以midi格式的音乐为背景,程序pass了,可以循环播放,可是当把背景音乐改为mp3格式后,居然就不行了,放一轮后就停止了,怎么会这样?谁知道的,帮帮我!
(另外,这个程序里的背景音乐是打了包的,我也试过没打包的,可是一样不行,tmd)
代码如下:
unit mp3_form;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,MPlayer;
type
TForm1 = class(TForm)
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
MediaPlayer:TMediaPlayer;
procedure OnNotify(Sender:TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{$R mp3.res}//将mp3文件转换为.res文件
{$R midi.res}
//将mp3.res中的数据源转换为文件的一个过程,将在后面引用到
procedure SourceToFile(Const ResName,ResType,FileName:String);
var
Res:TResourceStream;
begin
Res:=TResourceStream.Create(Hinstance,ResName,PChar(ResType));
Res.SaveToFile(FileName);
Res.Free;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
MediaPlayer.Close;
DeleteFile(MediaPlayer.FileName);//退出程序时删除已释放的文件
end;
//在窗体显示前
procedure TForm1.FormShow(Sender: TObject);
begin
MediaPlayer:=TMediaPlayer.Create(self);
//创建一个Tmediaplayer的实体
MediaPlayer.Visible:=false;
MediaPlayer.Parent:=self;//继承父体
MediaPlayer.OnNotify:=OnNotify;
MediaPlayer.DeviceType:=dtAutoSelect;
MediaPlayer.AutoOpen:=true;
MediaPlayer.Close;
//SourceToFile(''resource'',''file1'',''pretty_boy.mp3'');//引用Sourcetofile过程获取源文件
SourceToFile(''source'',''file1'',''beatit.mid'');
//MediaPlayer.FileName:=''pretty_boy.mp3'';
MediaPlayer.FileName:=''beatit.mid'';
MediaPlayer.Open;
MediaPlayer.Play;
end;
//如果背景乐停则通知继续播放
procedure TForm1.OnNotify(Sender:TObject);
begin
if MediaPlayer.Mode = mpstopped then
begin
MediaPlayer.Rewind;
MediaPlayer.Play;
end;
MediaPlayer.Notify:=true;
end;
end.
(另外,这个程序里的背景音乐是打了包的,我也试过没打包的,可是一样不行,tmd)
代码如下:
unit mp3_form;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,MPlayer;
type
TForm1 = class(TForm)
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
MediaPlayer:TMediaPlayer;
procedure OnNotify(Sender:TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{$R mp3.res}//将mp3文件转换为.res文件
{$R midi.res}
//将mp3.res中的数据源转换为文件的一个过程,将在后面引用到
procedure SourceToFile(Const ResName,ResType,FileName:String);
var
Res:TResourceStream;
begin
Res:=TResourceStream.Create(Hinstance,ResName,PChar(ResType));
Res.SaveToFile(FileName);
Res.Free;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
MediaPlayer.Close;
DeleteFile(MediaPlayer.FileName);//退出程序时删除已释放的文件
end;
//在窗体显示前
procedure TForm1.FormShow(Sender: TObject);
begin
MediaPlayer:=TMediaPlayer.Create(self);
//创建一个Tmediaplayer的实体
MediaPlayer.Visible:=false;
MediaPlayer.Parent:=self;//继承父体
MediaPlayer.OnNotify:=OnNotify;
MediaPlayer.DeviceType:=dtAutoSelect;
MediaPlayer.AutoOpen:=true;
MediaPlayer.Close;
//SourceToFile(''resource'',''file1'',''pretty_boy.mp3'');//引用Sourcetofile过程获取源文件
SourceToFile(''source'',''file1'',''beatit.mid'');
//MediaPlayer.FileName:=''pretty_boy.mp3'';
MediaPlayer.FileName:=''beatit.mid'';
MediaPlayer.Open;
MediaPlayer.Play;
end;
//如果背景乐停则通知继续播放
procedure TForm1.OnNotify(Sender:TObject);
begin
if MediaPlayer.Mode = mpstopped then
begin
MediaPlayer.Rewind;
MediaPlayer.Play;
end;
MediaPlayer.Notify:=true;
end;
end.