audio: Implement the previous() function
To iterate backwards through the list of recently played songs. Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
bd2aaf73d1
commit
5c5e4a1a66
|
@ -18,6 +18,7 @@ namespace audio
|
|||
void pause();
|
||||
void stop();
|
||||
void next();
|
||||
void previous();
|
||||
unsigned int current_trackid();
|
||||
|
||||
void seek_to(long);
|
||||
|
|
|
@ -16,6 +16,8 @@ static bool o_pause_enabled = false;
|
|||
static unsigned int o_pause_count = 0;
|
||||
static bool o_should_pause = false;
|
||||
|
||||
static Playqueue o_recently_played(PQ_ENABLED);
|
||||
|
||||
static void parse_error(GstMessage *error)
|
||||
{
|
||||
GError *err;
|
||||
|
@ -94,6 +96,7 @@ void audio :: init(int *argc, char ***argv)
|
|||
{
|
||||
GstBus *bus;
|
||||
|
||||
o_recently_played.set_flag(PQ_REPEAT);
|
||||
gst_init(argc, argv);
|
||||
|
||||
ocarina_player = gst_element_factory_make("playbin", "ocarina_player");
|
||||
|
@ -149,8 +152,25 @@ void audio :: next()
|
|||
id = deck :: next();
|
||||
library :: lookup(id, &song);
|
||||
load_song(song);
|
||||
cur_trackid = id;
|
||||
track_loaded = true;
|
||||
|
||||
cur_trackid = id;
|
||||
o_recently_played.add_front(id);
|
||||
o_recently_played.reset_cur();
|
||||
}
|
||||
|
||||
void audio :: previous()
|
||||
{
|
||||
library :: Song song;
|
||||
unsigned int id;
|
||||
|
||||
id = o_recently_played.next();
|
||||
if (id == cur_trackid)
|
||||
return;
|
||||
|
||||
library :: lookup(id, &song);
|
||||
load_song(song);
|
||||
cur_trackid = id;
|
||||
}
|
||||
|
||||
unsigned int audio :: current_trackid()
|
||||
|
|
|
@ -116,5 +116,5 @@ unsigned int Playqueue :: next()
|
|||
|
||||
void Playqueue :: reset_cur()
|
||||
{
|
||||
cur = -1;
|
||||
cur = 0;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ void check_error(int error, int expected)
|
|||
print("Failed with error: %d\n", error);
|
||||
} else {
|
||||
if (error == 0)
|
||||
print("Failed (expected error: %d)\n", error);
|
||||
print("Failed (expected error: %d)\n", expected);
|
||||
else
|
||||
print("Success!\n");
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ void test_0()
|
|||
} catch (int error) {
|
||||
check_error(error, -E_EXIST);
|
||||
}
|
||||
call_func("0i", audio :: previous, -E_EXIST);
|
||||
print("\n");
|
||||
}
|
||||
|
||||
|
@ -105,6 +106,14 @@ void test_1()
|
|||
call_func("1e", audio :: stop, 0);
|
||||
check_ret("1f", audio :: current_trackid() == 0, true);
|
||||
check_ret("1g", audio :: position(), 0);
|
||||
call_func("1h", audio :: previous, 0);
|
||||
check_ret("1i", audio :: current_trackid() == 0, true);
|
||||
audio :: next();
|
||||
audio :: next();
|
||||
call_func("1j", audio :: previous, 0);
|
||||
check_ret("1k", audio :: current_trackid() == 1, true);
|
||||
call_func("1l", audio :: previous, 0);
|
||||
check_ret("1m", audio :: current_trackid() == 0, true);
|
||||
print("\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ Selecting id: 1
|
|||
Selecting id: 2
|
||||
Selecting id: 3
|
||||
Selecting id: 4
|
||||
Selecting id: 0
|
||||
Selecting id: 1
|
||||
Selecting id: 2
|
||||
Selecting id: 3
|
||||
|
@ -40,6 +39,7 @@ Selecting id: 0
|
|||
Selecting id: 1
|
||||
Selecting id: 2
|
||||
Selecting id: 3
|
||||
Selecting id: 4
|
||||
Test 3b: size: 16, length: 2153
|
||||
|
||||
Test 4a: SUCCESS
|
||||
|
|
Loading…
Reference in New Issue