Re: Button remains "pressed" until callback function ends



On Wed, 2005-02-16 at 11:34, Michal Kepien wrote:
Play the sound in an idle handler which is set in the callback function.

That's quite a step forward. What if I want to play the sound in the background,
enabling the program to process other events simultaneously? I mean, when the
sound is being played, I can't eg. close the main window or click any other
button. Any hints?

If you're playing the sound via library - no swapping a command line -
you should use a separate thread to play the sound.

http://developer.gnome.org/doc/API/2.0/glib/glib-Threads.html

In your case, as no communication between the thread and the main
application this should be quite easy.

Just change:

void
my_callback(GtkButton* button, gpointer user_data)
{
        // play sound code.
}

To:

gpointer
my_playing_sound_proccess(gpointer data)
{
        // play sound code.
        return 0;
}

void
my_callback(GtkButton* button, gpointer user_data)
{
        GThread *thread;
        GError *error = NULL;

        // this can be moved to main()
        if (!g_thread_supported ())
        {
                g_thread_init (NULL);
        }

        thread = g_thread_create (my_playing_sound_proccess,
                         user_data, // or whatever
                         FALSE,
                         &error);

        if( thread==NULL )
        {
                g_print("Error %s", error->message);    
        }       
}

Regards.
-- 
Iago Rubio



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