Re: GTK & Sound



    Abhinaba> I appears that the use of sound in Gtk application has raised
    Abhinaba> enough debate.  But would some body please tell me how I can
    Abhinaba> incorporate sound in Gtk+ applications. I don't care if the
    Abhinaba> method is not that portable as I have a very demanding teacher
    Abhinaba> to satisfy ;^).

Pick a sound library that suits your needs and go with it.  The matter of
programming sound into your application really is orthogonal to the gtk part
of the application.  Presumably, you will be playing sound (from files or
generating on-the-fly) in response to signals emitted as a result of the
user poking and typing at your user interface.  That's not qualitatively any
different than Mozilla submitting a form to a website when I click the
submit button:

    #!/usr/bin/env python

    import gtk

    def playsoundandexit(widget, soundfile):
	print "here's where I'd play", soundfile
	gtk.mainquit()

    def main():
	window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL)

	play = gtk.GtkButton("Play")
	play.connect("clicked", playsoundandexit, "sound.au")
	window.add(play)

	window.show_all()

	gtk.mainloop()

    main()

For experimentation purposes (or for throwaway student programming code),
you may find it sufficient to build a small library of sound files and play
them at the appropriate times using play(1) via the system(3) library call.

-- 
Skip Montanaro (skip pobox com)
(847)971-7098




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