core/audio: Save current track in settings database
The settings code is designed to map strings to unsigned integers, which is exactly what we do here. This lets us cut out an extra file access, which is always a plus. We remove the audio file after upgrading to prevent reading it multiple times. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
7e00c8ed10
commit
903357395b
12
core/audio.c
12
core/audio.c
|
@ -4,8 +4,10 @@
|
|||
#include <core/audio.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/settings.h>
|
||||
#include <core/tempq.h>
|
||||
|
||||
static const char *SETTINGS_TRACK = "core.audio.cur";
|
||||
static struct file audio_file = FILE_INIT("cur_track", 0, 0);
|
||||
static struct track *audio_track = NULL;
|
||||
static GstElement *audio_player = NULL;
|
||||
|
@ -16,9 +18,7 @@ static guint audio_bus = 0;
|
|||
|
||||
static void __audio_save()
|
||||
{
|
||||
file_open(&audio_file, OPEN_WRITE);
|
||||
file_writef(&audio_file, "%u\n", track_index(audio_track));
|
||||
file_close(&audio_file);
|
||||
settings_set(SETTINGS_TRACK, track_index(audio_track));
|
||||
}
|
||||
|
||||
static bool __audio_change_state(GstState state)
|
||||
|
@ -96,9 +96,13 @@ static bool __audio_init_idle(void *data)
|
|||
{
|
||||
unsigned int track;
|
||||
|
||||
if (file_open(&audio_file, OPEN_READ)) {
|
||||
if (settings_has(SETTINGS_TRACK)) {
|
||||
track = settings_get(SETTINGS_TRACK);
|
||||
__audio_load(track_get(track), GST_STATE_PAUSED);
|
||||
} else if (file_open(&audio_file, OPEN_READ)) {
|
||||
file_readf(&audio_file, "%u", &track);
|
||||
file_close(&audio_file);
|
||||
file_remove(&audio_file);
|
||||
__audio_load(track_get(track), GST_STATE_PAUSED);
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue