repeating audio file playback

Questions regarding syntax

repeating audio file playback

Postby EasyCoder » Tue Nov 22, 2011 7:18 pm

Hi,

I have been tinkering with Kbasic for a few months now having used VB6 before and now and some questions.

Is it possible to repeat playback of an audio file automatically (wave or mp3) after the file ends and repeat forever?

I have the Windows version of Kbasic. If I purchase a key, will I then be able to compile a mac & linux version as well as a windows version of my program.

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

Re: repeating audio file playback

Postby Slowdown » Tue Nov 22, 2011 8:01 pm

Hi EasyCoder,
Is it possible to repeat playback of an audio file automatically (wave or mp3) after the file ends and repeat forever?

Yes that is possible use,
Code: Select all
xx.IsPlaying = True/False

where xx is your variable name.
Place the code in a while/wend loop and check if the file is playing and if not restart.
I have the Windows version of Kbasic. If I purchase a key, will I then be able to compile a mac & linux version as well as a windows version of my program.

If you have a key you can compile it on OSX, Linux and Windows but you have to use the OS you targeting on.
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 » Tue Nov 22, 2011 9:32 pm

Thanks for the reply Slowdown.

I could use a while loop. However, I was hoping there might be xx.PlayRepeat function instead.

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

Re: repeating audio file playback

Postby Slowdown » Thu Nov 24, 2011 8:00 pm

Hi EasyCoder,

If i look into the manuals i couldn't find it so i think there is no repeat function.
http://www.kbasic.com/doku.php?id=sound#play
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 Henning » Fri Nov 25, 2011 12:14 am

There seems to be an Event, Sub OnFinished ().

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

Re: repeating audio file playback

Postby Slowdown » Fri Nov 25, 2011 7:19 pm

missed that one Henning but i think in this case IsPlaying is the one to use.
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 » Mon Nov 28, 2011 11:04 pm

Thanks guys for looking into this further for me. So looks like a while loop is the only option.

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

Re: repeating audio file playback

Postby EasyCoder » Wed Nov 30, 2011 12:13 am

After some experimentation, I have found that the sound control is no use to me. I really need something that will repeat automatically.
Using a loop to check if the file is playing and restart playing is too slow. It appears that you need to sleep for 1 second to give the play() function enough time to start the playback, otherwise playback wont start at all. This is fine for playing back just once but no use for repeating playback. If you have a graphics app/game with fast display updates this causes a 1 second pause every time you need to repeat playback.

I would be grateful if you guys have any ideas on how to solve this problem.

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

Re: repeating audio file playback

Postby berndnoetscher » Wed Nov 30, 2011 8:57 am

EasyCoder wrote:After some experimentation, I have found that the sound control is no use to me. I really need something that will repeat automatically.
Using a loop to check if the file is playing and restart playing is too slow. It appears that you need to sleep for 1 second to give the play() function enough time to start the playback, otherwise playback wont start at all. This is fine for playing back just once but no use for repeating playback. If you have a graphics app/game with fast display updates this causes a 1 second pause every time you need to repeat playback.

I would be grateful if you guys have any ideas on how to solve this problem.

Regards,
EasyCoder.


The easiest way would be to add an option autorepeat for Sounds.
I will do it for q7basic soon, but for kbasic I have no time. sorry.
berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

Re: repeating audio file playback

Postby Henning » Wed Nov 30, 2011 11:03 am

@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
Henning
 
Posts: 262
Joined: Mon Feb 09, 2009 12:03 am
Location: Sweden

Next

Return to Coding Questions

cron