Commit 58f54e7f authored by Ludovic Fauvet's avatar Ludovic Fauvet

playback service: add support for repeat ONE and ALL.

parent ff488fb0
......@@ -37,6 +37,8 @@ struct media_list
media_item *p_mi;
int i_pos;
bool b_free_media;
enum PLAYLIST_REPEAT i_repeat;
};
#define ML_SEND_CALLBACK(pf_cb, ...) do { \
......@@ -90,6 +92,7 @@ media_list_create(bool b_free_media)
p_ml->b_free_media = b_free_media;
p_ml->i_pos = -1;
p_ml->i_repeat = REPEAT_NONE;
return p_ml;
}
......@@ -269,26 +272,48 @@ bool
media_list_set_pos(media_list *p_ml, int i_index)
{
ML_CLIP_POS(i_index);
if (i_index != p_ml->i_pos)
if (i_index != p_ml->i_pos || p_ml->i_repeat == REPEAT_ONE)
{
p_ml->i_pos = i_index;
p_ml->p_mi = p_ml->i_pos >= 0 ? eina_array_data_get(p_ml->p_item_array, p_ml->i_pos) : NULL;
media_list_on_new_pos(p_ml);
return true;
} else
} else {
if (p_ml->i_repeat == REPEAT_ALL)
{
p_ml->i_pos = 0;
p_ml->p_mi = eina_array_data_get(p_ml->p_item_array, p_ml->i_pos);
media_list_on_new_pos(p_ml);
return true;
}
return false;
}
}
bool
media_list_set_next(media_list *p_ml)
{
return media_list_set_pos(p_ml, p_ml->i_pos + 1);
if (p_ml->i_repeat == REPEAT_ONE)
{
return media_list_set_pos(p_ml, p_ml->i_pos);
}
else
{
return media_list_set_pos(p_ml, p_ml->i_pos + 1);
}
}
bool
media_list_set_prev(media_list *p_ml)
{
return media_list_set_pos(p_ml, p_ml->i_pos - 1);
if (p_ml->i_repeat == REPEAT_ONE)
{
return media_list_set_pos(p_ml, p_ml->i_pos);
}
else
{
return media_list_set_pos(p_ml, p_ml->i_pos - 1);
}
}
media_item *
......@@ -308,3 +333,15 @@ media_list_get_item_at(media_list *p_ml, unsigned int i_index)
assert(p_mi);
return p_mi;
}
void
media_list_set_repeat_mode(media_list *p_ml, enum PLAYLIST_REPEAT i_repeat)
{
p_ml->i_repeat = i_repeat;
}
enum PLAYLIST_REPEAT
media_list_get_repeat_mode(media_list *p_ml)
{
return p_ml->i_repeat;
}
......@@ -39,6 +39,12 @@ struct media_list_callbacks
void *p_user_data;
};
enum PLAYLIST_REPEAT {
REPEAT_NONE,
REPEAT_ONE,
REPEAT_ALL,
};
media_list *
media_list_create(bool b_free_media);
......@@ -84,6 +90,11 @@ media_list_get_item(media_list *p_ml);
media_item *
media_list_get_item_at(media_list *p_ml, unsigned int i_index);
void
media_list_set_repeat_mode(media_list *p_ml, enum PLAYLIST_REPEAT i_repeat);
enum PLAYLIST_REPEAT
media_list_get_repeat_mode(media_list *p_ml);
/*****************/
/* static helpers */
......
......@@ -297,6 +297,7 @@ playback_service_create(application *p_app)
return NULL;
p_ps->i_current_lock = -1;
p_ps->b_auto_exit = false;
for (unsigned int i = 0; i < PLAYLIST_CONTEXT_COUNT; ++i)
{
......@@ -508,6 +509,11 @@ playback_service_start(playback_service *p_ps, double i_time)
}
LOGD("playback_service_start: %s", p_mi->psz_path);
// Unset the current file. Because emotion_object_file_set returns EINA_FALSE
// when reloading the same file, we need to unset it first to allow the REPEAT_ONE
// function to work.
emotion_object_file_set(p_ps->p_e, NULL);
if (!emotion_object_file_set(p_ps->p_e, p_mi->psz_path))
{
LOGE("emotion_object_file_set failed");
......@@ -790,3 +796,15 @@ playback_service_set_auto_exit(playback_service *p_ps, bool value)
{
p_ps->b_auto_exit = value;
}
void
playback_service_set_repeat_mode(playback_service *p_ps, enum PLAYLIST_REPEAT i_repeat)
{
media_list_set_repeat_mode(p_ps->p_ml_list[PLAYLIST_CONTEXT_AUDIO], i_repeat);
}
enum PLAYLIST_REPEAT
playback_service_get_repeat_mode(playback_service *p_ps)
{
return media_list_get_repeat_mode(p_ps->p_ml_list[PLAYLIST_CONTEXT_AUDIO]);
}
......@@ -27,6 +27,7 @@
#include "application.h"
#include "media/media_item.h"
#include "media/media_list.h"
enum PLAYLIST_CONTEXT {
PLAYLIST_CONTEXT_AUDIO,
......@@ -169,4 +170,10 @@ playback_service_audio_channel_set(playback_service *p_ps, int channel);
void
playback_service_set_auto_exit(playback_service *p_ps, bool value);
void
playback_service_set_repeat_mode(playback_service *p_ps, enum PLAYLIST_REPEAT i_repeat);
enum PLAYLIST_REPEAT
playback_service_get_repeat_mode(playback_service *p_ps);
#endif /* PLAYBACK_SERVICE_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment