[gst-devel] Sound only once

Stefan Kost ensonic at hora-obscura.de
Wed Dec 14 05:14:05 CET 2005


Hi Bernd,

Bernd Muent schrieb:
> Andy Wingo schrieb:
> 
>>> My code (linked to gstreamer-0.8):
>>
>> There is a new release out
> 
> I know. But I think that a pkgconfig-check against 0.8 is absolutely
> enough to play a simple sound. I don't want to force the users to
> install a newer version.
> 
>>> #include <gst/gst.h>
>>>
>>> GstElement *bin,*filesrc,*decoder,*osssink;
>>
>>
>> you sure these are initialized to NULL?
> 
> All right. I added this.
> 
>>> void playSound(char *fileName) {
>>>         if (bin!=NULL)
>>>             gst_element_set_state(GST_ELEMENT(bin),GST_STATE_NULL);
>>
>> you should unref the old pipeline, if any, here
> 
> Something like that?
> gst_object_unref(GST_OBJECT(bin));

This is correct.

> 
>> if it's for a game, why mp3? vorbis is better and is free
> 
> OK, but this is not the problem. The sound is played once.
>>
>>>         if (!decoder) return;
>>>         osssink = gst_element_factory_make("osssink",
>>>                                            "play_audio");
>>>         if (!osssink) return;
>>>         gst_bin_add_many(GST_BIN(bin),filesrc,decoder,osssink,NULL);
>>>         gst_element_link_many(filesrc,decoder,osssink,NULL);
>>>         gst_element_set_state(bin,GST_STATE_PLAYING);
>>
>> you're not iterating the pipeline, dunno how it plays the first time ;)
> 
> I hear it one time.
> The sound is only approx. 0.2 sec. and I like to play it asnycronous in
> thebackground without stopping the game.

Then use a gst_thread_new() as a bin. Then it will play in the
background. There is an example in gstreamer/examples/thread if I recall
right.

> I found out another thing. When my prog is running (and has played the
> sound), a test with gstreamer-properties fails for oss-sound-system. The
> error message is in German "Weiterleitung nicht möglich" (something like
> "not able to forward message".

I belive the oss device is in use by you app. thats why the inspecting
it fails.

> When I terminate my program, the test runs well.
> So my conclusion: Something is blocked after first playing the sound but
> I don't know what.
> I added code like:
> gst_bin_remove_many(GST_BIN(bin),filesrc,decoder,osssink,NULL);
> gst_object_unref(GST_OBJECT(filesrc));
> gst_object_unref(GST_OBJECT(decoder));
> gst_object_unref(GST_OBJECT(osssink));

gst_object_unref(GST_OBJECT(bin)); is enough. This call unlinks and
removes all children.
> 
> but it's still the same problem.
> 
> Is there anybody who can post a simple working(!) example for playing a
> sound file more than once?
> 
> Greetings from Berlin, Bernd
> 
As another suggestion, if you e.g. use esdsink, then multiple app can
access the sound-device.

Hope that helps.

Stefan




More information about the gstreamer-devel mailing list