Skip to content

Commit

Permalink
Fix replay of recorded voice message
Browse files Browse the repository at this point in the history
Signed-off-by: Jacki <[email protected]>
  • Loading branch information
TheJackiMonster committed May 12, 2024
1 parent 5572829 commit abeaae1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
1 change: 1 addition & 0 deletions resources/ui/play_media.ui
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Author: Tobias Frisch
<object class="HdyHeaderBar" id="title_bar">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="title" translatable="yes">Play Media</property>
<property name="show-close-button">True</property>
<child>
<object class="GtkButton" id="back_button">
Expand Down
34 changes: 23 additions & 11 deletions src/ui/chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,13 +905,18 @@ handle_recording_play_button_click(UNUSED GtkButton *button,
_stop_playing_recording(handle, TRUE);
else if (handle->recording_filename[0])
{
GString* uri = g_string_new("file://");
g_string_append(uri, handle->recording_filename);

g_object_set(
G_OBJECT(handle->play_source),
"location",
handle->recording_filename,
G_OBJECT(handle->play_pipeline),
"uri",
uri->str,
NULL
);

g_string_free(uri, TRUE);

gst_element_set_state(handle->play_pipeline, GST_STATE_PLAYING);
handle->playing = TRUE;

Expand Down Expand Up @@ -995,10 +1000,13 @@ _play_timer_func(gpointer user_data)

UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data;

if (handle->play_time < handle->record_time * 100)
const gdouble played_seconds = 0.010 * handle->play_time + 0.005;
const gdouble listen_seconds = MAX(handle->record_time - 0.010, 0.0);

if (played_seconds < listen_seconds)
gtk_progress_bar_set_fraction(
handle->recording_progress_bar,
0.01 * handle->play_time / handle->record_time
played_seconds / listen_seconds
);
else
gtk_progress_bar_set_fraction(
Expand Down Expand Up @@ -1103,13 +1111,17 @@ _setup_gst_pipelines(UI_CHAT_Handle *handle)
gst_object_unref(bus);
}

handle->play_pipeline = gst_parse_launch(
"filesrc name=source ! oggdemux ! vorbisdec ! audioconvert ! autoaudiosink",
NULL
);
handle->play_pipeline = gst_element_factory_make("playbin", NULL);
handle->play_sink = gst_element_factory_make("autoaudiosink", "asink");

if ((!(handle->play_pipeline)) || (!(handle->play_sink)))
return;

handle->play_source = gst_bin_get_by_name(
GST_BIN(handle->play_pipeline), "source"
g_object_set(
G_OBJECT(handle->play_pipeline),
"audio-sink",
handle->play_sink,
NULL
);

{
Expand Down
2 changes: 1 addition & 1 deletion src/ui/chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ typedef struct UI_CHAT_Handle
GstElement *record_sink;

GstElement *play_pipeline;
GstElement *play_source;
GstElement *play_sink;

guint record_watch;
guint play_watch;
Expand Down
6 changes: 2 additions & 4 deletions src/ui/play_media.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,6 @@ ui_play_media_window_init(MESSENGER_Application *app,
gtk_builder_get_object(handle->builder, "title_bar")
);

hdy_header_bar_set_title(handle->title_bar, _("Play Media"));

handle->back_button = GTK_BUTTON(
gtk_builder_get_object(handle->builder, "back_button")
);
Expand Down Expand Up @@ -796,8 +794,8 @@ ui_play_media_window_init(MESSENGER_Application *app,

void
ui_play_media_window_update(UI_PLAY_MEDIA_Handle *handle,
const gchar *uri,
const struct GNUNET_CHAT_File *file)
const gchar *uri,
const struct GNUNET_CHAT_File *file)
{
g_assert((handle) && (uri));

Expand Down

0 comments on commit abeaae1

Please sign in to comment.