Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
3.doc
Скачиваний:
5
Добавлен:
24.02.2016
Размер:
26.27 Mб
Скачать

5. Листинг программы с комментариями

Рассмотрим листинг основных блоков и модулей программы.

Данный проект содержит 5 форм, которые являются основой приложений в Delphi.

Первая форма представляет собой главную форму программы, на которой расположены основные элементы программы. Наиболее главными компонентами на форме считаются компоненты ListBox-для отображения списков добавленных файлов, TrackBar- для регулировки звука, ProgressBar-для полоски прокрутки,Image-на этом компоненте помещена картинка, он выступает в роли кнопок, Timer-для регулировки скорости выезда\въезда панелей меню,Panel-на этом компоненте расположены пункты меню.

{**************************************

* Виктория Шевченко*

**************************************}

unit Media1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Buttons, ExtCtrls, MPlayer, jpeg, ComCtrls, Menus, MMSystem, StdCtrls, DirectShow9, UdxMediaPlayer, ComObj, ActiveX;

const

WM_MEDIA_NOTIFY = WM_USER + 1000;

type

PListBox=^TListBox;

TForm1 = class(TForm)

OpenDialog1: TOpenDialog;

ListBoxMediaName: TListBox;

ListBoxFiles: TListBox;

Label2: TLabel;

ProgressBar1: TProgressBar;

Panel2: TPanel;

Label4: TLabel;

TimerAnimacia: TTimer;

Timer500: TTimer;

ImageAddFiles: TImage;

ImageDelFiles: TImage;

PanelDel: TPanel;

DelSelect: TImage;

DelAll: TImage;

TimerDel: TTimer;

ImageFon: TImage;

ImagePause: TImage;

ImagePrev: TImage;

ImageBack: TImage;

ImagePlay: TImage;

ImageStep: TImage;

ImageNext: TImage;

ImageStop: TImage;

Antitle: TImage;

PanelAdd: TPanel;

AddFiles: TImage;

AddFolder: TImage;

AddPlaylist: TImage;

TimerAdd: TTimer;

MainMenu1: TMainMenu;

N2: TMenuItem;

N7: TMenuItem;

N8: TMenuItem;

ImageRepeat: TImage;

ImageRandom: TImage;

ImageVolume: TImage;

ImagePlaylist: TImage;

PanelPlaylist: TPanel;

ImageRenamePlaylist: TImage;

ImageSavePlaylist: TImage;

TimerPlaylist: TTimer;

TrackBar1: TTrackBar;

ImageDelPlaylist: TImage;

ListBoxPlayList: TListBox;

SaveDialogPlayList: TSaveDialog;

OpenDialogAddPlayList: TOpenDialog;

Timer1: TTimer;

N3: TMenuItem;

procedure ListBoxMediaNameDblClick(Sender: TObject);

procedure StopClick(Sender: TObject);

procedure ProgressBar1MouseDown(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

procedure TimerAnimaciaTimer(Sender: TObject);

procedure Timer500Timer(Sender: TObject);

procedure ImageDelFilesClick(Sender: TObject);

procedure TimerDelTimer(Sender: TObject);

procedure DelSelectClick(Sender: TObject);

procedure ImagePauseClick(Sender: TObject);

procedure ImagePrevClick(Sender: TObject);

procedure ImagePlayClick(Sender: TObject);

procedure ImageBackClick(Sender: TObject);

procedure ImageStepClick(Sender: TObject);

procedure ImageNextClick(Sender: TObject);

procedure ImageStopClick(Sender: TObject);

procedure TimerAddTimer(Sender: TObject);

procedure ImageAddFilesClick(Sender: TObject);

procedure N7Click(Sender: TObject);

procedure AddFilesClick(Sender: TObject);

procedure DelAllClick(Sender: TObject);

procedure AntitleClick(Sender: TObject);

procedure AddFolderClick(Sender: TObject);

procedure TimerPlaylistTimer(Sender: TObject);

procedure ImagePlaylistClick(Sender: TObject);

procedure N8Click(Sender: TObject);

procedure N9Click(Sender: TObject);

procedure TrackBar1Change(Sender: TObject);

procedure ImageVolumeClick(Sender: TObject);

procedure ImageRepeatClick(Sender: TObject);

procedure ImageRandomClick(Sender: TObject);

procedure ImageSavePlaylistClick(Sender: TObject);

procedure ImageDelPlaylistClick(Sender: TObject);

procedure ImageRenamePlaylistClick(Sender: TObject);

procedure AddPlaylistClick(Sender: TObject);

procedure N3Click(Sender: TObject);

procedure FormDestroy(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure FormShow(Sender: TObject);

procedure ButtonEnter(Sender: TObject);

procedure ButtonLeave(Sender: TObject);

procedure ImageRepeatMouseEnter(Sender: TObject);

procedure ImageRepeatMouseLeave(Sender: TObject);

procedure ImageVolumeMouseEnter(Sender: TObject);

procedure ImageVolumeMouseLeave(Sender: TObject);

private

FPositioning: boolean;

procedure MediaNotify(var Msg: Tmessage); message WM_MEDIA_NOTIFY;

{ Private declarations }

public

FileNamePls: string;

{ Public declarations }

end;

var

Form1: TForm1;

MediaPlayer: TdxMediaPlayer;

CurrentDir: string; // текущая директория

// функция которая преобразует минуты и секунды к виду mm:ss

function MinSecToTime(minuta,secunda: integer): string;

//процедура получает длительность трека в minuti и secundi

procedure GetTime(nomer_Treka: integer; var minuta, secunda: integer);

procedure StartTreck(treck: integer);

implementation

uses Unit2, FormRenamPls, FormPic, Unit3;//, StdCtrls;

var

// Revers: boolean; // True - реверсировать, False - не реверсировать

//Save_volume: integer; // Запоминает текущий звук, для кнопки отключить звук

test: integer;

napravlenie_Del: integer; //направление выезда панели удаления (1- выезжает, 2-заезжает);

napravlenie_Add: integer; //направление выезда панели добавления (1- выезжает, 2-заезжает);

napravlenie_Playlist: integer;

{$R *.dfm}

{*************************************************}

{** Обрабатываем сообщения от объекта MediaPlayer **}

{*************************************************}

procedure TForm1.MediaNotify(var Msg: Tmessage);

var

EventCode: Integer;

Param1, Param2: Integer;

var i:integer;

begin

while MediaPlayer.GetEvent(EventCode, Param1, Param2, 0) = S_OK do begin

if EventCode = EC_Complete then

begin MediaPlayer.Stop;

MediaPlayer.SetPlayingPosition(0);

for i := 0 to ListBoxMediaName.Count - 1 do

ListBoxMediaName.Selected[i]:=False;

if ListBoxMediaName.ItemIndex = ListBoxMediaName.Count-1 then begin ListBoxMediaName.ItemIndex:=0;

ListBoxFiles.ItemIndex:=0;

if ImageRepeat.Tag=1 then begin

StartTreck(ListBoxFiles.ItemIndex); end; end else begin ListBoxMediaName.ItemIndex:=ListBoxMediaName.ItemIndex+1;

ListBoxFiles.ItemIndex:=ListBoxFiles.ItemIndex+1;

StartTreck(ListBoxFiles.ItemIndex); end; end; ListBoxMediaName.Selected[ListBoxMediaName.ItemIndex]:=True; end; end;

procedure TForm1.ButtonEnter(Sender: TObject);

begin (Sender as TImage).Picture.LoadFromFile(CurrentDir+'\Image\'+(Sender as TImage).Name+'Sel.jpg'); end;

procedure TForm1.ButtonLeave(Sender: TObject);

begin (Sender as TImage).Picture.LoadFromFile(CurrentDir+'\Image\'+(Sender as TImage).Name+'.jpg');

end;

Procedure FillList(List:PListBox;pathh,mask:string;attr:Cardinal);

var path:string;

ser:TSearchRec;

begin path:=pathh;

if path[length(path)]<>'\' then

path:=path+'\';

List^.Items.Clear; if FindFirst(path+mask,attr,ser)<>0 then

exit; List^.Items.Add(ser.Name);

while FindNext(ser)=0 do

begin if ser.Attr and faDirectory=faDirectory then

List^.Items.Add(' ['+Ser.Name+']')

else List^.Items.Add(Ser.Name); end;

List^.Sorted:=false;

list^.Sorted:=true; end;

procedure StartTreck(treck: integer);

var

s: string;

Ext: string; //расширение файла

Volume: longint;

begin MediaPlayer.Stop;

Form1.ListBoxMediaName.Selected[treck]:=True;

s:=Form1.ListBoxFiles.Items[treck];

Ext:=LowerCase(ExtractFileExt(s));

FormPicture.Caption:=ExtractFileName(s);

if (Ext = '.jpg') or (Ext = '.bmp') then begin

FormPicture.Image1.Picture.LoadFromFile(s);

if FormPicture.Image1.Picture.Width<FormPicture.Image1.Width then FormPicture.Image1.Stretch:=False

else FormPicture.Image1.Stretch:=True;

FormPicture.PanelVideo.Visible:=False;

FormPicture.Image1.Visible:=True;

FormPicture.Show; end else begin

FormPicture.PanelVideo.Visible:=True;

FormPicture.Image1.Visible:=False;

if (Ext = '.avi') then

begin FormPicture.Show;

end; if (Ext = '.mp3') then

begin FormPicture.Close; end;

if SUCCEEDED(MediaPlayer.Initialize(WideString(s))) then begin

Form1.ProgressBar1.Max := MediaPlayer.FrameCount;

FormPicture.ProgressBar1.Max:=Form1.ProgressBar1.Max;

MediaPlayer.RegisterEventMessage(Form1.Handle, WM_MEDIA_NOTIFY);

MediaPlayer.SetWindowPosition(Rect(0, 0, FormPicture.PanelVideo.ClientRect.Right,

FormPicture.panelVideo.ClientRect.Bottom));

MediaPlayer.SetVolume(Form1.TrackBar1.Position * 50); end;

MediaPlayer.Play;

Form1.label4.Caption:= Form1.ListBoxMediaName.Items[treck];

Form1.label4.Left:=Form1.Panel2.Width;

Form1.TimerAnimacia.Enabled:=True;

Form1.ImagePlay.Tag:=1;

Form1.ImagePause.Tag:=0;

Form1.Timer500.Enabled:=True;

end; end;

// функция которая преобразует минуты и секунды к виду mm:ss function MinSecToTime(minuta,secunda: integer): string;

var

str: string;

begin if minuta>9 then

str := IntToStr(minuta) else

str:='0'+IntToStr(minuta);

str:=str+':';

if secunda>9 then str := str + IntToStr(secunda)

else str:= str + '0'+IntToStr(secunda);

result:=str; end;

procedure GetTime(nomer_Treka: integer; var minuta, secunda: integer);

var

posicia, TheLength: int64;

begin MediaPlayer.GetPlayingPosition(posicia);

TheLength := MediaPlayer.FrameCount;//[nomer_Treka];

minuta:=((TheLength -posicia) div 20) div 60;

secunda:=((TheLength -posicia) div 20) mod 60; end;

procedure TForm1.DelAllClick(Sender: TObject);

begin

ListBoxMediaName.Clear;

ListBoxFiles.Clear;

TimerDel.Enabled:=True; end;

procedure TForm1.DelSelectClick(Sender: TObject);

var i: integer;

begin i:=0;

while i < ListBoxMediaName.Count do begin

ша ДшыеИщчЬувшфТфьуюЫудусеувхшъ ерут ..Если очередной элемент выделенб то

begin

ListBoxMediaName.Items.Delete(i);

ListBoxFiles.Items.Delete(i) end

else i:=i+1; end;

TimerDel.Enabled:=True; end;

procedure TForm1.FormCreate(Sender: TObject);

var vol: longint;

begin

OpenDialog1.Filter:='медиофайлы|*.avi;*.mp3;*.jpg; *.bmp';

CurrentDir:=GetCurrentDir;

Randomize;

Form1.Width:=ImageFon.Width;

// делаем панель удаления и добавления не видимой

PanelDel.Visible:=False;

PanelAdd.Visible:=False;

PanelPlaylist.Visible:=False;

napravlenie_Del:=1;

PanelDel.Height:=0;

PanelDel.Top:=ImageDelFiles.Top;

PanelDel.Left:=ImageDelFiles.Left;

napravlenie_Add:=1;

PanelAdd.Height:=0;

PanelAdd.Top:=ImageAddFiles.Top;

PanelAdd.Left:=ImageAddFiles.Left;

napravlenie_Playlist:=1;

PanelPlaylist.Height:=0;

PanelPlaylist.Top:=ImagePlaylist.Top;

PanelPlaylist.Left:=ImagePlaylist.Left;

TrackBar1.Max:=0;

TrackBar1.Min:=-100;

TrackBar1.Position:=-100;

TrackBar1.Frequency:=5; end;

procedure TForm1.FormDestroy(Sender: TObject);

begin FreeAndNil(MediaPlayer); end;

procedure TForm1.FormShow(Sender: TObject);

var vol: longint;

begin MediaPlayer :=

TdxMediaPlayer.Create(FormPicture.panelVideo.Handle);

ImageVolume.Tag:=1;

Form1.TrackBar1.Position := -30; end;

procedure TForm1.ImagePauseClick(Sender: TObject);

begin

if ImagePause.Tag=0 then

begin

MediaPlayer.Pause;

ImagePause.Tag:=1;

ImagePlay.Tag:=0;

end; end;

procedure TForm1.ImagePlayClick(Sender: TObject);

begin if ImagePlay.Tag=0 then

begin MediaPlayer.Play;

ImagePlay.Tag:=1; end

else begin

MediaPlayer.Pause;

ImagePlay.Tag:=0; end; end;

procedure TForm1.ImagePlaylistClick(Sender: TObject);

var s,Dir: string;

begin

if PanelPlaylist.Height<=0 then

begin

ListBoxPlayList.Clear;

Dir:=CurrentDir+'\PlayLists';

FillList(@ListBoxPlayList,Dir,'*.mpls',faAnyFile);

end; if PanelAdd.Height>0 then

TimerAdd.Enabled:=True;

if PanelDel.Height>0 then

TimerDel.Enabled:=True;

TimerPlaylist.Enabled:=True; end;

procedure TForm1.ImagePrevClick(Sender: TObject);

begin MediaPlayer.Pause;

ProgressBar1.Position:=ProgressBar1.Position-200;

MediaPlayer.SetPlayingPosition(ProgressBar1.Position);

MediaPlayer.Play; end;

procedure TForm1.ImageRenamePlaylistClick(Sender: TObject);

var count: integer;

i: integer;

Dir: string;

begin

count:=0;

for i := 0 to ListBoxPlayList.Count-1 do

begin if ListBoxPlayList.Selected[i] = True then

begin count:=count+1; end; end;

if count = 1 then

begin Dir:=CurrentDir+'\Playlists\';

FormRenamePlayList.ShowModal;

RenameFile(Dir+ListBoxPlayList.Items[ListBoxPlayList.ItemIndex, Dir+FileNamePls+'.mpls');

ListBoxPlayList.Clear;

FillList(@ListBoxPlayList,Dir,'*.mpls',faAnyFile); end else

begin ShowMessage('Нужно выделить только один плейлист');

exit; end; end;

procedure TForm1.ImageSavePlaylistClick(Sender: TObject);

var f: TextFile;

i: integer;

begin SaveDialogPlayList.InitialDir:=CurrentDir+'\PlayLists';

if SaveDialogPlayList.Execute then begin

AssignFile(f,SaveDialogPlayList.FileName);

Rewrite(f);

for i := 0 to ListBoxFiles.Count - 1 do

writeln(f, ListBoxFiles.Items[i]);

CloseFile(f); end; end;

procedure TForm1.ImageStepClick(Sender: TObject);

var i: integer;

begin for i := 0 to ListBoxMediaName.Count - 1 do

ListBoxMediaName.Selected[i]:=False;

if ListBoxMediaName.ItemIndex = ListBoxMediaName.Count-1 then ListBoxMediaName.ItemIndex:=0 else

ListBoxMediaName.ItemIndex:=ListBoxMediaName.ItemIndex+1;

ListBoxFiles.ItemIndex:=ListBoxMediaName.ItemIndex;

StartTreck(ListBoxMediaName.ItemIndex); end;

procedure TForm1.ImageStopClick(Sender: TObject);

begin MediaPlayer.SetPlayingPosition(0);

MediaPlayer.Stop;

ImagePlay.Tag:=0; end;

procedure TForm1.AntitleClick(Sender: TObject);

var i: integer;

begin i:=0;

while i < ListBoxFiles.Count do begin

if not FileExists(ListBoxFiles.Items[i]) then //Если очередной элемент выделен, то

begin ListBoxMediaName.Items.Delete(i);

ListBoxFiles.Items.Delete(i) end else

i:=i+1; end;

TimerDel.Enabled:=True; end;

procedure TForm1.AddFilesClick(Sender: TObject);

var s: string;

begin if OpenDialog1.Execute then

begin ListBoxFiles.Items.Add(OpenDialog1.FileName);

s:=ExtractFileName(OpenDialog1.FileName);

ListBoxMediaName.ItemIndex:=ListBoxMediaName.Items.Add(s);

ListBoxFiles.ItemIndex:=ListBoxMediaName.ItemIndex;

ListBoxMediaName.Selected[ListBoxMediaName.ItemIndex]:=Tru;

StartTreck(ListBoxMediaName.ItemIndex); end;

TimerAdd.Enabled:=True; end;

procedure TForm1.AddFolderClick(Sender: TObject);

var s: string;

i: integer;

begin OpenDialog1.Options:=OpenDialog1.Options + [ofAllowMultiSelect];

if OpenDialog1.Execute then

begin for i := 0 to OpenDialog1.Files.Count - 1 do begin

ListBoxFiles.Items.Add(OpenDialog1.Files[i]);

s:=ExtractFileName(OpenDialog1.Files[i]);

ListBoxMediaName.Items.Add(s); end;

ListBoxMediaName.ItemIndex:=0;

ListBoxFiles.ItemIndex:=ListBoxMediaName.ItemIndex;

ListBoxMediaName.Selected[ListBoxMediaName.ItemIndex]:=Tru;

StartTreck(ListBoxMediaName.ItemIndex);

StartTreck(ListBoxMediaName.ItemIndex); end;

TimerAdd.Enabled:=True;

OpenDialog1.Options:=OpenDialog1.Options - [ofAllowMultiSelect]; end;

procedure TForm1.AddPlaylistClick(Sender: TObject);

var s,fileName: string;

f: TextFile;

begin SaveDialogPlayList.InitialDir:=CurrentDir+'\PlayLists';

if OpenDialogAddPlayList.Execute then

begin Assignfile(f,OpenDialogAddPlayList.FileName);

Reset(f);

while not Eof(f) do

begin Readln(f,fileName);

ListBoxFiles.Items.Add(fileName);

s:=ExtractFileName(fileName);

ListBoxMediaName.Items.Add(s); end; end;

TimerAdd.Enabled:=True;

ListBoxMediaName.ItemIndex:=0;

ListBoxFiles.ItemIndex:=ListBoxMediaName.ItemIndex;

ListBoxMediaName.Selected[ListBoxMediaName.ItemIndex]:=Tru;

end;

procedure TForm1.ImageRepeatClick(Sender: TObject);

begin if ImageRepeat.Tag = 1 then begin

ImageRepeat.Tag:=0;

ImageRepeat.Picture.LoadFromFile(CurrentDir+'\Image\ImageRepeatOFF.jpg');

end else begin ImageRepeat.Tag:=1;

ImageRepeat.Picture.LoadFromFile(CurrentDir+'\Image\ImageRepeatON.jpg'); end; end;

procedure TForm1.ImageRepeatMouseEnter(Sender: TObject);

begin

if ImageRepeat.Tag = 1 then begin

ImageRepeat.Picture.LoadFromFile(CurrentDir+'\Image\ImageRepeatONSel.jpg'); end else

begin

ImageRepeat.Picture.LoadFromFile(CurrentDir+'\Image\ImageRepeatOFFSel.jpg'); end; end;

procedure TForm1.ImageRepeatMouseLeave(Sender: TObject);

begin if ImageRepeat.Tag = 1 then

begin

ImageRepeat.Picture.LoadFromFile(CurrentDir+'\Image\ImageRepeatON.jpg'); end else begin

ImageRepeat.Picture.LoadFromFile(CurrentDir+'\Image\ImageRepeatOFF.jpg'); end; end;

procedure TForm1.ImageRandomClick(Sender: TObject);

var ItemsTemp: TStringList;

sluch: integer;

i: Integer;

s: string; begin

ItemsTemp := TStringList.Create;

ItemsTemp.Clear;

while ListBoxFiles.Count>0 do

begin sluch:=Random(ListBoxFiles.Count);

ItemsTemp.Add(ListBoxFiles.Items[sluch]);

ListBoxFiles.Items.Delete(sluch); end;

for i := 0 to ItemsTemp.Count-1 do begin

ListBoxFiles.Items.Add(ItemsTemp[i]) end;

ListBoxMediaName.Clear;

for i := 0 to ListBoxFiles.Count - 1 do

begin s:=ExtractFileName(ListBoxFiles.Items[i]);

ListBoxMediaName.Items.Add(s); end;

ItemsTemp.Destroy; end;

procedure TForm1.ImageVolumeClick(Sender: TObject);

var Vol: longint;

begin if ImageVolume.Tag = 1 then begin

ImageVolume.Tag:=0;

MediaPlayer.SetVolume(-5000);

ImageVolume.Picture.LoadFromFile(CurrentDir+'\Image\ImageVolumeOFF.jpg'); end else begin

ImageVolume.Tag:=1;

MediaPlayer.SetVolume(TrackBar1.Position*50);

ImageVolume.Picture.LoadFromFile(CurrentDir+'\Image\ImageVolumeON.jpg'); end; end;

procedure TForm1.ImageVolumeMouseEnter(Sender: TObject);

begin if ImageVolume.Tag = 1 then begin

ImageVolume.Picture.LoadFromFile(CurrentDir+'\Image\ImageVolumeONSel.jpg'); end else begin

ImageVolume.Picture.LoadFromFile(CurrentDir+'\Image\ImageVolumeOFFSel.jpg'); end; end;

procedure TForm1.ImageVolumeMouseLeave(Sender: TObject);

begin if ImageVolume.Tag = 1 then begin

ImageVolume.Picture.LoadFromFile(CurrentDir+'\Image\ImageVolumeON.jpg');

end else begin

ImageVolume.Picture.LoadFromFile(CurrentDir+'\Image\ImageVolumeOFF.jpg'); end; end;

procedure TForm1.ImageAddFilesClick(Sender: TObject);

begin if PanelDel.Height>0 then

TimerDel.Enabled:=True;

if PanelPlaylist.Height>0 then

TimerPlaylist.Enabled:=True;

TimerAdd.Enabled:=True; end;

procedure TForm1.ImageBackClick(Sender: TObject);

var i: integer;

begin for i := 0 to ListBoxMediaName.Count - 1 do

ListBoxMediaName.Selected[i]:=False;

if ListBoxMediaName.ItemIndex <> 0 then

ListBoxMediaName.ItemIndex:=ListBoxMediaName.ItemIndex-1

else ListBoxMediaName.ItemIndex:=ListBoxMediaName.Count-1;

ListBoxFiles.ItemIndex:=ListBoxMediaName.ItemIndex;

StartTreck(ListBoxMediaName.ItemIndex); end;

procedure TForm1.ImageDelPlaylistClick(Sender: TObject);

var i: integer;

begin for i := 0 to ListBoxPlayList.Count-1 do

begin if ListBoxPlayList.Selected[i] = True then

begin DeleteFile(CurrentDir+'\Playlists\'+ListBoxPlayList.Items[i]);

end; end; ListBoxPlayList.Clear;

FillList(@ListBoxPlayList,CurrentDir+'\Playlists\','*.mpls',faAnyFile); end;

procedure TForm1.ImageDelFilesClick(Sender: TObject);

begin if PanelAdd.Height>0 then

TimerAdd.Enabled:=True;

if PanelPlaylist.Height>0 then

TimerPlaylist.Enabled:=True;

TimerDel.Enabled:=True; end;

procedure TForm1.ImageNextClick(Sender: TObject);

begin MediaPlayer.Pause;

ProgressBar1.Position:=ProgressBar1.Position+200;

MediaPlayer.SetPlayingPosition(ProgressBar1.Position);

MediaPlayer.Play; end;

procedure TForm1.ListBoxMediaNameDblClick(Sender: TObject);

var s: string;

begin

ListBoxFiles.ItemIndex:=ListBoxMediaName.ItemIndex;

StartTreck(ListBoxMediaName.ItemIndex); end;

procedure TForm1.N7Click(Sender: TObject);

begin close; end;

procedure TForm1.N8Click(Sender: TObject);

begin AboutForm.Top:= Trunc(Form1.Top + Form1.Height/2 - AboutForm.Height/2);

AboutForm.Left := Trunc(Form1.Left +Form1.Width/2 - AboutForm.Width/2);

AboutForm.ShowModal; end;

procedure TForm1.N9Click(Sender: TObject);

// щелчок на кнопке Справка begin

winhelp(form1.Handle, 'MediaPlayer.HLP', help_context,1); end;

procedure TForm1.ProgressBar1MouseDown(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

begin MediaPlayer.Pause;

ProgressBar1.Position:=Trunc(ProgressBar1.Max*X/ProgressBar1.Width);

MediaPlayer.SetPlayingPosition(ProgressBar1.Position);

MediaPlayer.Play; end;

procedure TForm1.StopClick(Sender: TObject);

begin MediaPlayer.Stop; end;

procedure TForm1.TimerAddTimer(Sender: TObject);

begin if PanelDel.Height or PanelPlaylist.Height> 0 then

exit; if napravlenie_Add=2 then // если нужно заезжать

begin if PanelAdd.Height >0 then

begin PanelAdd.Top:=PanelAdd.Top+10;

PanelAdd.Height:=PanelAdd.Height-10; end

else begin TimerAdd.Enabled:=False;

PanelAdd.Visible:=False;

napravlenie_Add:=1;

PanelAdd.Height:=0;

PanelAdd.Top:=PanelAdd.Top; end; end

else begin if PanelAdd.Height<180 then

begin PanelAdd.Visible:=True;

PanelAdd.Top:=PanelAdd.Top-10;

PanelAdd.Height:=PanelAdd.Height+10; end

else begin TimerAdd.Enabled:=False;

napravlenie_Add:=2; end; end; end;

procedure TForm1.TimerAnimaciaTimer(Sender: TObject);

begin label4.Left:=label4.Left-4;

if (label4.Left+label4.Width) < 0 then

label4.Left:=Panel2.Width; end;

procedure TForm1.TimerDelTimer(Sender: TObject);

begin if PanelAdd.Height or PanelPlaylist.Height> 0 then

exit; if napravlenie_Del=2 then // если нужно заезжать

begin if PanelDel.Height>0 then

begin PanelDel.Top:=PanelDel.Top+10;

PanelDel.Height:=PanelDel.Height-10; end

else begin TimerDel.Enabled:=False;

PanelDel.Visible:=False;

napravlenie_Del:=1;

PanelDel.Height:=0;

PanelDel.Top:=PanelDel.Top; end; end

else begin if PanelDel.Height<180 then

begin PanelDel.Visible:=True;

PanelDel.Top:=PanelDel.Top-10;

PanelDel.Height:=PanelDel.Height+10; end

else begin TimerDel.Enabled:=False;

napravlenie_Del:=2; end; end; end

procedure TForm1.TimerPlaylistTimer(Sender: TObject);

begin if PanelAdd.Height or PanelDel.Height> 0 then

exit; if napravlenie_Playlist=2 then // если нужно заезжать

begin if PanelPlaylist.Height>0 then

begin PanelPlaylist.Top:=PanelPlaylist.Top+10;

PanelPlaylist.Height:=PanelPlaylist.Height-10; end else begin

TimerPlaylist.Enabled:=False;

PanelPlaylist.Visible:=False;

napravlenie_Playlist:=1;

PanelPlaylist.Height:=0;

PanelPlaylist.Top:=PanelPlaylist.Top; end; end

else begin if PanelPlaylist.Height<241 then

begin PanelPlaylist.Visible:=True;

PanelPlaylist.Top:=PanelPlaylist.Top-10;

PanelPlaylist.Height:=PanelPlaylist.Height+10; end

else begin TimerPlaylist.Enabled:=False;

napravlenie_Playlist:=2; end; end; end;

procedure TForm1.TrackBar1Change(Sender: TObject);

var Vol: longint;

begin if ImageVolume.Tag=1 then

begin MediaPlayer.SetVolume(TrackBar1.Position * 50);

end; end;

procedure TForm1.Timer500Timer(Sender: TObject);

var minuta, secunda: integer;

Pos: int64;

begin if SUCCEEDED(MediaPlayer.GetPlayingPosition(Pos)) then

ProgressBar1.Position:=Pos;

if ListBoxMediaName.ItemIndex>=0 then

begin GetTime(ListBoxMediaName.ItemIndex, minuta, secunda);

label2.Caption:=MinSecToTime(minuta,secunda); end; end;

procedure TForm1.N3Click(Sender: TObject); begin AboutForm2.Top:= Trunc(Form1.Top + Form1.Height/2 - AboutForm2.Height/2);

AboutForm2.Left := Trunc(Form1.Left +Form1.Width/2 - AboutForm2.Width/2);

AboutForm2.ShowModal; end; end.

Вторая форма представляет собой окно для вывода изображений и видео на экран. Главными компонентами на форме являются: ProgressBar-для полоски прокрутки, Image-на этом компоненте выводятся изображения, Panel-на этом компонент выводиться видео.

unit FormPic;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, ComCtrls, jpeg, DirectShow9, UdxMediaPlayer;

type

TFormPicture = class(TForm)

Image1: TImage;

PanelVideo: TPanel;

ImageStop: TImage;

ImageStep: TImage;

ImagePlay: TImage;

ImageBack: TImage;

ProgressBar1: TProgressBar;

Timer1: TTimer;

Image2: TImage;

procedure FormActivate(Sender: TObject);

procedure ButtonEnter(Sender: TObject);

procedure ButtonLeave(Sender: TObject);

procedure ImagePauseClick(Sender: TObject);

procedure ImagePrevClick(Sender: TObject);

procedure ImageBackClick(Sender: TObject);

procedure ImagePlayClick(Sender: TObject);

procedure ImageStepClick(Sender: TObject);

procedure ImageStopClick(Sender: TObject);

procedure ImagePlayMouseEnter(Sender: TObject);

procedure ImagePlayMouseLeave(Sender: TObject);

procedure Timer1Timer(Sender: TObject);

procedure FormClose(Sender: TObject; var Action: TCloseAction);

procedure ProgressBar1MouseDown(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

procedure FormResize(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

FormPicture: TFormPicture;

implementation

uses Media1;

{$R *.dfm}

procedure TFormPicture.FormActivate(Sender: TObject);

begin PanelVideo.Height:=409;

PanelVideo.Width:=600;

Left:=Form1.Left+Form1.Width+10;

Top:=Form1.Top; end;

procedure TFormPicture.FormClose(Sender: TObject; var Action: TCloseAction);

begin Form1.ImageStop.OnClick(Sender); end;

procedure TFormPicture.FormResize(Sender: TObject);

begin MediaPlayer.SetWindowPosition(Rect(0, 0, panelVideo.ClientRect.Right,

panelVideo.ClientRect.Bottom)); end;

procedure TFormPicture.ImageBackClick(Sender: TObject);

begin Form1.ImageBack.OnClick(Sender); end;

procedure TFormPicture.ImagePauseClick(Sender: TObject);

begin Form1.ImagePause.OnClick(Sender); end;

procedure TFormPicture.ImagePlayClick(Sender: TObject);

begin Form1.ImagePlay.OnClick(Sender); end;

procedure TFormPicture.ImagePlayMouseEnter(Sender: TObject);

begin if Form1.ImagePlay.Tag=1 then

ImagePlay.Picture.LoadFromFile(Media1.CurrentDir+'\Image\'+Form1.ImagePlay.Name+'Sel.jpg') else ImagePlay.Picture.LoadFromFile(Media1.CurrentDir+'\Image\'+Form1.ImagePause.Name+'Sel.jpg'); end;

procedure TFormPicture.ImagePlayMouseLeave(Sender: TObject);

begin if Form1.ImagePlay.Tag=1 then ImagePlay.Picture.LoadFromFile(Media1.CurrentDir+'\Image\'+Form1.ImagePlay.Name+'.jpg') else ImagePlay.Picture.LoadFromFile(Media1.CurrentDir+'\Image\'+Form1.ImagePause.Name+'.jpg'); end;

procedure TFormPicture.ImagePrevClick(Sender: TObject);

begin Form1.ImagePrev.OnClick(Sender); end;

procedure TFormPicture.ImageStepClick(Sender: TObject);

begin Form1.ImageStep.OnClick(Sender); end;

procedure TFormPicture.ImageStopClick(Sender: TObject);

begin Form1.ImageStop.OnClick(Sender); end;

procedure TFormPicture.ProgressBar1MouseDown(Sender: TObject;

Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

var X1: integer;

begin X1:=Trunc(X*Form1.ProgressBar1.Width/ProgressBar1.Width);

Form1.ProgressBar1.OnMouseDown(Sender,Button,Shift,X1,Y); end;

procedure TFormPicture.Timer1Timer(Sender: TObject);

var Pos: int64;

begin if SUCCEEDED(MediaPlayer.GetPlayingPosition(Pos)) then

ProgressBar1.Position:=Pos; end;

procedure TFormPicture.ButtonEnter(Sender: TObject);

begin(Sender as TImage).Picture.LoadFromFile(Media1.CurrentDir

+'\Image\'+(Sender as TImage).Name+'Sel.jpg'); end;

procedure TFormPicture.ButtonLeave(Sender: TObject);

begin (Sender as TImage).Picture.LoadFromFile(Media1.CurrentDir

+'\Image\'+(Sender as TImage).Name+'.jpg'); end; end.

Третья форма. Диалоговое окно предназначенное для ввода нового имени плейлиста при переименовании.

unit FormRenamPls;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Forms, Controls, Dialogs, StdCtrls, Buttons, jpeg, ExtCtrls;

type

TFormRenamePlayList = class(TForm)

Label1: TLabel;

BitBtn1: TBitBtn;

Image1: TImage;

Edit1: TEdit;

procedure BitBtn1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

FormRenamePlayList: TFormRenamePlayList;

implementation

uses Media1;

{$R *.dfm}

procedure TFormRenamePlayList.BitBtn1Click(Sender: TObject);

begin Form1.FileNamePls:=Edit1.Text; end; end.

Четвёртая форма представляет собой окно информации о программе.

unit FormRenamPls;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, jpeg, ExtCtrls;

Type

TFormRenamePlayList = class(TForm)

Label1: TLabel;

BitBtn1: TBitBtn;

Image1: TImage;

Edit1: TEdit;

procedure BitBtn1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

FormRenamePlayList: TFormRenamePlayList;

implementation

uses Media1;

{$R *.dfm}

procedure TFormRenamePlayList.BitBtn1Click(Sender: TObject);

begin Form1.FileNamePls:=Edit1.Text; end; end.

Пятая форма представляет собой окно информации об авторе.

unit Unit3;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls, Buttons, jpeg, ExtCtrls;

type

TAboutForm2 = class(TForm)

Image1: TImage;

Image2: TImage;

Label1: TLabel;

Label2: TLabel;

Label3: TLabel;

BitBtn1: TBitBtn;

procedure BitBtn1Click(Sender: TObject);

private

{ Private declarations }

Public

{ Public declarations } end;

var

AboutForm2: TAboutForm2;

implementation

{$R *.dfm}

procedure TAboutForm2.BitBtn1Click(Sender: TObject);

begin ModalResult := mrOk; end; end.

57

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]