I am trying to play a sound file on the RP5 via GTK using the code below but am not hearing anything. I verified that gtk_media_stream_play() in play() is being called but done() is never called.
Is it possible that I am missing an audio package and/or am not setting a permission?
Is it possible that I am missing an audio package and/or am not setting a permission?
Code:
#include <gtk/gtk.h>void done( GObject *object ){ g_object_unref( object );}void play( const char *name ){ GtkMediaStream *stream; stream = gtk_media_file_new_for_filename( name ); gtk_media_stream_set_volume( stream, 1.0 ); g_signal_connect( stream, "notify::ended", G_CALLBACK( done ), NULL ); gtk_media_stream_play( stream );}void playSound( GtkWidget *button ){ play( "sample.wav" );}void activate( GtkApplication *app, gpointer user_data ){ GtkWidget *window; GtkWidget *button; window = gtk_application_window_new( app ); gtk_window_set_title( GTK_WINDOW( window ), "Play Sound" ); gtk_window_set_resizable( GTK_WINDOW( window ), FALSE ); button = gtk_button_new_with_label( "play" ); g_signal_connect( button, "clicked", G_CALLBACK( playSound ), NULL ); gtk_window_set_child( GTK_WINDOW( window ), button ); gtk_window_present( GTK_WINDOW( window ) );}int main( int argc, char *argv[] ){ GtkApplication *app; int status; gtk_init(); app = gtk_application_new( "com.example.sound", G_APPLICATION_DEFAULT_FLAGS ); g_signal_connect( app, "activate", G_CALLBACK( activate ), NULL ); status = g_application_run( G_APPLICATION( app ), argc, argv ); g_object_unref( app ); return status;}
Statistics: Posted by rp5_art — Thu Oct 17, 2024 7:56 pm — Replies 0 — Views 7