无法使用gstreamer apis播放.wav文件

rub*_*uby 1 gstreamer

编写以下代码来播放.wav文件,但它似乎不起作用.我想知道我是否遗漏了一些东西.

码:

#include <gst/gst.h>
#include <glib.h>

int main(int argc , char *argv[])
{
GMainLoop *loop;
GstElement *source,*audioparser,*sink,*pipeline;
GstBus *bus;

gst_init(&argc,&argv);

// create a pipeline
loop = g_main_loop_new (NULL, FALSE);
pipeline = gst_pipeline_new ("wav-player");
source = gst_element_factory_make("filesrc","file-source");
audioparser = gst_element_factory_make("wavparse","wav-parser");
sink = gst_element_factory_make("alsasink","sink1");
g_object_set (G_OBJECT (source), "location", argv[1], NULL);
gst_element_set_state (pipeline, GST_STATE_NULL);
// set location to current sourceg_object_set(G_OBJECT(source),"location",argv[1],NULL);

// add elements to bin
gst_bin_add_many(GST_BIN(pipeline),source,audioparser,sink,NULL);

gst_element_link_many(source,audioparser,sink,NULL);

// create bus
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
g_main_loop_run (loop);
return 1;
}
Run Code Online (Sandbox Code Playgroud)

请使用以下命令编译:

 gcc -Wall $(pkg-config --cflags --libs gstreamer-0.10) wav.c -o wavparser
Run Code Online (Sandbox Code Playgroud)

提前致谢

小智 5

只需使用playbin2而不是手工制作的管道

也就是说,将"pipeline = gst_pipeline_new()"中的所有内容替换为"gst_element_link_many":

pipeline = gst_element_factory_make("playbin2", NULL);
g_object_set(pipeline, "uri", "file:///the/file/I/want.wav", NULL);
Run Code Online (Sandbox Code Playgroud)