Delphi程序的設(shè)計(jì)及實(shí)驗(yàn)指導(dǎo)第1章_第1頁
Delphi程序的設(shè)計(jì)及實(shí)驗(yàn)指導(dǎo)第1章_第2頁
Delphi程序的設(shè)計(jì)及實(shí)驗(yàn)指導(dǎo)第1章_第3頁
Delphi程序的設(shè)計(jì)及實(shí)驗(yàn)指導(dǎo)第1章_第4頁
Delphi程序的設(shè)計(jì)及實(shí)驗(yàn)指導(dǎo)第1章_第5頁
已閱讀5頁,還剩26頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、第十一章第十一章 多媒體編程多媒體編程 11.1 動畫組件tanimate 11.2 簡單的動畫播放程序的設(shè)計(jì) 11.3 簡單的cd播放器的制作 1用途 2主要屬性 【例11-1】使用tanimate組件設(shè)計(jì)一個簡單的動畫播放程序。 11.1.2 媒體播放器組件tmediaplayer 2主要屬性 【例11-2】使用tmediaplayer組件編寫一個簡單的avi文件播放器程序。 為了更好地理解tanimate組件的屬性、方法和事件,這一節(jié)創(chuàng)建一個簡單的動畫播放程序。通過實(shí)例3,更好地掌握tanimate組件的應(yīng)用以及多媒體程序的設(shè)計(jì)思路。 11.2.1 界面設(shè)計(jì) 11.2.2 代碼編寫 1定

2、義存放起始幀、結(jié)束幀、循環(huán)次數(shù)和總幀數(shù) var form1: tform1; startframe,stopframe,repeatframe,sumframe:integer; 2tanimate1組件的onopen事件處理程序代碼 procedure tform1.animate1open(sender: tobject); begin showmessage(tanimaet組件觸發(fā)onopen事件,初始化變量!); (*初始化變量*) startframe:=animate1.startframe; stopframe:=animate1.stopframe; repeatframe:

3、=animate1.repetitions; sumframe:=animate1.framecount; estartframe.text:=inttostr(startframe); estopframe.text:=inttostr(stopframe); esumframe.text:=inttostr(sumframe); erepeatframe.text:=inttostr(repeatframe); end; 3“開始播放”按鈕的onclick事件處理程序代碼 procedure tform1.playclick(sender: tobject); begin startfra

4、me:=strtoint(estartframe.text); stopframe:=strtoint(estopframe.text); repeatframe:=strtoint(erepeatframe.text); (*驗(yàn)證動畫屬性設(shè)置編輯框的數(shù)據(jù)合法性*) if (startframestopframe) or(stopframesumframe) then begin /輸入范圍錯誤 showmessage(輸入幀的范圍錯誤,所有設(shè)置復(fù)位!); animate1.startframe:=1; animate1.stopframe:=animate1.framecount; anim

5、ate1.repetitions:=0; estartframe.text:=1; estopframe.text:=inttostr(animate1.framecount); erepeatframe.text:=0; end else begin (*設(shè)置組件的enabled屬性*) play.enabled:=false; stop.enabled:=true; estartframe.enabled:=false; estopframe.enabled:=false; erepeatframe.enabled:=false; (*設(shè)置tanimate組件的屬性,然后進(jìn)行播放*) an

6、imate1.startframe:=startframe; animate1.stopframe:=stopframe; animate1.repetitions:=repeatframe; animate1.active:=true; /進(jìn)入播放狀態(tài) end; end; 4“停止播放”按鈕的onclick事件的處理程序代碼 procedure tform1.stopclick(sender: tobject); begin (*停止播放*) animate1.stop; play.enabled:=true; /“開始播放”按鈕可用 stop.enabled:=false; (*設(shè)置文本框

7、為可用*) estartframe.enabled:=true; estopframe.enabled:=true; erepeatframe.enabled:=true; end; 運(yùn)行程序,在estopframe文本框中輸入結(jié)束幀為9,單擊“開始播放”按鈕,結(jié)果如圖11-7所示。 圖11-7 運(yùn)行結(jié)果11.3 簡單的簡單的cd播放器的制作播放器的制作 11.3.1 界面設(shè)計(jì) 11.3 簡單的簡單的cd播放器的制作播放器的制作圖11-8 cd播放器的界面11.3 簡單的簡單的cd播放器的制作播放器的制作 11.3.2 代碼編寫11.3 簡單的簡單的cd播放器的制作播放器的制作 2按鈕的onc

8、lick事件處理程序代碼 procedure tform1.button1click(sender: tobject); begin mediaplayer1.play; /“播放”按鈕的onclick事件處理 end; procedure tform1.button3click(sender: tobject); begin mediaplayer1.pause; /“暫?!卑粹o的onclick事件處理 end;11.3 簡單的簡單的cd播放器的制作播放器的制作procedure tform1.button2click(sender: tobject);beginmediaplayer1.s

9、top;滯不前 /“停止”按鈕的onclick事件處理end;procedure tform1.button4click(sender: tobject);beginmediaplayer1.previous; /“前一曲”按鈕的onclick事件處理end;procedure tform1.button6click(sender: tobject);beginmediaplayer1.next; /“后一曲”按鈕的onclick事件處理end;procedure tform1.button7click(sender: tobject);beginmediaplayer1.eject;勤部 /

10、“彈出”按鈕的onclick事件處理end;11.3 簡單的簡單的cd播放器的制作播放器的制作 (*“打開”按鈕的onclick事件處理*) procedure tform1.button5click(sender: tobject); begin if opendialog1.execute then begin mediaplayer1.filename:=opendialog1.filename; mediaplayer1.open; end; end;11.3 簡單的簡單的cd播放器的制作播放器的制作 3timer1組件的timer1timer事件處理程序代碼 窗體中的timer組件的

11、作用是為程序的運(yùn)行提供事件的控制,例如顯示cd播放的當(dāng)前位置、狀態(tài)等信息。這里利用memo組件顯示相關(guān)的信息。 procedure tform1.timer1timer(sender: tobject); var i,j,k:integer; pos1,pos2:longint; flag:boolean; str1:string;11.3 簡單的簡單的cd播放器的制作播放器的制作 begin memo1.lines0:=總曲目數(shù):+inttostr(mediaplayer1.tracks); mediaplayer1.timeformat:=tfmilliseconds; pos1:=0;

12、pos2:=0; flag:=true; for i:=0 to mediaplayer1.tracks-1 do /顯示正在播放的第幾首曲目 begin for j:=0 to i-1 do begin pos1:=pos1+mediaplayer1.tracklengthj; pos2:=pos1; end;11.3 簡單的簡單的cd播放器的制作播放器的制作 pos2:=pos2+mediaplayer1.tracklengthi; if mediaplayer1.positionpos1 then begin if mediaplayer1.positionpos2 then begin

13、 memo1.lines1:=正在播放的曲目:第 +inttostr(i+1)+ 首; flag:=false; end; end; end; 11.3 簡單的簡單的cd播放器的制作播放器的制作if flag then memo1.lines1:=正在播放的曲目:第 1 首; k:=round(mediaplayer1.length/60000); memo1.lines2:=曲目長度:+inttostr(k); str1:=當(dāng)前狀態(tài): ;(*顯示cd播放的當(dāng)前狀態(tài)*) case mediaplayer1.mode of mpnotready: memo1.lines3:=str1+準(zhǔn)備未緒; mpstopped: memo1.lines3:=str1+已停止; mpplaying: memo1.lines3:=str1+正在播放; mprecording: memo1.lines3:=str1+正在記錄; mpseeking: memo1.lines3

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論