#include <gst/gst.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
GstElement *element;
GstElement *element1;
GstElement *element2;
GstElement *pipeline;
gst_init(&argc, &argv);
if(argc != 2)
{
g_print("usage: %s argv[1] \n", argv[0]);
exit(EXIT_FAILURE);
}
/* Creating a new pipeline */
pipeline = gst_pipeline_new("pipeline");
/* creating a new *.mp3 source element */
element = gst_element_factory_make("filesrc", "source");
if(element != NULL)
g_object_set(G_OBJECT(element), "location", argv[1], NULL);
else
{
g_print("Failed to create element \n");
exit(EXIT_FAILURE);
}
/* creating a new *.mp3 de-coder element */
element1 = gst_element_factory_make("decodebin2", "decoder");
if(element1 != NULL)
g_print("element1 success \n");
else
{
g_print("Failed to create element1 \n");
exit(EXIT_FAILURE);
}
/* creating a new *.mp3 sink element */
element2 = gst_element_factory_make("autoaudiosink", "play_audio");
if(element2 != NULL)
g_print("element2 success \n");
else
{
g_print("Failed to create element2 \n");
exit(EXIT_FAILURE);
}
/* Adding elements to pipeline */
gst_bin_add_many(GST_BIN(pipeline), element, element1, element2, NULL);
/* Linking src to sink element */
gst_element_link_many(element, element1, element2, NULL);
/* start playing */
gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING);
while(gst_bin_iterate_recurse(GST_BIN(pipeline)));
/* stop playing */
gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_NULL);
/* un-referencing all the elements in the pipeline */
gst_object_unref(GST_OBJECT(pipeline));
return 0;
}
1)编译步骤:- gcc gst6.c -o gst6 pk-config --cflags --libs gstreamer-0.10
,它正在编译,没有任何警告和错误。
2) 导出 PKG_CONFIG_PATH 环境变量,即导出 PKG_CONFIG_PATH=/usr/lin/pkgconfig。3)执行步骤:./gst6 /home/user/Downloads/*.mp3 4)输出:element1成功,element2成功
杀死。
无法播放音频文件。请让我知道我的程序有什么问题。这是我的第一个程序。