Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This worked for me! I was missing code Gst::init(); in main()</p> <pre><code>#include &lt;gtkmm.h&gt; #include &lt;gstreamermm.h&gt; #include &lt;glibmm/main.h&gt; #include &lt;iostream&gt; class Sound { public: Sound(); void start_playing(double frequency); bool stop_playing(); private: Glib::RefPtr&lt;Gst::Pipeline&gt; m_pipeline; Glib::RefPtr&lt;Gst::Element&gt; m_source; Glib::RefPtr&lt;Gst::Element&gt; m_sink; }; Sound::Sound() { m_pipeline = Gst::Pipeline::create("note"); m_source = Gst::ElementFactory::create_element("audiotestsrc", "source"); m_sink = Gst::ElementFactory::create_element("autoaudiosink", "output"); m_pipeline-&gt;add(m_source); m_pipeline-&gt;add(m_sink); m_source-&gt;link(m_sink); } void Sound::start_playing (double frequency) { m_source-&gt;set_property("freq", frequency); //m_pipeline-&gt;set_state(Gst::STATE_NULL); //m_pipeline-&gt;set_state(Gst::STATE_PAUSED); //m_pipeline-&gt;set_state(Gst::STATE_READY); m_pipeline-&gt;set_state(Gst::STATE_PLAYING); /* stop it after 200ms */ Glib::signal_timeout().connect(sigc::mem_fun(*this, &amp;Sound::stop_playing), 200); } bool Sound::stop_playing() { //m_pipeline-&gt;set_state(Gst::STATE_PAUSED); m_pipeline-&gt;set_state(Gst::STATE_NULL); return false; } class HelloWorld : public Gtk::Window { public: HelloWorld(); virtual ~HelloWorld(); protected: //Signal handlers: void on_button_clicked(); //Member widgets: Gtk::Button m_button; Sound sound; }; HelloWorld::HelloWorld() : m_button("Hear Sound") // creates a new button with label "Hello World". { // Sets the border width of the window. set_border_width(10); // When the button receives the "clicked" signal, it will call the // on_button_clicked() method defined below. m_button.signal_clicked().connect(sigc::mem_fun(*this, &amp;HelloWorld::on_button_clicked)); // This packs the button into the Window (a container). add(m_button); // The final step is to display this newly created widget... m_button.show(); } HelloWorld::~HelloWorld() { } void HelloWorld::on_button_clicked() { std::cout &lt;&lt; "Hello World" &lt;&lt; std::endl; sound.start_playing(400); } int main(int argc, char* argv[]) { Gst::init(); Glib::RefPtr&lt;Gtk::Application&gt; app = Gtk::Application::create(argc, argv, "org.gtkmm.example"); HelloWorld helloworld; //Shows the window and returns when it is closed. return app-&gt;run(helloworld); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload