大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 程序开发 -> DELPHI实现文本文件显示和声音同步播放

DELPHI实现文本文件显示和声音同步播放

时间: 2021-07-31 作者:daque

朱群生 ---- 在少许谈话熏陶软硬件中,常常运用文本表露和声响同步播放,咱们不妨用del phi实行之。  ---- 一、资料的创造  ---- 开始,咱们采用几篇作品,这边咱们采用马丁路德金、林肯和里根的演说,每一篇作品分为几何句,在创造声响文献时,记下每个句子的发端功夫和中断功夫,而后将其记到一个数据表中,这个表犹如下字段:no、text、starttime,辨别表白每句序号、实质、发端功夫。  ---- 二、 界面包车型的士创造  ---- 在delphi中创造一个新工程,在form中放入多媒介控件,rtf编纂器,吩咐按钮,单选分批框,数据表,时钟和标签,如图所示  ---- 三、各个控件的属性  ---- 1、 多媒介控件的autoenable和autoopen个性树立为false ,visiblebuttons个性树立record、eject、step为不看来。  ---- 2、 table控件的databasename设为寄存表的目次,咱们将运用步调、声响文献和表寄存在myprog目次,所以这边将databasename设为c:\myprog,将tablename设为默许的播放文献对应的数据表的名字,这边设为ex1.dbf。  ---- 3、 radiogroup控件的caption设为 ‘请采用播放实质’,itmes个性中加上三行:马丁路德金,林肯,里根。  ---- 4、 richedit控件的lines个性加上‘报告实质。  ---- 四、代码的编写  ---- 1、变量证明  var isend:boolean; currentbutton:tmpbtntype; currentplay,currentdisp:longint; ---- 个中isend表白播放能否仍旧到了结束,currentbutton表白暂时mediaplayer元件中按下了哪个按钮,currentplay ,currentdisp表白暂时播放记载及暂时表露记载。  ---- 2、在formcreate事变中做少许需要的筹备处事,其代码如次:  procedure tform1.formcreate(sender: tobject); begin table1.tablename:='ex1.dbf'; table1.open; mediaplayer1.filename:='ex1.wav';mediaplayer1.open;      mediaplayer1.timeformat:=tfmilliseconds; isend:=false; currentbutton:=btstop; currentdisp:=1; currentplay:=1; end; ---- 3、在单选分批框中加进如次代码:  procedure tform1.radiogroup1click(sender: tobject); begin mediaplayer1.close; table1.close; case radiogroup1.itemindex of 0:begin mediaplayer1.filename:='ex1.wav';     table1.tablename:='ex1.dbf';end; 1:begin mediaplayer1.filename:='ex2.wav';     table1.tablename:='ex2.dbf';end; 2:begin mediaplayer1.filename:='ex3.wav';     table1.tablename:='ex3.dbf'; end; end; table1.open; mediaplayer1.open; end;      ---- 4、为了符合窜改mediaplayer元件中各个按钮的功效,须要编写mediaplayer元件的click事变的代码,主假如窜改“快进”及“快退”的功效,使其历次挪动一句,且挪动后径直播放,而不必再按“播放”按钮。为到达这个功效,在进程的一发端,树立dodefault参数为false,表白不实行默许的举措,在进程的中央局部,加上需要的处置,在进程的中断处,写上按照按下的按钮实行相映功效语句。  procedure tform1.mediaplayer1click(sender: tobject; button: tmpbtntype; var dodefault: boolean); begin dodefault:=false; with mediaplayer1 do begin case button of btplay : begin if isend=true then begin table1.first; position:=start; currentplay:=1; currentdisp:=1; isend:=false; richedit1.lines.clear; richedit1.lines.add     ('报告实质'); end; currentbutton:=btplay; end; btstop : begin currentbutton:=btstop;  isend:=true;     end; btpause: if currentbutton=btplay then currentbutton:=btpause else if currentbutton=btpause then currentbutton:=btplay; btprev: begin currentbutton:=btprev;  table1.prior; position:=table1.fieldvalues ['starttime']; currentbutton:=btplay; end; btback: begin currentbutton:=btback; table1.first; position:=start;  currentplay:=1;      currentdisp:=1; richedit1.lines.clear; richedit1.lines.add     ('报告实质'); currentbutton:=btplay; end; btnext: begin currentbutton:=btnext;  table1.next; position:=table1.fieldvalues ['starttime']; currentbutton:=btplay; end; end; case currentbutton of btplay: play; btpause:pause; btstop:stop; end; end; end;      ---- 5、为了能同步表露文本,须要编写准时器ontime事变的代码,即使暂时播放的功夫胜过了暂时记载的发端功夫,则树立currentplay为暂时记载号,即使currentplay胜过了currentdisp ,则表露暂时记载。  procedure tform1.timer1timer(sender: tobject); begin with mediaplayer1 do  begin if currentbutton=btplay then begin if not table1.eof and (position     >table1.fieldvalues['starttime']) then  begin currentplay:=table1.recno; if currentplay >=currentdisp then begin richedit1.lines.add(table1.fieldvalues['text']); currentdisp:=currentdisp+1; end; table1.next; end; if table1.eof then begin currentbutton:=btstop; isend:=true; end; end; end; end; ---- 注:在mediaplayer的click事变中,运用了btprev,btnext等恒量,为了不妨经过编写翻译,在uses子句中需将comctrls放在mplayer之前,免得惹起辩论。

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.