English has gradually become a global language, and modern people's enthusiasm for learning English has increased. Therefore, English repeaters are very popular. However, no matter how powerful the repeater is, there is an obvious flaw - the fixed repeat time. If the rereading time is too short, then there is nothing you can do when encountering long sentences; if the rereading time is very long, you will inevitably have to reread some redundant parts and fast-forward (some 200-second rereading machines nowadays have a fast-forward function). ), which is as troublesome as fast forwarding the tape! Therefore, the author wants to use Delphi's powerful media playback control to develop a software repeater. The biggest advantage of the software repeater is that you can repeat it freely regardless of the length of the sentence! Absolutely no need to rewind or fast forward. Not only that, the software repeater also has a random reading function, which is difficult to achieve with ordinary repeaters.
Preparation
Delphi's media playback control can play various sound files. We can record the learning materials into the computer according to our own preferences and save them in a suitable format. Generally, it can be saved as wave file or mp3 file.
Development of repeater
The software repeater developed mainly uses Delphi's media playback control TMediaplayer. This control is in the system control (system) page.
First create an application. Set the BorderStyle of the main form to BsDialog to disable the magnification and reduction of the form. Set KeyPReview to True to let the main form handle keyboard events.
Place controls on the main form:
in:
The media player is the key control of the program and is used to play sounds.
TrackBar is used to indicate the current playback progress.
The TlistBox (SectionList) on the left is used to store the name of the sound file to be played (learning materials).
The two TlistBoxes (StartList, StopList) on the right are used to record the repeated sentences.
'Add' and 'Delete' buttons are used to maintain learning materials.
TrackBar1 is used to display the playback process.
Timer1 is used to dynamically display the playback progress.
OpenDialog1 is used to select files to play.
Implementation of repeat function:
① Set two integers (StartPos, SstopPos) in the program to record the start and end points of playback, and set StopPos to -1 during initialization.
② Record the starting value each time it is played: StartPos := Mediaplayer1.Position;
③ In the program, use the space bar to control repeating and the Enter key to continue playback. First, set the KeyPreview of the main form to True so that the main form can intercept key messages. Then, overload the OnKeyDown method. The code is as follows:
Implementation of free reading function:
Since the starting and ending points of all repeated sentences are recorded during rereading, any sentence can be reread. When the user double-clicks a line in 'Past Years' with the mouse, the user can directly switch to the playback of that sentence. The code is as follows:
procedure TRepeaterForm.ListDblClick(Sender: TObject);
begin
SID := (Sender as TListBox).ItemIndex; //Get the index of the current row
SID StopList.ItemIndex := SID; //Set the end point list to
SID StartList.ItemIndex := SID; //Set the starting list to
SID StartPos := StrToInt(StartList.Items[SID]);//Get the starting position
StopPos := StrToInt(StopList.Items[SID]);//Get the end position
Mediaplayer1.StoP; //Stop the current playback
Mediaplayer1.StartPos := StartPos; //Set a new playback range
Mediaplayer1.EndPos := StopPos;
Mediaplayer1.Play; //Play the sound in the specified range
end;
Addition of learning materials:
Click the Add button to add learning materials. It should be noted that the original list should be retrieved before adding new files to prevent duplication. The code is as follows:
procedure TRepeaterForm.AddBtnClick(Sender: TObject);
var fn: string;
begin
if OpenDialog1.Execute then
begin
fn := OpenDialog1.FileName;
if SectionList.Items.IndexOf(fn)<0 then //Retrieve the file first, if it does not exist SectionList.Items.Add(fn); //Add to the list
end;
end;
Selection of study materials:
Achieved by overloading the OnClick method. First get the index when clicked, and then get the file name through Items [index]. Assign the file name to the Filename property of Mediaplayer and then call the Open method. (code omitted)
In addition, the learning material file should be opened when the program is initialized; the learning material should be saved when the program exits. These functions are implemented through TlistBox.Items.LoadFromFile and TlistBox.Items.SaveToFile (code omitted).
The program passed debugging in the Chinese Windows98+Delphi5.0 environment. All source code can be obtained by mailing the author.