Buscar

Converter position (mediaplayer) para hh:mm:ss

Código

Esta é uma função que converte o Position do componente MediaPlayer que tem no Delphi 6 (nas outras versões eu não testei) para HH:MM:SS.
Vale ressaltar que não foi feito todos os testes para verificar bug's. Mas basicamente funciona. Ela ainda pode ser melhorada.
Bom, espero que seja útil. Ainda sou aprendiz no delphi!

function PositionToTime( pos: integer ): string;
var
  str : string[20];
  aux : integer;
  hh,mm,ss: byte;
begin
  //Inicializando variáveis
  hh := 0;
  mm := 0;
  ss := 0;
  str := inttoStr( pos );
  str := copy(str, 1, length(str)-3);
  pos := strToInt( str );

  //Colocando horas
  if (pos div 3600) > 0 then
  begin
    hh := pos div 3600;
  end;

  //Colocando Minutos
  if (pos div 60) > 0 then
  begin
    if hh > 0 then
    begin
      aux := 3600 * hh;
      pos := pos - aux;
    end;
    mm := pos div 60;
    if mm > 59 then
      mm := 0;
  end;

  //Colocando segundos
  if pos > 59 then
  begin
    if mm > 0 then
    begin
      aux := 60 * mm;
      ss := pos - aux;
    end;
  end else ss := pos;

  //Acrescentando 00
  if hh < 10  then
    str := '
0'+intToStr(hh)+':'
  else str := intToStr(hh)+'
:';

  if mm < 10 then
    str := str+'
0'+intToStr(mm)+':'
  else str := str+intToStr(mm)+'
:';

  if ss < 10 then
    str := str+'
0'+intToStr(ss)
  else str := str+intToStr(ss);

  PositionToTime := str;
end;

Publicidade

Vote na dica




Quantidade de votos: 0 votos
Aceitação: 0%


Detalhes da dica

Categoria: Multimedia
Adicionada dia: 13/10/04
Por: Bruno Oliveira
Visualizada: 3205 vezes

Planeta Delphi - Tudo sobre programação Delphi Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009