mediaplayer的length 如何轉化為時間 HMS |
尚未結案
|
elctppo
一般會員 ![]() ![]() 發表:28 回覆:22 積分:10 註冊:2005-04-01 發送簡訊給我 |
這是我在help看到的example ...
type HMSRec = record
Hours: byte;
Minutes: byte;
Seconds: byte;
NotUsed: byte; end;//我不明白上面這些是什麼還有應該放在哪裡
也不明白下面是如何使用上面這些的,將timeformat改成tfhms後,
跟上面那些變數類型 byte 又有什麼關係呢 ?
謝謝各位=== procedure TForm1.Button1Click(Sender: TObject); var
TheLength: LongInt;
begin
{ Set time format - note that some devices don急 support tfHMS }
MediaPlayer1.TimeFormat := tfHMS;
{ Store length of currently loaded media in var }
TheLength := MediaPlayer1.Length;
with HMSRec(TheLength) do { Typecast TheLength as a HMSRec record }
begin
Label1.Caption := IntToStr(Hours); { Display Hours in Label1 }
Label2.Caption := IntToStr(Minutes); { Display Minutes in Label2 } Label3.Caption := IntToStr(Seconds); { Display Seconds in Label3 }
end;
end; 如果大大有更好的方法==謝謝指點 http://www.mezone.net
|
Fishman
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi elctppo, 試試這樣:
procedure TMedia_Player.Button1Click(Sender: TObject); var Media_Length : Integer; TOTAL_TIME : String; begin Media_Length := Round(MediaPlayer1.Length / 1000); TOTAL_TIME := FormatFloat('00' , Trunc(Media_Length / 3600)) ':' FormatFloat('00' , Trunc(Media_Length / 60)) ':' FormatFloat('00' , Media_Length MOD 60); Showmessage(TOTAL_TIME); end;
------
Fishman |
elctppo
一般會員 ![]() ![]() 發表:28 回覆:22 積分:10 註冊:2005-04-01 發送簡訊給我 |
引言: Hi elctppo, 試試這樣:procedure TMedia_Player.Button1Click(Sender: TObject); var Media_Length : Integer; TOTAL_TIME : String; begin Media_Length := Round(MediaPlayer1.Length / 1000); TOTAL_TIME := FormatFloat('00' , Trunc(Media_Length / 3600)) ':' FormatFloat('00' , Trunc(Media_Length / 60)) ':' FormatFloat('00' , Media_Length MOD 60); Showmessage(TOTAL_TIME); end; |
elctppo
一般會員 ![]() ![]() 發表:28 回覆:22 積分:10 註冊:2005-04-01 發送簡訊給我 |
|
Fishman
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi elctppo, 謝謝你的指教,一時筆誤,已更正如下:
procedure TMedia_Player.Button1Click(Sender: TObject); var Media_Length : Integer; TOTAL_TIME : String; begin Media_Length := Round(MediaPlayer1.Length / 1000); TOTAL_TIME := FormatFloat('00' , Trunc(Media_Length / 3600)) ':' FormatFloat('00' , (Trunc(Media_Length / 60)) MOD 60) ':' FormatFloat('00' , Media_Length MOD 60); Showmessage(TOTAL_TIME); end;其中 Media_Length 即為 Media 長度,單位為秒,詳細轉換方式與原則可參考 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=78917 FormatFloat : 將數值轉換回文字字串並且補上前置零用 Trunc : 取整數
------
Fishman |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |