unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, MPlayer, ComCtrls, FileCtrl, ExtCtrls, mmsystem;
type
TForm1 =
class(TForm)
Button1: TButton;
MediaPlayer1: TMediaPlayer;
FileListBox1: TFileListBox;
DirectoryListBox1: TDirectoryListBox;
DriveComboBox1: TDriveComboBox;
ScrollBar1: TScrollBar;
Timer1: TTimer;
Button2: TButton;
Button3: TButton;
TrackBar1: TTrackBar;
procedure Button1Click(Sender: TObject);
procedure FileListBox1DblClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure SetVolume(
const volL, volR: Word);
procedure GetVolume(
var volL, volR: Word);
procedure TrackBar1Change(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
DateiNr,Dateianzahl: integer;
VolLi, VolRe: Word;
implementation
{$R *.dfm}
// -------------------------------------------------- Stop ----------
procedure TForm1.Button1Click(Sender: TObject);
begin
MediaPlayer1.Stop;
MediaPlayer1.Position := 0;
Timer1.Enabled := false;
ScrollBar1.Position := 0;
end;
// ---------------------------------------- Doppelklick auf Datei ----------
procedure TForm1.FileListBox1DblClick(Sender: TObject);
var
x:integer;
begin
MediaPlayer1.Stop;
for x:=0
to (FileListBox1.Count-1)
do
if FileListBox1.Selected[x]
then DateiNr:=x;
if DateiNr = 0
then
FileListBox1.Selected[0] := true;
MediaPlayer1.FileName := FileListBox1.FileName;
MediaPlayer1.Open;
MediaPlayer1.Play;
if MediaPlayer1.Length < 10000
then Timer1.Interval := 100;
if MediaPlayer1.Length > 100000
then Timer1.Interval := 2000;
Timer1.Enabled := true;
end;
// -------------------------------------------------- Position ----------
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if ScrollBar1.Position < 100
then
begin
ScrollBar1.Position := Round(MediaPlayer1.Position / (MediaPlayer1.Length / 100));
end;
if MediaPlayer1.Position = MediaPlayer1.Length
then
begin
ScrollBar1.Position := 0;
if DateiNr >= FileListBox1.Count-1
then
begin
if FileListBox1.Count > 0
then
begin
FileListBox1.Selected[0] := true;
FileListBox1DblClick(
NIL);
end else begin
Button1Click(
NIL);
end;
end else begin
FileListBox1.Selected[DateiNr+1] := true;
FileListBox1DblClick(
NIL);
end;
end;
end;
// -------------------------------------------------- Play ----------
procedure TForm1.Button2Click(Sender: TObject);
var
x,y:integer;
begin
for x:=0
to (FileListBox1.Count-1)
do
if FileListBox1.Selected[x]
then y:=x;
if (MediaPlayer1.Position = 0)
OR (DateiNr <> y)
then
begin
if FileListBox1.Count > 0
then
FileListBox1DblClick(
NIL);
end else
MediaPlayer1.Play;
end;
// -------------------------------------------------- Pause ----------
procedure TForm1.Button3Click(Sender: TObject);
begin
MediaPlayer1.Pause;
end;
// -------------------------------------------------- Lautstärke ermitteln ----------
procedure TForm1.GetVolume(
var volL, volR: Word);
var
hWO: HWAVEOUT;
waveF:
TWAVEFORMATEX;
vol: DWORD;
begin
volL:= 0;
volR:= 0;
// init TWAVEFORMATEX
FillChar(waveF, SizeOf(waveF), 0);
// open WaveMapper = std output of playsound
waveOutOpen(@hWO, WAVE_MAPPER, @waveF, 0, 0, 0);
// get volume
waveOutGetVolume(hWO, @vol);
volL:= vol
and $FFFF;
volR:= vol
shr 16;
waveOutClose(hWO);
end;
// -------------------------------------------------- Lautstärke setzen ----------
procedure TForm1.SetVolume(
const volL, volR: Word);
var
hWO: HWAVEOUT;
waveF:
TWAVEFORMATEX;
vol: DWORD;
begin
// init TWAVEFORMATEX
FillChar(waveF, SizeOf(waveF), 0);
// open WaveMapper = std output of playsound
waveOutOpen(@hWO, WAVE_MAPPER, @waveF, 0, 0, 0);
vol:= volL + volR
shl 16;
// set volume
waveOutSetVolume(hWO, vol);
waveOutClose(hWO);
end;
// -------------------------------------------------- Lautstärke setzen ----------
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
SetVolume(Round(VolLi/10*(10-TrackBar1.Position)),Round(VolRe/10*(10-TrackBar1.Position)));
end;
procedure TForm1.FormShow(Sender: TObject);
begin
GetVolume(VolLi,VolRe);
end;
end.