m_管道,gst_状态_就绪); gst\元素\设置\状态(ptr->m\管道,gst\状态\暂停); g_消息(“GST_消息_EOS\n”); 打破 案例GST\u消息\u错误: gchar*调试; GError*错误; gst\消息\解析\错误(消息、错误和调试); g_自由(调试); g_printerr(“错误:%s\n”,错误->消息); g_无错误(错误); 打破 违约: g_消息(“默认\n”); 打破 } bus=bus;//防止“未使用”警告 返回TRUE; } 吃角子老虎{ m_gstReturnValue=gst_元素_集合_状态(m_管道、gst_状态_播放); 如果(m_gstReturnValue==GST_状态_更改_失败) { g_printerr(“错误:无法播放!!\n”); } } 时隙暂停(){ m_gstReturnValue=gst_元素_设置_状态(m_管道,gst_状态_暂停); 如果(m_gstReturnValue==GST_状态_更改_失败) { g_printerr(“错误:无法暂停!!\n”); } } 槽_停止(){ m_gstReturnValue=gst_元素_集合_状态(m_管道,gst_状态_就绪); m_gstReturnValue=gst_元素_设置_状态(m_管道,gst_状态_暂停); 如果(m_gstReturnValue==GST_状态_更改_失败) { g_printerr(“错误:无法停止!!\n”); } } 插槽设置卷(int vol i){ 第一卷=(第一卷>10)?10:(第一卷,qt,audio,gstreamer,Qt,Audio,Gstreamer" /> m_管道,gst_状态_就绪); gst\元素\设置\状态(ptr->m\管道,gst\状态\暂停); g_消息(“GST_消息_EOS\n”); 打破 案例GST\u消息\u错误: gchar*调试; GError*错误; gst\消息\解析\错误(消息、错误和调试); g_自由(调试); g_printerr(“错误:%s\n”,错误->消息); g_无错误(错误); 打破 违约: g_消息(“默认\n”); 打破 } bus=bus;//防止“未使用”警告 返回TRUE; } 吃角子老虎{ m_gstReturnValue=gst_元素_集合_状态(m_管道、gst_状态_播放); 如果(m_gstReturnValue==GST_状态_更改_失败) { g_printerr(“错误:无法播放!!\n”); } } 时隙暂停(){ m_gstReturnValue=gst_元素_设置_状态(m_管道,gst_状态_暂停); 如果(m_gstReturnValue==GST_状态_更改_失败) { g_printerr(“错误:无法暂停!!\n”); } } 槽_停止(){ m_gstReturnValue=gst_元素_集合_状态(m_管道,gst_状态_就绪); m_gstReturnValue=gst_元素_设置_状态(m_管道,gst_状态_暂停); 如果(m_gstReturnValue==GST_状态_更改_失败) { g_printerr(“错误:无法停止!!\n”); } } 插槽设置卷(int vol i){ 第一卷=(第一卷>10)?10:(第一卷,qt,audio,gstreamer,Qt,Audio,Gstreamer" />

Qt 使用gstreamer API播放音频文件时出现问题:应用程序挂起 我用C++编写了一个简单的音频播放器应用程序。我跟着。这是我的代码: CMediaPlayer::CMediaPlayer(QString path) { gst_init(NULL, NULL); createElements(path); } createElements(QString &path) { /* Create gstreamer elements */ m_pipeline = gst_pipeline_new("audio-player"); m_fileSource = gst_element_factory_make("filesrc", "file-source"); m_audioDecoder = gst_element_factory_make("mad", "mp3-decoder"); m_volume = gst_element_factory_make("volume", "volume-name"); m_audioConverter = gst_element_factory_make("audioconvert", "audio-converter"); m_sink = gst_element_factory_make("alsasink", "audio-output"); if (!m_pipeline || !m_fileSource || !m_audioDecoder || !m_volume || !m_audioConverter || !m_sink) { g_printerr ("One or more elements could not be created !! \n"); return false; } /* Set up the pipeline */ else { /* set a message handler on a bus */ GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (m_pipeline)); gst_bus_add_watch(bus, bus_call, m_loop); gst_object_unref(bus); g_object_set (G_OBJECT (m_fileSource), "location", path.toLatin1().data(), NULL); /* add all elements into the pipeline */ gst_bin_add_many (GST_BIN (m_pipeline), m_fileSource, m_audioDecoder, m_volume, m_audioConverter, m_sink, NULL); /* link the elements together */ if(!gst_element_link_many (m_fileSource, m_audioDecoder, NULL)) { g_printerr("ERROR: Failed to link file-source and audio-decoder !! \n"); return false; } if(!gst_element_link_many (m_audioDecoder, m_volume, NULL)) { g_printerr("ERROR: Failed to link audio-decoder and volume !! \n"); return false; } if(!gst_element_link_many (m_volume, m_audioConverter, NULL)) { g_printerr("ERROR: Failed to link audio-decoder and audio-converter !! \n"); return false; } if(!gst_element_link_many (m_audioConverter, m_sink, NULL)) { g_printerr("ERROR: Failed to link audio-converter and sink !! \n"); return false; } } /* Prepare the pipeline */ gst_element_set_state(m_pipeline, GST_STATE_READY); gst_element_set_state(m_pipeline, GST_STATE_PAUSED); } bus_call(GstBus *bus, GstMessage *msg, gpointer data) { CMediaPlayer *ptr = (CMediaPlayer*)(data); switch(GST_MESSAGE_TYPE(msg)) { case GST_MESSAGE_EOS: // Reset the position of the stream gst_element_set_state (ptr->m_pipeline, GST_STATE_READY); gst_element_set_state (ptr->m_pipeline, GST_STATE_PAUSED); g_message("GST_MESSAGE_EOS \n"); break; case GST_MESSAGE_ERROR: gchar *debug; GError *error; gst_message_parse_error (msg, &error, &debug); g_free (debug); g_printerr ("ERROR: %s\n", error->message); g_error_free (error); break; default: g_message("default \n"); break; } bus = bus; // prevent "unused" warning return TRUE; } slot_play() { m_gstReturnValue = gst_element_set_state (m_pipeline, GST_STATE_PLAYING); if(m_gstReturnValue == GST_STATE_CHANGE_FAILURE) { g_printerr("ERROR: Cannot play !! \n"); } } slot_pause() { m_gstReturnValue = gst_element_set_state (m_pipeline, GST_STATE_PAUSED); if(m_gstReturnValue == GST_STATE_CHANGE_FAILURE) { g_printerr("ERROR: Cannot pause !! \n"); } } slot_stop() { m_gstReturnValue = gst_element_set_state (m_pipeline, GST_STATE_READY); m_gstReturnValue = gst_element_set_state (m_pipeline, GST_STATE_PAUSED); if(m_gstReturnValue == GST_STATE_CHANGE_FAILURE) { g_printerr("ERROR: Cannot stop !! \n"); } } slot_setVolume(int vol_i) { vol_i = (vol_i > 10) ? 10 : (vol_i < 0) ? 0 : vol_i; g_object_set(G_OBJECT(m_volume), "volume", (gdouble(vol_i)/10), NULL); } CMediaPlayer::CMediaPlayer(QString路径) { gst_init(空,空); 创建元素(路径); } createElements(QString和path) { /*创建gstreamer元素*/ m_pipeline=gst_pipeline_new(“音频播放器”); m_fileSource=gst_element_factory_make(“filesrc”,“文件源”); m_audioDecoder=gst_元件_工厂_制造(“mad”、“mp3解码器”); m_volume=gst_element_factory_make(“卷”、“卷名”); m_audioConverter=gst_元件_工厂制造(“audioconvert”、“audio converter”); m_sink=gst_元素_工厂制造(“ALASINK”,“音频输出”); 如果(!m|U管道| |!m|U文件源| |!m|U音频解码器| |!m|U音量| |!m| U音频转换器| |!m|U接收器){ g_printerr(“无法创建一个或多个元素!!\n”); 返回false; } /*铺设管道*/ 否则{ /*在总线上设置消息处理程序*/ GstBus*总线=gst_管道_get_总线(gst_管道(m_管道)); gst_总线_添加_手表(总线、总线呼叫、m_环路); 商品及服务税(巴士); g_object_set(g_object(m_fileSource),“location”,path.toLatin1().data(),NULL); /*将所有元素添加到管道中*/ gst_bin_add_many(gst_bin(m_管道)、m_文件源、m_音频解码器、m_音量、m_音频转换器、m_接收器、NULL); /*将元素链接在一起*/ if(!gst_元素_链接_多个(m_文件源,m_音频解码器,NULL)){ g_printerr(“错误:链接文件源和音频解码器失败!!\n”); 返回false; } if(!gst\u元素\u链接\u多(m\u音频解码器,m\u音量,空)){ g_printerr(“错误:无法链接音频解码器和音量!!\n”); 返回false; } 如果(!gst_元素_链接_多个(m_音量,m_音频转换器,空)){ g_printerr(“错误:链接音频解码器和音频转换器失败!!\n”); 返回false; } if(!gst_元素_链接_多(m_音频转换器、m_接收器、空)){ g_printerr(“错误:链接音频转换器和接收器失败!!\n”); 返回false; } } /*准备管道*/ gst_元件_设置_状态(m_管道,gst_状态_就绪); gst_元素_设置_状态(m_管道,gst_状态_暂停); } 总线调用(GstBus*总线、GstMessage*消息、gpointer数据){ CMediaPlayer*ptr=(CMediaPlayer*)(数据); 开关(GST\信息\类型(msg)) { 案例GST\信息\ EOS: //重置流的位置 gst_元素_设置_状态(ptr->m_管道,gst_状态_就绪); gst\元素\设置\状态(ptr->m\管道,gst\状态\暂停); g_消息(“GST_消息_EOS\n”); 打破 案例GST\u消息\u错误: gchar*调试; GError*错误; gst\消息\解析\错误(消息、错误和调试); g_自由(调试); g_printerr(“错误:%s\n”,错误->消息); g_无错误(错误); 打破 违约: g_消息(“默认\n”); 打破 } bus=bus;//防止“未使用”警告 返回TRUE; } 吃角子老虎{ m_gstReturnValue=gst_元素_集合_状态(m_管道、gst_状态_播放); 如果(m_gstReturnValue==GST_状态_更改_失败) { g_printerr(“错误:无法播放!!\n”); } } 时隙暂停(){ m_gstReturnValue=gst_元素_设置_状态(m_管道,gst_状态_暂停); 如果(m_gstReturnValue==GST_状态_更改_失败) { g_printerr(“错误:无法暂停!!\n”); } } 槽_停止(){ m_gstReturnValue=gst_元素_集合_状态(m_管道,gst_状态_就绪); m_gstReturnValue=gst_元素_设置_状态(m_管道,gst_状态_暂停); 如果(m_gstReturnValue==GST_状态_更改_失败) { g_printerr(“错误:无法停止!!\n”); } } 插槽设置卷(int vol i){ 第一卷=(第一卷>10)?10:(第一卷

Qt 使用gstreamer API播放音频文件时出现问题:应用程序挂起 我用C++编写了一个简单的音频播放器应用程序。我跟着。这是我的代码: CMediaPlayer::CMediaPlayer(QString path) { gst_init(NULL, NULL); createElements(path); } createElements(QString &path) { /* Create gstreamer elements */ m_pipeline = gst_pipeline_new("audio-player"); m_fileSource = gst_element_factory_make("filesrc", "file-source"); m_audioDecoder = gst_element_factory_make("mad", "mp3-decoder"); m_volume = gst_element_factory_make("volume", "volume-name"); m_audioConverter = gst_element_factory_make("audioconvert", "audio-converter"); m_sink = gst_element_factory_make("alsasink", "audio-output"); if (!m_pipeline || !m_fileSource || !m_audioDecoder || !m_volume || !m_audioConverter || !m_sink) { g_printerr ("One or more elements could not be created !! \n"); return false; } /* Set up the pipeline */ else { /* set a message handler on a bus */ GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (m_pipeline)); gst_bus_add_watch(bus, bus_call, m_loop); gst_object_unref(bus); g_object_set (G_OBJECT (m_fileSource), "location", path.toLatin1().data(), NULL); /* add all elements into the pipeline */ gst_bin_add_many (GST_BIN (m_pipeline), m_fileSource, m_audioDecoder, m_volume, m_audioConverter, m_sink, NULL); /* link the elements together */ if(!gst_element_link_many (m_fileSource, m_audioDecoder, NULL)) { g_printerr("ERROR: Failed to link file-source and audio-decoder !! \n"); return false; } if(!gst_element_link_many (m_audioDecoder, m_volume, NULL)) { g_printerr("ERROR: Failed to link audio-decoder and volume !! \n"); return false; } if(!gst_element_link_many (m_volume, m_audioConverter, NULL)) { g_printerr("ERROR: Failed to link audio-decoder and audio-converter !! \n"); return false; } if(!gst_element_link_many (m_audioConverter, m_sink, NULL)) { g_printerr("ERROR: Failed to link audio-converter and sink !! \n"); return false; } } /* Prepare the pipeline */ gst_element_set_state(m_pipeline, GST_STATE_READY); gst_element_set_state(m_pipeline, GST_STATE_PAUSED); } bus_call(GstBus *bus, GstMessage *msg, gpointer data) { CMediaPlayer *ptr = (CMediaPlayer*)(data); switch(GST_MESSAGE_TYPE(msg)) { case GST_MESSAGE_EOS: // Reset the position of the stream gst_element_set_state (ptr->m_pipeline, GST_STATE_READY); gst_element_set_state (ptr->m_pipeline, GST_STATE_PAUSED); g_message("GST_MESSAGE_EOS \n"); break; case GST_MESSAGE_ERROR: gchar *debug; GError *error; gst_message_parse_error (msg, &error, &debug); g_free (debug); g_printerr ("ERROR: %s\n", error->message); g_error_free (error); break; default: g_message("default \n"); break; } bus = bus; // prevent "unused" warning return TRUE; } slot_play() { m_gstReturnValue = gst_element_set_state (m_pipeline, GST_STATE_PLAYING); if(m_gstReturnValue == GST_STATE_CHANGE_FAILURE) { g_printerr("ERROR: Cannot play !! \n"); } } slot_pause() { m_gstReturnValue = gst_element_set_state (m_pipeline, GST_STATE_PAUSED); if(m_gstReturnValue == GST_STATE_CHANGE_FAILURE) { g_printerr("ERROR: Cannot pause !! \n"); } } slot_stop() { m_gstReturnValue = gst_element_set_state (m_pipeline, GST_STATE_READY); m_gstReturnValue = gst_element_set_state (m_pipeline, GST_STATE_PAUSED); if(m_gstReturnValue == GST_STATE_CHANGE_FAILURE) { g_printerr("ERROR: Cannot stop !! \n"); } } slot_setVolume(int vol_i) { vol_i = (vol_i > 10) ? 10 : (vol_i < 0) ? 0 : vol_i; g_object_set(G_OBJECT(m_volume), "volume", (gdouble(vol_i)/10), NULL); } CMediaPlayer::CMediaPlayer(QString路径) { gst_init(空,空); 创建元素(路径); } createElements(QString和path) { /*创建gstreamer元素*/ m_pipeline=gst_pipeline_new(“音频播放器”); m_fileSource=gst_element_factory_make(“filesrc”,“文件源”); m_audioDecoder=gst_元件_工厂_制造(“mad”、“mp3解码器”); m_volume=gst_element_factory_make(“卷”、“卷名”); m_audioConverter=gst_元件_工厂制造(“audioconvert”、“audio converter”); m_sink=gst_元素_工厂制造(“ALASINK”,“音频输出”); 如果(!m|U管道| |!m|U文件源| |!m|U音频解码器| |!m|U音量| |!m| U音频转换器| |!m|U接收器){ g_printerr(“无法创建一个或多个元素!!\n”); 返回false; } /*铺设管道*/ 否则{ /*在总线上设置消息处理程序*/ GstBus*总线=gst_管道_get_总线(gst_管道(m_管道)); gst_总线_添加_手表(总线、总线呼叫、m_环路); 商品及服务税(巴士); g_object_set(g_object(m_fileSource),“location”,path.toLatin1().data(),NULL); /*将所有元素添加到管道中*/ gst_bin_add_many(gst_bin(m_管道)、m_文件源、m_音频解码器、m_音量、m_音频转换器、m_接收器、NULL); /*将元素链接在一起*/ if(!gst_元素_链接_多个(m_文件源,m_音频解码器,NULL)){ g_printerr(“错误:链接文件源和音频解码器失败!!\n”); 返回false; } if(!gst\u元素\u链接\u多(m\u音频解码器,m\u音量,空)){ g_printerr(“错误:无法链接音频解码器和音量!!\n”); 返回false; } 如果(!gst_元素_链接_多个(m_音量,m_音频转换器,空)){ g_printerr(“错误:链接音频解码器和音频转换器失败!!\n”); 返回false; } if(!gst_元素_链接_多(m_音频转换器、m_接收器、空)){ g_printerr(“错误:链接音频转换器和接收器失败!!\n”); 返回false; } } /*准备管道*/ gst_元件_设置_状态(m_管道,gst_状态_就绪); gst_元素_设置_状态(m_管道,gst_状态_暂停); } 总线调用(GstBus*总线、GstMessage*消息、gpointer数据){ CMediaPlayer*ptr=(CMediaPlayer*)(数据); 开关(GST\信息\类型(msg)) { 案例GST\信息\ EOS: //重置流的位置 gst_元素_设置_状态(ptr->m_管道,gst_状态_就绪); gst\元素\设置\状态(ptr->m\管道,gst\状态\暂停); g_消息(“GST_消息_EOS\n”); 打破 案例GST\u消息\u错误: gchar*调试; GError*错误; gst\消息\解析\错误(消息、错误和调试); g_自由(调试); g_printerr(“错误:%s\n”,错误->消息); g_无错误(错误); 打破 违约: g_消息(“默认\n”); 打破 } bus=bus;//防止“未使用”警告 返回TRUE; } 吃角子老虎{ m_gstReturnValue=gst_元素_集合_状态(m_管道、gst_状态_播放); 如果(m_gstReturnValue==GST_状态_更改_失败) { g_printerr(“错误:无法播放!!\n”); } } 时隙暂停(){ m_gstReturnValue=gst_元素_设置_状态(m_管道,gst_状态_暂停); 如果(m_gstReturnValue==GST_状态_更改_失败) { g_printerr(“错误:无法暂停!!\n”); } } 槽_停止(){ m_gstReturnValue=gst_元素_集合_状态(m_管道,gst_状态_就绪); m_gstReturnValue=gst_元素_设置_状态(m_管道,gst_状态_暂停); 如果(m_gstReturnValue==GST_状态_更改_失败) { g_printerr(“错误:无法停止!!\n”); } } 插槽设置卷(int vol i){ 第一卷=(第一卷>10)?10:(第一卷,qt,audio,gstreamer,Qt,Audio,Gstreamer,当我运行应用程序时,它的行为异常。有时它玩,有时不玩。当它不播放时,我会从中获取信息: 0:01:12.000176325 31988 0x5e3000 INFO GST_EVENT gstevent.c:1244:gst_event_new_latency: creating latency event 0:00:00.000000000 0:01:12.000953562 31988 0x5e3000 INFO bi

当我运行应用程序时,它的行为异常。有时它玩,有时不玩。当它不播放时,我会从中获取信息:

0:01:12.000176325 31988   0x5e3000 INFO               GST_EVENT gstevent.c:1244:gst_event_new_latency: creating latency event 0:00:00.000000000
0:01:12.000953562 31988   0x5e3000 INFO                     bin gstbin.c:2502:gst_bin_do_latency_func:<audio-player> configured latency of 0:00:00.000000000
0:01:12.001444706 31988   0x5e3000 INFO              GST_STATES gstbin.c:2230:gst_bin_element_set_state:<audio-output> current PAUSED pending VOID_PENDING, desired next PLAYING
0:01:12.004258709 31988   0x5e3000 INFO              GST_STATES gstelement.c:2328:gst_element_continue_state:<audio-output> completed state change to PLAYING
0:01:12.004433239 31988   0x5e3000 INFO              GST_STATES gstelement.c:2233:_priv_gst_element_state_changed:<audio-output> notifying about state-changed PAUSED to PLAYING (VOID_PENDING pending)
0:01:12.004624124 31988   0x5e3000 INFO              GST_STATES gstbin.c:2673:gst_bin_change_state_func:<audio-player> child 'audio-output' changed state to 4(PLAYING) successfully
0:01:12.004783134 31988   0x5e3000 INFO              GST_STATES gstbin.c:2230:gst_bin_element_set_state:<audio-converter> current PAUSED pending VOID_PENDING, desired next PLAYING
0:01:12.004904644 31988   0x5e3000 INFO              GST_STATES gstelement.c:2328:gst_element_continue_state:<audio-converter> completed state change to PLAYING
0:01:12.004990634 31988   0x5e3000 INFO              GST_STATES gstelement.c:2233:_priv_gst_element_state_changed:<audio-converter> notifying about state-changed PAUSED to PLAYING (VOID_PENDING pending)
0:01:12.005134540 31988   0x5e3000 INFO              GST_STATES gstbin.c:2673:gst_bin_change_state_func:<audio-player> child 'audio-converter' changed state to 4(PLAYING) successfully
0:01:12.005267925 31988   0x5e3000 INFO              GST_STATES gstbin.c:2230:gst_bin_element_set_state:<volume-name> current PAUSED pending VOID_PENDING, desired next PLAYING
0:01:12.005386310 31988   0x5e3000 INFO              GST_STATES gstelement.c:2328:gst_element_continue_state:<volume-name> completed state change to PLAYING
0:01:12.005483653 31988   0x5e3000 INFO              GST_STATES gstelement.c:2233:_priv_gst_element_state_changed:<volume-name> notifying about state-changed PAUSED to PLAYING (VOID_PENDING pending)
0:01:12.005634851 31988   0x5e3000 INFO              GST_STATES gstbin.c:2673:gst_bin_change_state_func:<audio-player> child 'volume-name' changed state to 4(PLAYING) successfully
0:01:12.005785006 31988   0x5e3000 INFO              GST_STATES gstbin.c:2230:gst_bin_element_set_state:<mp3-decoder> current PAUSED pending VOID_PENDING, desired next PLAYING
0:01:12.005916673 31988   0x5e3000 INFO              GST_STATES gstelement.c:2328:gst_element_continue_state:<mp3-decoder> completed state change to PLAYING
0:01:12.006004329 31988   0x5e3000 INFO              GST_STATES gstelement.c:2233:_priv_gst_element_state_changed:<mp3-decoder> notifying about state-changed PAUSED to PLAYING (VOID_PENDING pending)
0:01:12.006142245 31988   0x5e3000 INFO              GST_STATES gstbin.c:2673:gst_bin_change_state_func:<audio-player> child 'mp3-decoder' changed state to 4(PLAYING) successfully
0:01:12.006259484 31988   0x5e3000 INFO              GST_STATES gstbin.c:2230:gst_bin_element_set_state:<file-source> current PAUSED pending VOID_PENDING, desired next PLAYING
0:01:12.006381567 31988   0x5e3000 INFO              GST_STATES gstelement.c:2328:gst_element_continue_state:<file-source> completed state change to PLAYING
0:01:12.006465942 31988   0x5e3000 INFO              GST_STATES gstelement.c:2233:_priv_gst_element_state_changed:<file-source> notifying about state-changed PAUSED to PLAYING (VOID_PENDING pending)
0:01:12.006599379 31988   0x5e3000 INFO              GST_STATES gstbin.c:2673:gst_bin_change_state_func:<audio-player> child 'file-source' changed state to 4(PLAYING) successfully
0:01:12.006726983 31988   0x5e3000 INFO              GST_STATES gstelement.c:2328:gst_element_continue_state:<audio-player> completed state change to PLAYING
0:01:12.006812868 31988   0x5e3000 INFO              GST_STATES gstelement.c:2233:_priv_gst_element_state_changed:<audio-player> notifying about state-changed PAUSED to PLAYING (VOID_PENDING pending)
0:01:12.000176325 31988 0x5e3000信息GST\U事件gstevent.c:1244:GST\U事件新延迟:创建延迟事件0:00:00.000000000
0:01:12.000953562 31988 0x5e3000信息bin gstbin.c:2502:gst\u bin\u do\u latency\u func:。但这没用


我错过了什么?我是gstreamer的新手。任何指针都会非常有用。

好的,这对我来说很好,一直在玩

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

int createElements(char *path)
{

    /* Create gstreamer elements */
    GstElement *m_pipeline  = gst_pipeline_new("audio-player");
    GstElement *m_fileSource = gst_element_factory_make("filesrc", "file-source");
    GstElement *m_audioDecoder = gst_element_factory_make("mad", "mp3-decoder");
    GstElement *m_volume = gst_element_factory_make("volume", "volume-name");
    GstElement *m_audioConverter = gst_element_factory_make("audioconvert", "audio-converter");
    GstElement *m_sink = gst_element_factory_make("alsasink", "audio-output");

    if (!m_pipeline || !m_fileSource || !m_audioDecoder || !m_volume || !m_audioConverter || !m_sink) {
            g_printerr ("One or more elements could not be created !! \n");
            return 0;
    } else {
            g_object_set (G_OBJECT (m_fileSource), "location", path, NULL);

            gst_bin_add_many (GST_BIN (m_pipeline), m_fileSource, m_audioDecoder, m_volume, m_audioConverter, m_sink, NULL);

            if(!gst_element_link_many (m_fileSource, m_audioDecoder, NULL)) {
                    g_printerr("ERROR: Failed to link file-source and audio-decoder !! \n");
                    return 0;
            }
            if(!gst_element_link_many (m_audioDecoder, m_volume, NULL)) {
                    g_printerr("ERROR: Failed to link audio-decoder and volume !! \n");
                    return 0;
            }
            if(!gst_element_link_many (m_volume, m_audioConverter, NULL)) {
                    g_printerr("ERROR: Failed to link audio-decoder and audio-converter !! \n");
                    return 0;
            }
            if(!gst_element_link_many (m_audioConverter, m_sink, NULL)) {
                    g_printerr("ERROR: Failed to link audio-converter and sink !! \n");
                    return 0;
            }
    }

    gst_element_set_state(m_pipeline, GST_STATE_PAUSED);
    sleep(3);
    gst_element_set_state(m_pipeline, GST_STATE_PLAYING);
    sleep(1);
    gst_element_set_state(m_pipeline, GST_STATE_PAUSED);
    sleep(2);
    gst_element_set_state(m_pipeline, GST_STATE_PLAYING);

    return 1;
}


int main(int argc, char **argv) {
    GMainLoop *loop = g_main_loop_new (NULL, FALSE);
    gst_init(&argc, &argv);
    createElements(argv[1]);
    g_main_loop_run (loop);
    return 0;
}
使用./alsa_player file.mp3运行

我正在使用gstreamer1.6,但我认为这段代码对于任何1.x gstreamer都能完美运行

更新2: 您还可以尝试使用gst play命令来执行指定ALASINK的相同任务:

gst-play-1.0 japaka.mp3--audiosink=alsasink


使用空间暂停和播放

这对您来说有趣吗
gst-launch-1.0 filesrc location=/home/../some.mp3!疯狂的音量!音频转换!alsasink
?你能把你呼叫的地方的密码也显示出来吗?@otopolsky:是的。命令运行良好。我在构造函数中调用gst_int。我已经编辑了我的帖子,把它也包括在内。我按照你的建议运行了它。如果只需要播放文件,代码似乎就可以工作。当我暂停/停止然后再次播放时,麻烦就来了。我还收到了这些警告:0:00:00.238477854 4109 0x1f84320 WARN alsa conf.c:4705:snd_config_expand:alsalib error:Unknown parameters{AES0 0x02 AES1 0x82 AES2 0x00 AES3 0x02}0:00.238729364 4109 0x1f84320 WARN alsa pcm.c:2239:snd_pcm_open_update:alsalib error
gcc -Wall alsa_player.c -o alsa_player $(pkg-config --cflags --libs gstreamer-1.0)