2013-02-08 09:35:17 -08:00
|
|
|
//Compile with:
|
2015-04-26 04:49:26 -07:00
|
|
|
// gcc -o emotion_generic_example emotion_generic_example.c `pkg-config --libs --cflags emotion evas ecore ecore-evas eina eo`
|
|
|
|
|
|
|
|
#define EFL_EO_API_SUPPORT
|
|
|
|
#define EFL_BETA_API_SUPPORT
|
2013-02-08 09:35:17 -08:00
|
|
|
|
2013-01-09 19:43:32 -08:00
|
|
|
#include <Ecore.h>
|
|
|
|
#include <Ecore_Evas.h>
|
|
|
|
#include <Evas.h>
|
|
|
|
#include <Emotion.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#define WIDTH (320)
|
|
|
|
#define HEIGHT (240)
|
|
|
|
|
|
|
|
static Eina_List *filenames = NULL;
|
|
|
|
static Eina_List *curfile = NULL;
|
|
|
|
|
2016-06-20 07:31:31 -07:00
|
|
|
static void
|
2016-08-30 05:34:10 -07:00
|
|
|
_playback_started_cb(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
printf("Emotion object started playback.\n");
|
|
|
|
}
|
|
|
|
|
2016-06-20 07:31:31 -07:00
|
|
|
static void
|
2016-08-30 05:34:10 -07:00
|
|
|
_playback_stopped_cb(void *data EINA_UNUSED, const Efl_Event *ev)
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
printf("Emotion playback stopped.\n");
|
2016-05-19 00:19:06 -07:00
|
|
|
emotion_object_play_set(ev->object, EINA_FALSE);
|
|
|
|
emotion_object_position_set(ev->object, 0);
|
2013-01-09 19:43:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static Evas_Object *
|
|
|
|
_create_emotion_object(Evas *e)
|
|
|
|
{
|
|
|
|
Evas_Object *em = emotion_object_add(e);
|
|
|
|
|
|
|
|
emotion_object_init(em, "generic");
|
|
|
|
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add
|
2016-09-22 02:43:34 -07:00
|
|
|
(em, EFL_CANVAS_VIDEO_EVENT_PLAYBACK_START, _playback_started_cb, NULL);
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_add
|
2016-09-22 02:43:34 -07:00
|
|
|
(em, EFL_CANVAS_VIDEO_EVENT_PLAYBACK_STOP, _playback_stopped_cb, NULL);
|
2013-01-09 19:43:32 -08:00
|
|
|
|
|
|
|
return em;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-01-09 23:33:22 -08:00
|
|
|
_on_key_down(void *data, Evas *e EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *event_info)
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
Evas_Event_Key_Down *ev = event_info;
|
|
|
|
Evas_Object *em = data;
|
|
|
|
|
2014-01-03 20:25:21 -08:00
|
|
|
if (!strcmp(ev->key, "Return"))
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
emotion_object_play_set(em, EINA_TRUE);
|
|
|
|
}
|
2014-01-03 20:25:21 -08:00
|
|
|
else if (!strcmp(ev->key, "space"))
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
emotion_object_play_set(em, EINA_FALSE);
|
|
|
|
}
|
2014-01-03 20:25:21 -08:00
|
|
|
else if (!strcmp(ev->key, "Escape"))
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
ecore_main_loop_quit();
|
|
|
|
}
|
2014-01-03 20:25:21 -08:00
|
|
|
else if (!strcmp(ev->key, "t"))
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
int w, h;
|
|
|
|
emotion_object_size_get(em, &w, &h);
|
|
|
|
fprintf(stderr, "example -> size: %dx%d\n", w, h);
|
|
|
|
}
|
2014-01-03 20:25:21 -08:00
|
|
|
else if (!strcmp(ev->key, "s"))
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
float len, pos;
|
|
|
|
len = emotion_object_play_length_get(em);
|
|
|
|
pos = 0.98 * len;
|
|
|
|
fprintf(stderr, "skipping to position %0.3f\n", pos);
|
|
|
|
emotion_object_position_set(em, pos);
|
|
|
|
}
|
2014-01-03 20:25:21 -08:00
|
|
|
else if (!strcmp(ev->key, "1"))
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
fprintf(stderr, "setting speed to 1.0\n");
|
|
|
|
emotion_object_play_speed_set(em, 1.0);
|
|
|
|
}
|
2014-01-03 20:25:21 -08:00
|
|
|
else if (!strcmp(ev->key, "2"))
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
fprintf(stderr, "setting speed to 2.0\n");
|
|
|
|
emotion_object_play_speed_set(em, 2.0);
|
|
|
|
}
|
2014-01-03 20:25:21 -08:00
|
|
|
else if (!strcmp(ev->key, "n"))
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
const char *file;
|
|
|
|
if (!curfile)
|
|
|
|
curfile = filenames;
|
|
|
|
else
|
|
|
|
curfile = eina_list_next(curfile);
|
|
|
|
file = eina_list_data_get(curfile);
|
|
|
|
fprintf(stderr, "playing next file: %s\n", file);
|
|
|
|
emotion_object_file_set(em, file);
|
|
|
|
}
|
2014-01-03 20:25:21 -08:00
|
|
|
else if (!strcmp(ev->key, "p"))
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
const char *file;
|
|
|
|
if (!curfile)
|
|
|
|
curfile = eina_list_last(filenames);
|
|
|
|
else
|
|
|
|
curfile = eina_list_prev(curfile);
|
|
|
|
file = eina_list_data_get(curfile);
|
|
|
|
fprintf(stderr, "playing next file: %s\n", file);
|
|
|
|
emotion_object_file_set(em, file);
|
|
|
|
}
|
2014-01-03 20:25:21 -08:00
|
|
|
else if (!strcmp(ev->key, "d"))
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
evas_object_del(em);
|
|
|
|
}
|
2014-01-03 20:25:21 -08:00
|
|
|
else if (!strcmp(ev->key, "l"))
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
// force frame dropping
|
|
|
|
sleep(5);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-03 20:25:21 -08:00
|
|
|
fprintf(stderr, "unhandled key: %s\n", ev->key);
|
2013-01-09 19:43:32 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-20 07:31:31 -07:00
|
|
|
static void
|
2016-08-30 05:34:10 -07:00
|
|
|
_frame_decode_cb(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
// fprintf(stderr, "smartcb: frame_decode\n");
|
|
|
|
}
|
|
|
|
|
2016-06-20 07:31:31 -07:00
|
|
|
static void
|
2016-08-30 05:34:10 -07:00
|
|
|
_length_change_cb(void *data EINA_UNUSED, const Efl_Event *ev)
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
2016-05-19 00:19:06 -07:00
|
|
|
fprintf(stderr, "smartcb: length_change: %0.3f\n", emotion_object_play_length_get(ev->object));
|
2013-01-09 19:43:32 -08:00
|
|
|
}
|
|
|
|
|
2016-06-20 07:31:31 -07:00
|
|
|
static void
|
2016-08-30 05:34:10 -07:00
|
|
|
_position_update_cb(void *data EINA_UNUSED, const Efl_Event *ev)
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
2016-05-19 00:19:06 -07:00
|
|
|
fprintf(stderr, "smartcb: position_update: %0.3f\n", emotion_object_position_get(ev->object));
|
2013-01-09 19:43:32 -08:00
|
|
|
}
|
|
|
|
|
2016-06-20 07:31:31 -07:00
|
|
|
static void
|
2016-08-30 05:34:10 -07:00
|
|
|
_progress_change_cb(void *data EINA_UNUSED, const Efl_Event *ev)
|
2013-01-09 19:43:32 -08:00
|
|
|
{
|
|
|
|
fprintf(stderr, "smartcb: progress_change: %0.3f, %s\n",
|
2016-05-19 00:19:06 -07:00
|
|
|
emotion_object_progress_status_get(ev->object),
|
|
|
|
emotion_object_progress_info_get(ev->object));
|
2013-01-09 19:43:32 -08:00
|
|
|
}
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
EFL_CALLBACKS_ARRAY_DEFINE(emotion_object_example_callbacks,
|
2016-09-22 02:43:34 -07:00
|
|
|
{ EFL_CANVAS_VIDEO_EVENT_FRAME_DECODE, _frame_decode_cb },
|
|
|
|
{ EFL_CANVAS_VIDEO_EVENT_LENGTH_CHANGE, _length_change_cb },
|
|
|
|
{ EFL_CANVAS_VIDEO_EVENT_POSITION_CHANGE, _position_update_cb },
|
|
|
|
{ EFL_CANVAS_VIDEO_EVENT_PROGRESS_CHANGE, _progress_change_cb });
|
2015-04-26 04:49:26 -07:00
|
|
|
|
2013-01-09 19:43:32 -08:00
|
|
|
int
|
|
|
|
main(int argc, const char *argv[])
|
|
|
|
{
|
|
|
|
Ecore_Evas *ee;
|
|
|
|
Evas *e;
|
|
|
|
Evas_Object *bg, *em;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
{
|
|
|
|
printf("One argument is necessary. Usage:\n");
|
|
|
|
printf("\t%s <filename>\n", argv[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
eina_init();
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
filenames = eina_list_append(filenames, eina_stringshare_add(argv[i]));
|
|
|
|
|
|
|
|
curfile = filenames;
|
|
|
|
|
|
|
|
if (!ecore_evas_init())
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
/* this will give you a window with an Evas canvas under the first
|
|
|
|
* engine available */
|
|
|
|
ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
|
|
|
|
if (!ee)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
ecore_evas_show(ee);
|
|
|
|
|
|
|
|
/* the canvas pointer, de facto */
|
|
|
|
e = ecore_evas_get(ee);
|
|
|
|
|
|
|
|
/* adding a background to this example */
|
|
|
|
bg = evas_object_rectangle_add(e);
|
|
|
|
evas_object_name_set(bg, "our dear rectangle");
|
|
|
|
evas_object_color_set(bg, 255, 255, 255, 255); /* white bg */
|
|
|
|
evas_object_move(bg, 0, 0); /* at canvas' origin */
|
|
|
|
evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */
|
|
|
|
evas_object_show(bg);
|
|
|
|
|
|
|
|
/* Creating the emotion object */
|
|
|
|
em = _create_emotion_object(e);
|
|
|
|
emotion_object_file_set(em, eina_list_data_get(curfile));
|
|
|
|
evas_object_move(em, 0, 0);
|
|
|
|
evas_object_resize(em, WIDTH, HEIGHT);
|
|
|
|
evas_object_show(em);
|
|
|
|
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_event_callback_array_add(em, emotion_object_example_callbacks(), NULL);
|
2013-01-09 19:43:32 -08:00
|
|
|
|
|
|
|
evas_object_event_callback_add(bg, EVAS_CALLBACK_KEY_DOWN, _on_key_down, em);
|
|
|
|
evas_object_focus_set(bg, EINA_TRUE);
|
|
|
|
|
|
|
|
emotion_object_play_set(em, EINA_TRUE);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
|
|
|
ecore_evas_free(ee);
|
|
|
|
ecore_evas_shutdown();
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
fprintf(stderr, "you got to have at least one evas engine built and linked"
|
|
|
|
" up to ecore-evas for this example to run properly.\n");
|
|
|
|
|
|
|
|
EINA_LIST_FREE(filenames, curfile)
|
|
|
|
eina_stringshare_del(eina_list_data_get(curfile));
|
|
|
|
|
|
|
|
ecore_evas_shutdown();
|
|
|
|
eina_shutdown();
|
|
|
|
return -1;
|
|
|
|
}
|