repeating audio file playback

Questions regarding syntax

Re: repeating audio file playback

Postby EasyCoder » Wed Nov 30, 2011 5:57 pm

Henning wrote:@EasyCoder

If your app is supposed to respond, never use Sleep. Sleep does exactly what it says, puts your app to sleep. Use DoEvents in tight loops to allow other parts of the app to do anything.

Did you try the Event? Sub xx_OnFinished ().

/Henning


The problem isn't checking if the file has finished playing. If you want to restart playback it seems to want a certain amount of time to start to play. Adding any command after the play() function will cause it stop working unless you sleep first.

xx.play(file)
sleep 1
command

Without the sleep above the file wont play. It's possible it only requires 10mS to start playback, but I cannot tell because the minimum delay time with the sleep function is 1 second. I really don't know why you can't set the delay in mS for the sleep function.

berndnoetscher, can I load a Kbasic project into Q7basic without changes ? It took me long time to transfer a VB6 project to Kbasic and I don't want to have to go through that pain again.

I was going to buy a license key, but until I am sure I can create the app that I want I am still holding off.

Regards,
EasyCoder.
EasyCoder
 
Posts: 13
Joined: Tue Nov 22, 2011 7:09 pm

Re: repeating audio file playback

Postby Henning » Wed Nov 30, 2011 6:24 pm


xx.play(file)
sleep 1
command


What if you change sleep 1 to DoEvents?

/Henning
Henning
 
Posts: 262
Joined: Mon Feb 09, 2009 12:03 am
Location: Sweden

Re: repeating audio file playback

Postby EasyCoder » Wed Nov 30, 2011 7:35 pm

Henning wrote:

xx.play(file)
sleep 1
command


What if you change sleep 1 to DoEvents?

/Henning


I tried that and it does not work either.

Regards,
EasyCoder.
EasyCoder
 
Posts: 13
Joined: Tue Nov 22, 2011 7:09 pm

Re: repeating audio file playback

Postby Henning » Wed Nov 30, 2011 8:46 pm

What is command representing?

/Henning
Henning
 
Posts: 262
Joined: Mon Feb 09, 2009 12:03 am
Location: Sweden

Re: repeating audio file playback

Postby EasyCoder » Wed Nov 30, 2011 11:17 pm

Henning wrote:What is command representing?

/Henning


It could be any command. Incrementing a counter in a while loop for example.

Regards,
EasyCoder.
EasyCoder
 
Posts: 13
Joined: Tue Nov 22, 2011 7:09 pm

Re: repeating audio file playback

Postby Slowdown » Thu Dec 01, 2011 7:47 am

tested, experimental code,
Code: Select all
Private Sub Form_OnOpen()
  Dim NoEnd As Boolean
   
  Sound1.Load("d:\Tempory\tone.mp3")
  Sound1.Play("d:\tempory\tone.mp3")
  MyTicks()
  NoEnd = False
  Do
    DoEvents()
    If Sound1.IsPlaying = False Then
      Sound1.Stop()
      Sound1.Play("d:\tempory\tone.mp3")
    End If
  Loop While NoEnd=False
End Sub

Sub MyTicks()
  Dim Lus As Integer
  For Lus = 1 to 500
    DoEvents()
  Next
End Sub 

Works here but as i said experimental.
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: repeating audio file playback

Postby berndnoetscher » Thu Dec 01, 2011 7:56 am

EasyCoder wrote:
Henning wrote:@EasyCoder

If your app is supposed to respond, never use Sleep. Sleep does exactly what it says, puts your app to sleep. Use DoEvents in tight loops to allow other parts of the app to do anything.

Did you try the Event? Sub xx_OnFinished ().

/Henning


The problem isn't checking if the file has finished playing. If you want to restart playback it seems to want a certain amount of time to start to play. Adding any command after the play() function will cause it stop working unless you sleep first.

xx.play(file)
sleep 1
command

Without the sleep above the file wont play. It's possible it only requires 10mS to start playback, but I cannot tell because the minimum delay time with the sleep function is 1 second. I really don't know why you can't set the delay in mS for the sleep function.

berndnoetscher, can I load a Kbasic project into Q7basic without changes ? It took me long time to transfer a VB6 project to Kbasic and I don't want to have to go through that pain again.

I was going to buy a license key, but until I am sure I can create the app that I want I am still holding off.

Regards,
EasyCoder.


q7basic does not contain kbasic form designer yet, but supports Qt designer.
The language part is nearly kbasic right now. q7basic is supposed to have all features of kbasic within the next months.
I would give it a try, if I were you.
berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

Re: repeating audio file playback

Postby Slowdown » Thu Dec 01, 2011 8:54 am

Hi EasyCoder,
Was a bit in a hurry this morning but,
Without the sleep above the file wont play. It's possible it only requires 10mS to start playback, but I cannot tell because the minimum delay time with the sleep function is 1 second. I really don't know why you can't set the delay in mS for the sleep function.

As you see in my small example i don't use sleep and for the reason Henning mentioned in his post.
I would give it a try, if I were you.

He's right, just try it.
Qt designer is easy to work with but sadly for you you cant 'just' import the pressent KBasic project into Q7B.
But in my opinion Q7B will be better than KBasic.
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: repeating audio file playback

Postby EasyCoder » Thu Dec 01, 2011 11:05 pm

Thanks for the code snippet slowdown. However, it still wont work unless I insert Sleep after Play().
It could be a problem with my system or winxp, I just don't know.

Are you using the linux or mac version of Kbasic ? could be something to do with audio implementation on windows.


It took a long time and head banging to get the Kbasic version of my program looking and functioning the same as the VB6 version, I don't want to have to go through that again with Q7basic. From what I can tell Q7basic is still not ready for release and is missing features from Kbasic.

Regards,
EasyCoder.
EasyCoder
 
Posts: 13
Joined: Tue Nov 22, 2011 7:09 pm

Re: repeating audio file playback

Postby Henning » Fri Dec 02, 2011 1:27 am

If it is to any comfort, on my computer (WinXP) it doesn't play with or without Sleep...

/Henning
Henning
 
Posts: 262
Joined: Mon Feb 09, 2009 12:03 am
Location: Sweden

PreviousNext

Return to Coding Questions

cron