play sound when a key is pressed



All,

I'm trying to create a very simple app (actually written in vala) that
plays a sound (preferably from a wav file) when a key is pressed.  Key
press events are likely to arrive quite close together.   Currently
I'm using gstreamer to do this but it seems to take quite a while
after playing the first "wav" file that I can play the next.

Is using gstreamer the correct approach to attack this requirement or
should look into another library?

Thanks

//andy


Here is the current code I use to play audio.

class Audio {

    private Element playbin;
    private bool playing;
    private string audio_src;

    public Audio() {
        string sounds =
GLib.Path.build_filename(Environment.get_current_dir(), "sounds",
null);
        audio_src = GLib.Path.build_filename(sounds, "alert.wav", null);
        playbin = Gst.ElementFactory.make("playbin", "player");
        playbin.set_property("uri", "file://" + audio_src);

        var bus = playbin.get_bus();
        bus.add_signal_watch();
        bus.message.connect(player_message);
    }

    private void player_message(Message message) {
        if (message.type == Gst.MessageType.EOS ) {
            playbin.set_state(Gst.State.NULL);
            playing=false;
            stdout.printf("read for next sound\n");
        }
    }

    public void make_sound() {
        if(!playing) {
            playing = true;
            playbin.set_state(Gst.State.PLAYING);
        }
    }
}



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