SRL Archive - Other Scripts

SCAR .wav Player


Naum

2009-02-07 10:37:06

A little SCAR .wav player I put together, origonally based on SmartzKid's SoundBoard but I added alot of extra features into this. It only plays one song atm, which is a real problem.
Enjoy.
{Used Play Current song from SmartzKid's SoundBoard V2}
program WAVPlay0r;


var
// MusicForm variables.
EndMusicForm : Boolean;
frmDesign : TForm;

Label1, Label20 : TLabel;
GroupBox1 : TGroupBox;

ListBox1 : TListBox;
Button1, Button2, Button3, Button4,

Button5, Button6, Button7 : TButton;
Edit1 : TEdit;

Sounds : Array Of String;
M : Integer;

Timer : TTimer;
SoundDur, SoundStart : Integer;

SongProg : TProgressBar;

Function Browse : Array Of String; //Thx Da 0wner
var
OpenDialog1 : TOpenDialog;
begin
OpenDialog1 := TOpenDialog.Create(Nil);
OpenDialog1.InitialDir:='C:\WINDOWS\Media';
OpenDialog1.Title := 'SCAR Wav Player - Select Music!';
OpenDialog1.Filter := 'Wav Music Files (.wav)| *.wav';
if OpenDialog1.Execute then
SetLength(Result, OpenDialog1.Files.Count);
For M := 0 to OpenDialog1.Files.Count - 1 Do
Result[M] := OpenDialog1.Files.Strings[M];
OpenDialog1.Free;
end;

procedure PlayCurrentSound;
begin
if(ListBox1.Itemindex > -1)then
begin
SoundDur := GetSoundDuration(Sounds[ListBox1.Itemindex]);
SoundStart := GetSystemTime;
PlaySound(Sounds[ListBox1.Itemindex]);
Timer.Enabled := True;
end;
end;

Procedure OkiClick(Sender : TObject);
Begin
Case Sender Of
Button1 : ListBox1.Items.Clear;
Button2 : ListBox1.Items.Delete(ListBox1.ItemIndex) ;
Button3 : PlaySound('.wav');
Button4, ListBox1 : PlayCurrentSound;
Button5 : Begin
Sounds := Browse;
For M := 0 to High(Sounds) Do
ListBox1.Items.Add(ExtractFileName(Sounds[M]));
end;
Button6 : Begin
FrmDesign.Close;
PlaySound('.wav');
end;
Button7 : OpenWebPage('http://www.villavu.com/forum/showthread.php?t=41676?t=44631');
End;
End;

Procedure UpdateProgressbar;
begin
try
SongProg.Position := Ceil((GetSystemTime - SoundStart) / SoundDur * 100);
except
end;
if((GetSystemTime - SoundStart) > Round(SoundDur))then
begin
Timer.Enabled := false;
SongProg.Position := 0;
end;
end;

Procedure Update;
Begin
Label20.Caption := ('Song Status(s) | ' +FloatToStr(Ceil(((GetSystemTime - SoundStart) / 60) / 10))+' / '+FloatToStr(Ceil((SoundDur/60) / 10)));
end;

Procedure UpdateProgressBar1(Sender4 : TObject);
var V : TVariantArray;
begin
V := [];
SetArrayLength(V, 0);
ThreadSafeCall('Update', v);
ThreadSafeCall('UpdateProgressBar', v);
end;

// This form was parsed using: DFM Form Parser v.25 by Ron.
procedure MusicForm;
var
TimeMusicForm : Integer;
begin
TimeMusicForm := GetSystemTime;
frmDesign := CreateForm;
with frmDesign do
begin
Position := poScreenCenter;
BorderStyle := bsNew;
BorderIcons := [biMinimize];
ClientWidth := 376;
ClientHeight := 192;
Caption := ' SCAR Music Player (.wav file only)';
Color := clBtnFace;
Font.Color := clWindowText;
Font.Height := -11;
Font.Name := 'MS Sans Serif';
Font.Style := [];
PixelsPerInch := 96;
end;
Label1 := TLabel.Create(frmDesign);
with Label1 do
begin
Parent := frmDesign;
Left := 192;
Top := 16;
Width := 169;
Height := 13;
Caption := 'Music Play List (.wav Files ONLY!!)';
end;
GroupBox1 := TGroupBox.Create(frmDesign);
with GroupBox1 do
begin
Parent := frmDesign;
Left := 6;
Top := 8;
Width := 363;
Height := 177;
Caption := 'SCAR Music Player';
TabOrder := 17;
end;
ListBox1 := TListBox.Create(frmDesign);
with ListBox1 do
begin
Parent := frmDesign;
Left := 192;
Top := 32;
Width := 169;
Height := 121;
ItemHeight := 13;
TabOrder := 8;
OnDblClick := @OkiClick;
end;
Button1 := TButton.Create(frmDesign);
with Button1 do
begin
Parent := frmDesign;
Left := 120;
Top := 32;
Width := 65;
Height := 25;
Caption := 'Remove All';
TabOrder := 9;
OnClick := @OkiClick;
end;
Button2 := TButton.Create(frmDesign);
with Button2 do
begin
Parent := frmDesign;
Left := 115;
Top := 64;
Width := 75;
Height := 25;
Caption := 'Remove Song';
TabOrder := 10;
OnClick := @OkiClick;
end;
Button3 := TButton.Create(frmDesign);
with Button3 do
begin
Parent := frmDesign;
Left := 115;
Top := 96;
Width := 75;
Height := 25;
Caption := 'Stop Song';
TabOrder := 11;
OnClick := @OkiClick;
end;
Button4 := TButton.Create(frmDesign);
with Button4 do
begin
Parent := frmDesign;
Left := 120;
Top := 128;
Width := 65;
Height := 25;
Caption := 'Play';
TabOrder := 8;
OnClick := @OkiClick;
end;
Button5 := TButton.Create(frmDesign);
with Button5 do
begin
Parent := frmDesign;
Left := 8;
Top := 32;
Width := 97;
Height := 41;
Caption := 'Browse Music File';
TabOrder := 13;
OnClick := @OkiClick;
end;
Button6 := TButton.Create(frmDesign);
with Button6 do
begin
Parent := frmDesign;
Left := 8;
Top := 88;
Width := 97;
Height := 41;
Caption := 'Exit Program';
TabOrder := 14;
OnClick := @OkiClick;
end;
Button7 := TButton.Create(frmDesign);
with Button7 do
begin
Parent := frmDesign;
Left := 8;
Top := 144;
Width := 97;
Height := 41;
Caption := 'Visit Thread';
TabOrder := 15;
OnClick := @OkiClick;
end;
SongProg := TProgressBar.Create(GroupBox1);
with SongProg do
begin
Parent := GroupBox1;
Left := 216 + 10;
Top := 152;
Width := 127;
Height := 17;
TabOrder := 0;
Min := 0;
Max := 100;
end;
Label20 := TLabel.Create(GroupBox1);
with Label20 do
begin
Parent := GroupBox1;
Left := 112;
Top := 152;
Width := 69;
Height := 13;
Caption := 'Song Status | 0 / 0 ';
end;
Timer := TTimer.Create(frmDesign);
with Timer do
begin
Enabled := false;
Interval := 1;
OnTimer := @UpdateProgressbar1;
end;

WriteLn('MusicForm compiled in ' + IntToStr(GetSystemTime - TimeMusicForm) + ' milliseconds!');
end;

procedure SafeMusicForm;
var
V : TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('MusicForm', V);
end;

procedure ShowMusicFormModal;
begin
frmDesign.ShowModal;
end;

procedure SafeShowMusicFormModal;
var
V : TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('ShowMusicFormModal', V);
end;

procedure MainMusicForm;
begin
try
SafeMusicForm;
SafeShowMusicFormModal;
finally
FreeForm(frmDesign);
end;
end;

begin
ClearDebug;
If GetSCARVersion >= 300 Then
WriteLn('SCAR can run this')
Else
WriteLn('Please Upgrade to SCAR Divi :)');
MainMusicForm;
end.

I might make it play 2 songs later on. If you know how to make it play more than one, Please PM me. Thanks!

Freddy1990

2009-02-08 04:35:16

Hmm, gave me out of range error at some point… Btw, SCAR 3.20 can play wav, mp3, mp2, mp1, ogg, aiff, flac, …

senrath

2009-02-08 05:26:15

If I had multiple files in the list and tried to play anything other than the first file, it gave me an Out of Range error.

Naum

2009-02-08 06:34:23

It only plays one song atm, which is a real problem..


@Freedy really?? Thats so cool!! I cant wait for SCAR 3.20, after spending 1 hr searching for a plugin which converts music files.

Shuttleu

2009-02-08 07:06:52

From: NaumanAkhlaQ
@Freedy really?? Thats so cool!! I cant wait for SCAR 3.20, after spending 1 hr searching for a plugin which converts music files.


just get 3.20 RC2
theres a link on freddy1990.com main page

~shut

Naum

2009-02-08 07:12:34

Is it stable ATM?? Also how many people use SCAR 3.20?

Shuttleu

2009-02-08 07:24:05

From: NaumanAkhlaQ
Is it stable ATM?? Also how many people use SCAR 3.20?


well i use it and im sure quite a lot of other people use it aswell
i find it very stable and i havent found one bug yet

~shut

@freddy1990
how do you use the Music Player in SCAR 3.20?

Da 0wner

2009-02-10 03:20:48

TMusic component I believe.

Freddy1990

2009-02-10 06:19:16

From: Shuttleu
well i use it and im sure quite a lot of other people use it aswell
i find it very stable and i havent found one bug yet

~shut

@freddy1990
how do you use the Music Player in SCAR 3.20?


var
Music: TMusic;
begin
Music := GetMusicPlayer;
Music.LoadFromFile(
'yourfilehere'
);
Music.Play(True);
Wait(60000);
end.

EDIT: Btw, in the next release of 3.20 you'll also be able to get the total length of the song and the current position in the song (which you can also set)

Da 0wner

2009-02-10 20:07:54

Yep I knew it was TMusic :p. And Freddy that would be nice so that you can like click << or >> to go forward or backward in the song :).

P1nky

2009-02-12 11:14:19

From: Freddy1990
Hmm, gave me out of range error at some point… Btw, SCAR 3.20 can play wav, mp3, mp2, mp1, ogg, aiff, flac, …


wow thats quite helpful i use to hate converting the formats , for my forms.

Thanks for adding those formats