Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.07.25;
Скачать: CL | DM;

Вниз

Вопрос по Медиа Плееру   Найти похожие ветки 

 
NightDevil ©   (2004-05-08 17:43) [0]

Как сделать, чтобы положение TrackBar"а соответствовало просмотренному в MediaPlayer"e ролику, и чтоб при изменении его положения менялся кадр?


 
student2   (2004-05-08 17:59) [1]

Присвой максу у трекбара количество фреймой у ролика.


 
*BES* ©   (2004-05-08 21:37) [2]

<ТАЙМЕР>
Допустим TrackBar1.Max := Mediaplayer1.lengtj;


 
Юрий Ж. ©   (2004-05-08 22:41) [3]

Сталкивался я стакой проблемой...Единственное что пришло на ум это при изменении (прокрутке) TrackBar"а проверять на сколько он изменился и если меньше, например 100, то ничего не делать, иначе
MediaPlayer.Position:=TrackBar.Position

А по таймеру с интервалом в 1000 млс
TrackBar.Position:=MediaPlayer.Position

А чтобы вообще исчерпать вопрос вот код (САМ ПИСАЛ!!!):

...
var
 Form1: TForm1;
 Paused: boolean = False;
 CurVol: DWord;
 BeginVol: DWord;
 CurIndex: Integer = -1;
implementation
uses MMSystem;
{$R *.dfm}

function GetWaveVolume: DWord; // Получает громкость
var
 Woc : TWAVEOUTCAPS;
 Volume : DWord;
begin
 result:=0;
 if WaveOutGetDevCaps(WAVE_MAPPER, @Woc, sizeof(Woc)) = MMSYSERR_NOERROR then
   if Woc.dwSupport and WAVECAPS_VOLUME = WAVECAPS_VOLUME then
     begin
       WaveOutGetVolume(WAVE_MAPPER,@Volume);
       Result := Volume;
     end;
end;

procedure SetWaveVolume(const AVolume: DWord); // Устанавливает громкость
var
 Woc : TWAVEOUTCAPS;
begin
 if WaveOutGetDevCaps(WAVE_MAPPER, @Woc, sizeof(Woc)) =MMSYSERR_NOERROR then
   if Woc.dwSupport and WAVECAPS_VOLUME = WAVECAPS_VOLUME then
     WaveOutSetVolume(WAVE_MAPPER, AVolume);
end;

function AlreadyAdd(FileName:String):boolean;
var
 i: integer;
begin
 Result:=False;
 i:=0;
 while i<=Form1.ListBox1.Count-1 do
 begin
   if Form1.ListBox1.Items.Strings[i]=FileName then
   begin
     Result:=true;
     Exit;
   end;
   inc(i);
 end;
end;

procedure PlayFile(FileName: String);
begin
 with Form1 do
 begin
   MediaPlayer1.Close;
   TrackBar1.Position:=0;
   MediaPlayer1.FileName:=FileName;
   MediaPlayer1.Open;
   MediaPlayer1.TimeFormat := tfMilliseconds;
   TrackBar1.Max:=MediaPlayer1.Length;
   Timer1.OnTimer(Timer1);
   Timer1.Enabled:=True;
   MediaPlayer1.Play;
 end;
end;

function AddNeed(Str: String;Need: byte):string;
begin
 Result:=Str;
 while Length(Result)< Need do
   insert("0",Result,1);
end;

procedure TForm1.SpeedButton6Click(Sender: TObject);
var
 i: integer;
begin
 if not OpenDialog1.Execute then Exit;
 if ListBox1.Count=0 then CurIndex:=0;
 for i:=0 to OpenDialog1.Files.Count-1 do
   if not AlreadyAdd(OpenDialog1.Files.Strings[i]) then
     ListBox1.Items.Add(OpenDialog1.Files.Strings[i]);
 if ListBox1.Count=1 then
   CurIndex:= 0;
 ListBox1.ItemIndex:=CurIndex;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
 if Paused then
 begin
   MediaPlayer1.Play;
   Paused:=False;
   Exit;
 end;
 if ListBox1.Count>0 then
 PlayFile(ListBox1.Items.Strings[CurIndex]) else
 begin
   SpeedButton6.OnClick(Self);
   if ListBox1.Count>0 then
   PlayFile(ListBox1.Items.Strings[0]);
 end;
end;

procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
 if ListBox1.Count>0 then
 begin
   PlayFile(ListBox1.Items.Strings[ListBox1.ItemIndex]);
   CurIndex:=ListBox1.ItemIndex;
 end;
end;

procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
 if not Paused then
 begin
   MediaPlayer1.PauseOnly;
   Paused:=True;
 end else
 begin
   MediaPlayer1.Play;
   Paused:=False;
 end;
end;

procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
 MediaPlayer1.Stop;
 Timer1.Enabled:=False;
 TrackBar1.Position:=0;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
 if (ListBox1.Count > 1) and (CurIndex > 0) then
 begin
   PlayFile(ListBox1.Items.Strings[ListBox1.ItemIndex-1]);
   ListBox1.ItemIndex:=CurIndex-1;
   Dec(CurIndex);
 end;
end;

procedure TForm1.SpeedButton5Click(Sender: TObject);
begin
 if (ListBox1.Count > 1) and (CurIndex < ListBox1.Count -1) then
 begin
   PlayFile(ListBox1.Items.Strings[ListBox1.ItemIndex+1]);
   ListBox1.ItemIndex:=CurIndex+1;
   Inc(CurIndex);
 end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
 i,l: integer;
begin
 TrackBar1.Position:=MediaPlayer1.Position;
 i:=MediaPlayer1.Position;
 l:=MediaPlayer1.Length;
 l:=l div 1000;
 i:=i div 1000;

 Label10.Caption:=Format("Time: %s:%s / %s:%s",
 [AddNeed(IntToStr(i div 60),2), AddNeed(InttoStr(i mod 60),2),
  AddNeed(IntToStr(l div 60),2),AddNeed(IntToStr(l mod 60),2)]);
end;

procedure TForm1.ListBox1KeyDown(Sender: TObject; var Key: Word;
 Shift: TShiftState);
var
 i : integer;
begin
 if Key = vk_delete then
 begin
  i:=ListBox1.ItemIndex;
  ListBox1.DeleteSelected;
  ListBox1.ItemIndex:=i;
  CurIndex:=i;
 end;
 if (Key = vk_return) and (ListBox1.Count > 0) then
   ListBox1.OnDblClick(ListBox1);
end;

procedure TForm1.MediaPlayer1Notify(Sender: TObject);
begin
 with MediaPlayer1 do
 if NotifyValue = nvSuccessful then
 begin
   Notify := True;
   SpeedButton5.OnClick(Sender);
 end;
end;

procedure TForm1.TrackBar2Change(Sender: TObject);
begin
 if TrackBar2.Position <= 80 then
 begin
   SetWaveVolume(MakeLong(CurVol,CurVol-(100-TrackBar2.Position)*(CurVol div 100)));
   Label1.Caption:=IntToStr(100-TrackBar2.Position)+"% LEFT";
 end;
 if TrackBar2.Position >= 120 then
 begin
   SetWaveVolume(MakeLong(CurVol-(TrackBar2.Position-100)*(CurVol div 100),CurVol));
   Label1.Caption:=IntToStr(TrackBar2.Position-100)+"% RIGHT";
 end;
 if (TrackBar2.Position > 80) and (TrackBar2.Position < 120) then
 begin
   TrackBar2.Position:=100;
   SetWaveVolume(MakeLong(CurVol,CurVol));
   Label1.Caption:="CENTER";
 end;
end;

procedure TForm1.TrackBar3Change(Sender: TObject);
begin
 CurVol:=TrackBar3.Position*655;
 TrackBar2.OnChange(Self);
 Label6.Caption:=IntToStr(TrackBar3.Position)+"%";
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 BeginVol:=GetWaveVolume;
 TrackBar3.OnChange(Self);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
 SetWaveVolume(BeginVol);
end;

procedure TForm1.ListBox1Exit(Sender: TObject);
begin
 ListBox1.ItemIndex:=CurIndex;
end;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
 if abs(TrackBar1.Position-MediaPlayer1.Position)>1000 then
 begin
   MediaPlayer1.Stop;
   MediaPlayer1.Position:=TrackBar1.Position;
   MediaPlayer1.Play;
 end;
end;

end.


Если что-то не понятно - объясню.



Страницы: 1 вся ветка

Текущий архив: 2004.07.25;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.057 c
6-1085463570
ORMADA
2004-05-25 09:39
2004.07.25
посылка почты


1-1089379025
DelphiNew
2004-07-09 17:17
2004.07.25
Не раскрывается TreeView


14-1089098299
Григорьев Антон
2004-07-06 11:18
2004.07.25
Бывают же такие поэты :))


8-1084317604
MicroMozg
2004-05-12 03:20
2004.07.25
Проигрывание XM ов.


14-1088689475
KilkennyCat
2004-07-01 17:44
2004.07.25
11500 дней!