diff --git a/core/audio.c b/core/audio.c index 1a25f16e..899ac609 100644 --- a/core/audio.c +++ b/core/audio.c @@ -305,13 +305,15 @@ struct track *audio_prev() return __audio_load(playlist_prev(), LOAD_PLAYING); } -void audio_pause_after(int n) +bool audio_pause_after(int n) { - if (n != audio_pause_count) { + if (n >= -1 && n != audio_pause_count) { audio_pause_count = n; if (audio_cb) audio_cb->audio_cb_config_pause(audio_pause_count); + return true; } + return false; } #ifdef CONFIG_TESTING diff --git a/include/core/audio.h b/include/core/audio.h index c088696e..43eebc73 100644 --- a/include/core/audio.h +++ b/include/core/audio.h @@ -73,8 +73,11 @@ struct track *audio_next(); /* Called to load the previous track. */ struct track *audio_prev(); -/* Called to configure automatic pausing. */ -void audio_pause_after(int); +/* + * Called to configure automatic pausing. + * Returns true if the value has been changed. + */ +bool audio_pause_after(int); #ifdef CONFIG_TESTING void test_audio_eos(); diff --git a/tests/core/audio.c b/tests/core/audio.c index 595fc106..a55bdb3b 100644 --- a/tests/core/audio.c +++ b/tests/core/audio.c @@ -201,20 +201,26 @@ void test_autopause() struct playlist *history = playlist_lookup(PL_SYSTEM, "History"); int i; - audio_pause_after(3); - g_assert_cmpuint(pause_count, ==, 3); + g_assert_true(audio_pause_after(3)); + g_assert_cmpint(pause_count, ==, 3); + + g_assert_false(audio_pause_after(-2)); + g_assert_cmpint(pause_count, ==, 3); pause_count = 0; - audio_pause_after(3); - g_assert_cmpuint(pause_count, ==, 0); + g_assert_false(audio_pause_after(3)); + g_assert_cmpint(pause_count, ==, 0); - audio_pause_after(5); - g_assert_cmpuint(pause_count, ==, 5); + g_assert_true(audio_pause_after(-1)); + g_assert_cmpint(pause_count, ==, -1); + + g_assert_true(audio_pause_after(5)); + g_assert_cmpint(pause_count, ==, 5); state_count = 0; for (i = 4; i > -1; i--) { test_audio_eos(); - g_assert_cmpuint(pause_count, ==, i); + g_assert_cmpint(pause_count, ==, i); g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING); g_assert(playlist_at(history, 0) == audio_cur_track()); }