9 Replies - 657 Views - Last Post: 04 February 2016 - 02:53 PM Rate Topic: -----

#1 Omarado  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 22-September 15

Make a progress bar track the progress of the sound file play

Posted 04 February 2016 - 10:17 AM

on the same project i was working on i want to make a progress bar track the progress of the sound file play


which means the progress bar works during the play then reaches the end once the sound ends [track the progress of the sound file]


all files are in OGG format for your INFO , so please tell me how to make the progress bar do that ...


i had a problem opening the help file as the contents didn't show , so i searched Google and found the same help file but on their website i think i found that code:

Dim StreamInfo As New TStreamInfo()
player.GetStreamInfo(StreamInfo)


it is written that this code should get the stream status including the length

so to make sure i added a code to get the stream info , so the code was like that:

Dim StreamInfo As New TStreamInfo()
player.GetStreamInfo(StreamInfo)
Msgbox(Streaminfo.Tostring)


i placed that code with the [Play] button code so the sound plays and the msgbox appears with it which means the sound file has been opened and the code should get the info of the opened file

but all what i get in the msgbox is that:

" Mr_Perfect_English_Dictionary.libZPlay.TStreaminfo "

i didn't get any info about the stream

i can make the progress bar track the progress of a timer but what i am missing is the Length part , once i can get the Length i can set the timer interval to be the same as the file length and the timer starts once [Play] button is clicked but my problem is to get the Length and the code i got above doesn't show any info .....


any help would be appreciated


~thanks in advance~

This post has been edited by Omarado: 04 February 2016 - 10:18 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Make a progress bar track the progress of the sound file play

#2 TechnoBear  Icon User is offline

  • Lady A
  • member icon

Reputation: 185
  • View blog
  • Posts: 818
  • Joined: 02-November 11

Re: Make a progress bar track the progress of the sound file play

Posted 04 February 2016 - 10:23 AM

Two things:

Did IronRazer already cover this exact question for you? I feel like I saw it already, that or I am crazy.

secondly is the parameter in

player.GetStreamInfo(StreamInfo)


a referenced variable? or is that a function with a return?

and lastly, the reason you are getting " Mr_Perfect_English_Dictionary.libZPlay.TStreaminfo " is because you are calling .ToString on a class. The StreamInfo object will have properties, one of those will be related to the length of the file and potentially for current position in said audio file which may be more precise for your progress bar than the timer itself.

This post has been edited by TechnoBear: 04 February 2016 - 10:24 AM

Was This Post Helpful? 0
  • +
  • -

#3 Omarado  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 22-September 15

Re: Make a progress bar track the progress of the sound file play

Posted 04 February 2016 - 11:15 AM

for the IronRazer thing , i had a topic before this but it was removed because the admin thought i didn't do any effort so he removed it saying that you don't provide codes so i started a new one with what i have done :)/>

i got now reach this so far and the msgbox now shows the exact length of the sound file in milleseconds using that code:

Dim StreamInfo As New TStreamInfo()
        player.GetStreamInfo(StreamInfo)
        MsgBox(StreamInfo.Length.ms)


now i can get the length of the program

now i need help on how to make the progress bar track that length because after some tests i couldn't get it to track the timer

This post has been edited by andrewsw: 04 February 2016 - 12:07 PM
Reason for edit:: Removed previous quote, just press REPLY

Was This Post Helpful? 0
  • +
  • -

#4 TechnoBear  Icon User is offline

  • Lady A
  • member icon

Reputation: 185
  • View blog
  • Posts: 818
  • Joined: 02-November 11

Re: Make a progress bar track the progress of the sound file play

Posted 04 February 2016 - 12:04 PM

ProgressBar has properties too

Look at Minimum, Maximum, Step, Value, and the PerformStep() method. Here is the MSDN doc on it:

https://msdn.microso...(v=vs.110).aspx
Was This Post Helpful? 0
  • +
  • -

#5 Omarado  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 22-September 15

Re: Make a progress bar track the progress of the sound file play

Posted 04 February 2016 - 12:20 PM

i already looked at those but with no result , here's what i have done:

i added 2 timers [sdur] with interval 1 ms and another one [msdur] and its interval is the same as the sound file length [set by codes]


i named the timers [sdur] = Stream duration / [msdur] = main stream duration

now once [Play] button is clicked , the following happens:

i get the length of the stream in MS
then the progress bar maximum is set to the sound file length in MS
timer [msdur] interval is set to sound file length in MS
both timers [sdur] and [msdur] are enabled

first method:
once timer [sdur] ticks once each 1 MS , the progress bar value is increased by 1 , and if progress bar value reaches maximum this timer is disabled and the progress bar value is set back to 1

second method:
once timer [msdur] ends , both timers [msdur] and [sdur] get disabled

None of those worked at all !


these are the codes :


Play button:

Public Sub play(ByVal k As String)

        If player.OpenFile(k & ".ogg", TStreamFormat.sfOgg) = False Then
            '' error
        End If
        player.StartPlayback()
        Dim StreamInfo As New TStreamInfo()
        player.GetStreamInfo(StreamInfo)
        dur.Text = StreamInfo.Length.ms / 1000 & "  secs"
        ProgressBar1.Maximum = StreamInfo.Length.ms + 1
        msdur.Interval = StreamInfo.Length.ms + 1
        sdur.Enabled = True
        msdur.Enabled = True
    End Sub



[sdur] timer tick: [interval is set to 1 ms ]


Private Sub sdur_Tick(sender As Object, e As EventArgs) Handles sdur.Tick
        ProgressBar1.Value = ProgressBar1.Value + 1
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            sdur.Enabled = False
            ProgressBar1.Value = 1
        End If
    End Sub




[msdur] timer tick: [interval is the same at the sound file length in ms]

Private Sub msdur_Tick(sender As Object, e As EventArgs) Handles msdur.Tick
        msdur.Enabled = False
        sdur.Enabled = False

    End Sub

This post has been edited by Omarado: 04 February 2016 - 12:22 PM

Was This Post Helpful? 0
  • +
  • -

#6 TechnoBear  Icon User is offline

  • Lady A
  • member icon

Reputation: 185
  • View blog
  • Posts: 818
  • Joined: 02-November 11

Re: Make a progress bar track the progress of the sound file play

Posted 04 February 2016 - 12:46 PM

Your first method is on the right track, what is it not doing that you think it should be?
Was This Post Helpful? 0
  • +
  • -

#7 IronRazer  Icon User is offline

  • Custom Control Freak
  • member icon

Reputation: 1464
  • View blog
  • Posts: 3,712
  • Joined: 01-February 13

Re: Make a progress bar track the progress of the sound file play

Posted 04 February 2016 - 12:53 PM

The problem i see with using a timer set to 1ms intervals is that a Timer can not actually go any faster than about 20 or 30 milliseconds intervals. Not to mention a Timer is really not very accurate to begin with.

Also, depending on other programs doing things on your computer and things going on in your app the cpu may get tied up and you may very well find times that the timer may not tick for several intervals.

So, if you are trying to get an accurate reflection of progress, using a Timer in this way is not going to do it.
Was This Post Helpful? 0
  • +
  • -

#8 Omarado  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 22-September 15

Re: Make a progress bar track the progress of the sound file play

Posted 04 February 2016 - 01:01 PM

View PostTechnoBear, on 04 February 2016 - 12:46 PM, said:

Your first method is on the right track, what is it not doing that you think it should be?



TechnoBear , when i used the first method , the progress bar advances too slow which means the sound file is played and finishes and the progress bar doesn't even reach the half but if i wait for it , it will reach the end and reset back but that isn't what i want

i want the progress bar to go right with the file ...

and IronRazer , if using a timer with 1 ms won't do it , what else should i do to get this working?

please NOTE that all the sound files are 5 seconds and shorter , most of them are 2 seconds and shorter and some are less than a second .
Was This Post Helpful? 0
  • +
  • -

#9 IronRazer  Icon User is offline

  • Custom Control Freak
  • member icon

Reputation: 1464
  • View blog
  • Posts: 3,712
  • Joined: 01-February 13

Re: Make a progress bar track the progress of the sound file play

Posted 04 February 2016 - 01:30 PM

Just to add, i have tried setting the ProgressBar.Maximum to the length in milliseconds of the stream and then using a timer tick event to set the ProgressBar.Value to the current position of the stream time in milliseconds and it appears there is something screwy going on with this method.

I am not sure if it is the length of time it takes to execute the GetPosition method in the tick event or what exactly but, it would not update or show any progress in the ProgressBar until well after the file was started and did nor reflect an accurate reflection of the current time of the file.

Being this is the first i have ever tried LibZPlay and i am really not familiar with using it, there may be something i am not aware of or maybe you would have better luck setting the value of the progressbar from the CallBack function somehow.

Have you tried asking the Author of the LibZPlay library? That may be the best thing to try since he wrote it and would know how it should be done.

This post has been edited by IronRazer: 04 February 2016 - 01:32 PM

Was This Post Helpful? 0
  • +
  • -

#10 Omarado  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 22-September 15

Re: Make a progress bar track the progress of the sound file play

Posted 04 February 2016 - 02:53 PM

Happily ,i solved my problem in a strange way but it worked at the end :D/> :)/>

here's my whole form1 code to understand what i have done:


Imports Mr_Perfect_English_Dictionary.libZPlay

Public Class Form1test
    Dim player As New ZPlay
    Dim ln2 As Long
    Public Sub play(ByVal k As String)

        If player.OpenFile(k & ".ogg", TStreamFormat.sfOgg) = False Then
            '' error
        End If

        Dim StreamInfo As New TStreamInfo()
        player.GetStreamInfo(StreamInfo)
        Dim ln As Long = StreamInfo.Length.ms
        Dim ln1 As Long
        ln1 = ln / 4
        sdur.Interval = ln1
        sdur2.Interval = ln1
        sdur3.Interval = ln1
        sdur4.Interval = ln1
        ln2 = ln1
        dur.Text = StreamInfo.Length.ms / 1000 & "  secs"
        ProgressBar1.Maximum = StreamInfo.Length.ms
        msdur.Interval = StreamInfo.Length.ms + 1
        sdur.Enabled = True
        player.StartPlayback()

    End Sub
    Public Sub view(ByVal v As String)
        info.Text = v
    End Sub
    Public Sub art(ByVal a As String)
        arat.Text = a
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Select Case words.SelectedIndex
            Case 0
                play("aback")
                view("/əbk/ adv taken aback surprised and shocked by something unpleasant , She was somewhat taken aback when he told her there was no train that evening.")
                art("فوجئ")
            Case 1
                play("abacus")
                view("/bəkəs/ nounan object used forcounting, consisting of a frame with ball swhich can be moved on bars")
                art("طبلية تاج")
            Case 2
                play("abandon")
                view("/əbndən/ verb 1.to leave someone or something without help The crew abandoned the sinking boat.Synonym" & vbCrLf & "to give up or stop doing something , The company has decided to abandon the project.We abandoned the idea of setting up a London office.")
                art("التخلي عن")
            Case 3
                play("abandoned")
                view("/əbndənd/ adj no longer used or lived in")
                art("غير مأهولة")
            Case 4
                play("abandonment")
                view("/əbndənmənt/ noun1. the act or process of giving someone or something up  2.the act or process of leaving someone or something without help. Synonymdesertion")
                art("هجر")
            Case 5
                play("abashed")
                view("/əbʃt/ adj ashamed or embarrassed ")
                art("خجول")
            Case 6
                play("abate")
                view("/əbet/verbto become less strong or forceful(formal.).Synonymdecrease")
                art("انحسر")
            Case 7
                play("abattoir")
                view("/bətwɑ	/ nouna place where animals are killed for meat. Synonym slaughterhouse ")
                art("مسلخ مجزر")
            Case 8
                play("abbey")
                view("/bi/ noun1.a place where a community of Christian monks or nuns live2.a large churchWestminister Abbey")
                art("دير")
            Case 9
                play("abbreviate")
                view("/əbri	viet/ verb1.to shorten a word by leaving out some of the letters2.to shorten a piece of writing by leaving out part of it. Synonymcut")
                art("اختصر")
            Case 10
                play("abbreviated")
                view("/əbri	vietd/ adjshortened by having something left out")
                art("مختصر")
            Case 11
                play("abbreviation")
                view("/əbri	vieʃ(ə)n/ noun a shortened form of a word. Compare acronym ")
                art("الاختصار")
            Case 12
                play("abdicate")
                view("/bdket/ verbto give up the position as king or queen of a country")
                art("التنازل عن العرش")
            Case 13
                play("abdication")
                view("/bdkeʃ(ə)n/ nounthe act of giving up the position of king or queen of a country")
                art("التنازل")
            Case 14
                play("abdomen")
                view("/bdəmən/ nounthe space in the front part of your body, containing the stomach and other organs")
                art("البطن")
            Case 15
                play("abdominal")
                view("/bdɒmn(ə)l/ adjreferring to the abdomen")
                art("البطن")
            Case 16
                play("abduct")
                view("/bdkt/ verb to take someone away, usually by force. Synonymkidnap")
                art("خطف")
            Case 17
                play("abduction")
                view("/bdkʃən/ nounthe act of taking someone away, usually by force. Synonymkidnap")
                art("اختطاف")
            Case 18
                play("aberrant")
                view("/berənt/ adjnot usual or as expected(formal.). Synonym abnormal. Antonymnormal")
                art("شاذ أو غير طبيعي")
            Case 19
                play("aberration")
                view("/bəreʃ(ə)n/ nounan action or thing which is not usual or expected. Synonymabnormality")
                art("انحراف")
            Case 20
                play("abet")
                view("/əbet/ verb to encourage or help someone to do something wrong or illegal (formal.)aid(NOTE:abetting – abetted)")
                art("يحرض")
            Case 21
                play("abhorrence")
                view("/əbhɒrəns/ nouna feeling of hatred or horror(formal.)")
                art("اشمئزاز")
            Case 22
                play("abhorrent")
                view("/əbhɒrənt/ adjhorrible or disgusting(formal.)")
                art("بغيض")
            Case 23
                play("abide")
                view("/əbad/ verb to abide by to follow rules or customs You must abide by the rules of the game.We have to abide by the decision of the referee. to abide by a promiseto keep a promise")
                art("الالتزام")
            Case 24
                play("abiding")
                view("/əbadŋ/ adjlasting a long time (formal.). Synonym enduring. Antonym transient ")
                art("مستمر")





        End Select
        If words.SelectedIndex = Nothing Then
        Else
            wc.Visible = False
        End If
        ProgressBar1.Value = 0
    End Sub

    Private Sub words_SelectedIndexChanged(sender As Object, e As EventArgs) Handles words.SelectedIndexChanged
        wc.Visible = True
    End Sub

   

    Private Sub sdur_Tick(sender As Object, e As EventArgs) Handles sdur.Tick


        ProgressBar1.Value = ProgressBar1.Value + ln2
        sdur.Enabled = False
        sdur2.Enabled = True


        If ProgressBar1.Value = ProgressBar1.Maximum Then
            sdur.Enabled = False
            ProgressBar1.Value = 1
        End If
    End Sub

    

    Private Sub sdur2_Tick(sender As Object, e As EventArgs) Handles sdur2.Tick
        ProgressBar1.Value = ProgressBar1.Value + ln2
        sdur2.Enabled = False
        sdur3.Enabled = True
    End Sub

    Private Sub sdur3_Tick(sender As Object, e As EventArgs) Handles sdur3.Tick
        ProgressBar1.Value = ProgressBar1.Value + ln2
        sdur3.Enabled = False
        sdur4.Enabled = True
    End Sub

    Private Sub sdur4_Tick(sender As Object, e As EventArgs) Handles sdur4.Tick
        ProgressBar1.Value = ProgressBar1.Value + ln2
        sdur4.Enabled = False

    End Sub
End Class


at last what i have done is the following:

Since timers may not work properly if they are set to 1 ms so i decided to use 4 timers to make that progress bar work !!!

i canceled timer [msdur] and had 4 timers who are [sdur] , [sdur2] , [sdur3] , [sdur4]

the progress bar maximum value is the sound file length

as you see in the SUB [play] i have a variable which gets the length oh the sound file divided by 4 and as you see each timer's interval of those 4 gets the sound file length divided by 4 ...

when play button is clicked the first timer starts and after it ends it add a value to the progress bar equal to the length of the sound file divided by 4

when the 1st timer ends it enables the 2nd timer and when the 2nd one ends the 3rd one starts and so on till the 4th one comes , each timer adds the same value to the progress bar which is equal to the sound file length divided by 4 and the adds the last value to the progress bar making it reach its maximum then once [Play] is clicked again the progress bar value is reset back to 0 and the same happens again

in this code i avoided the 1 ms timer thing and made the progress bar advance on 4 steps only instead of 1000 steps and more [1000 steps because of the 1 ms timer ] and now the program works smoothly and ends right with the sound file

if you didn't understand a word from what i said , just read the code and i think you will understand everything :)/>

i hope someone else after me finds this helpful , and tell what do you think of this trick i made in the code ?!?!?!?!?!

This post has been edited by Omarado: 04 February 2016 - 02:58 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1