RE: running a function




I am new to gtk, and trying my hand at writing a mp3player, I
am working on the point of the player that when one song is done
playing it will load and play the next song. How do I run a test
function every couple milli seconds to check to see if it is still
playing or not? is g_timeout_add() what I need to use?

g_timeout_add() will do pretty much exactly what you want (the only gotca with it is that you'll probably 
need to cast your callback to the right type, and you have to check your callback return value).  Even 
running an external program, you can generally coax it into telling you when it's finished.  Glib as 
mechanisms for doing that.

But it's a pretty ghastly way of doing things.  GUI's are supposed to be event-driven, which basically means 
that the program spends as much time as possible doing absolutely nothing.  It just sits around waiting for 
someone or something to come around and wake it up.  Instead of polling the player to see if it's still 
running, make it tell you when it's finished.  And if it won't, find one that will.  (Someone suggested 
gstreamer)

In general, if you have to use a callback to check something at very small intervals, and you're not working 
directly with fickle hardware, you're probably doing something wrong.


Fredderic

_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]