[gst-devel] Is there any way to play audio files asynchonously

Stefan Kost ensonic at hora-obscura.de
Sun Jul 6 13:18:34 CEST 2008


Ganesh Kundapur schrieb:
> Hi,
>   I'm playing mp3 file and the code snippet for that is as fallows
> 
> ...
> loop = g_main_loop_new ( NULL, FALSE );
> 
> pipeline = gst_pipeline_new ( "mp3-player" );
> source = gst_element_factory_make ( "filesrc", "file-source" );
> decoder = gst_element_factory_make ( "mad", "mp3-decoder" );
> conv = gst_element_factory_make ( "audioconvert", "converter" );
> sink = gst_element_factory_make ( "alsasink", "sink" );
> 
> g_object_set ( G_OBJECT(source), "location", "x.mp3", NULL );
> 
> gst_bin_add_many ( GST_BIN(pipeline), souce, decoder, conv, sink, NULL );
> gst_element_link_many ( souce, decoder, conv, sink, NULL );
> 
> gst_element_set_state ( pipeline, GST_STATE_PLAYING );
> g_main_loop_run ( loop );
> 
> Here after, it starts playing. Once its playing, control is not coming 
> out till the stream ended.
> If i want to pause after certain time interval say 10 sec, i cant do it 
> while playing the stream. Even i set alarm signal and signal handler, 
> but  alarm signal is not delivered while playing the stream.
> 
> Is there any way to play the audio files asynchronously?
> 
They are play'ed async already. You need to register some callback to get 
control back. E.g.:
g_timeout_add_seconds()

or without a mainloop:
clock = gst_pipeline_get_clock (GST_PIPELINE (bin));
clock_id = gst_clock_new_single_shot_id (clock,
     gst_clock_get_time (clock) + (10 * GST_SECOND));
gst_clock_id_wait (clock_id, NULL);

Stefan
> 
> /Ganesh
> 
> 
> ------------------------------------------------------------------------
> 
> -------------------------------------------------------------------------
> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
> Studies have shown that voting for your favorite open source project,
> along with a healthy diet, reduces your potential for chronic lameness
> and boredom. Vote Now at http://www.sourceforge.net/community/cca08
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gstreamer-devel





More information about the gstreamer-devel mailing list