RichTextBox Line Highlight and Autoscroll with Audio

Answered RichTextBox Line Highlight and Autoscroll with Audio

  • Sunday, August 19, 2012 4:04 PM
     
     

    Hello All- I am trying to build a language tool, basically I am getting lines of text into a richtextbox and playing the audio for that line. Things are working great except that I want to highlight the text being played and autoscroll when it plays the next line.

    Here is what I am doing I have a button which gets a bunch of audio files from a folder then I get the same lines of text as in the audio from the database and dump them in the richtextbox, then the player plays those lines and the same lines are displayed in the richtextbox.

    Code:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            AxWindowsMediaPlayer1.currentPlaylist.clear()
            timerDuration.Enabled = False

            Dim oMedia As WMPLib.IWMPMedia

            Dim mp3fileName As String

            Dim d As Integer
            For d = Fromnumber to Tonumber

                mp3fileName = mp3fileName + ".mp3"

                    oMedia = AxWindowsMediaPlayer1.newMedia(folderName & "\" & mp3fileName)
                    AxWindowsMediaPlayer1.currentPlaylist.appendItem(oMedia)

                    'MsgBox(folderName)
                End If

            Next

            timerDuration.Enabled = True
            AxWindowsMediaPlayer1.Ctlcontrols.play()



    Dim mySelectQuery As String
            mySelectQuery = "SELECT * from table where (paraID = '" & ID & "')  and lines between '" & FromNumber & "' and '" & ToNumber & "'"
            Dim sqConnection As New SQLiteConnection(connString)
            Dim sqCommand As New SQLiteCommand(mySelectQuery, sqConnection)
            sqCommand.Connection.Open()
            Dim sqReader As SQLiteDataReader = sqCommand.ExecuteReader()

            ExtRichTextBox1.Clear()
            ExtRichTextBox1.SelectionIndent = 15

            If sqReader.HasRows Then
                Do While sqReader.Read()

                    ExtRichTextBox1.AppendText(sqReader.GetString(1))
                    ExtRichTextBox1.AppendText(Environment.NewLine)

                Loop

            Else
                MsgBox("No rows returned.")
            End If
            sqConnection.Close()
            sqConnection.Dispose()

        End Sub

    Then I have a timer which keeps track so to get the duration and time etc

    CODE:

    Private Sub timerDuration_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerDuration.Tick

            Dim remain, minutes As Integer ' I would just use INT's as they truncate for you
            Dim seconds, elapsedtime As String ' Ok, I see why these are strings now...

            ''Displays length of current playing track or movie.
            lblTime.Text = AxWindowsMediaPlayer1.currentMedia.durationString()

            remain = AxWindowsMediaPlayer1.currentMedia.duration - AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
            minutes = (remain \ 60).ToString("00")
            seconds = (remain Mod 60).ToString("00")
           elapsedtime = minutes & ":" & seconds

            lblDuration.Text = elapsedtime

            Dim rbt As String
            rbt = AxWindowsMediaPlayer1.currentMedia.name
            rbt = rbt.Substring(3)

            lblrbt.Text = rbt

            If AxWindowsMediaPlayer1.playState = WMPPlayState.wmppsStopped Then
                lblTime.Text = "00:00"
                lblDuration.Text = "00:00"
                timerDuration.Enabled = False
                'timerDuration.Stop()
            End If
        End Sub

    Now my question is how to highlight the text the audio is playing and autoscroll the highlight to the next line when the audio starts the next line.

    Thanks for your help guys.

All Replies