emotion_signals_example.c

This example shows that some of the information available from the emotion object, like the media file play length, aspect ratio, etc. can be not available just after setting the file to the emotion object.

One callback is declared for each of the following signals, and some of the info about the file is displayed. Also notice that the order that these signals are emitted can change depending on the module being used. Following is the full source code of this example:

//Compile with:
// gcc -o emotion_signals_example emotion_signals_example.c `pkg-config --libs --cflags emotion evas ecore ecore-evas eo`
#ifndef EFL_BETA_API_SUPPORT
# define EFL_BETA_API_SUPPORT
#endif
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <Evas.h>
#include <Emotion.h>
#include <stdio.h>
#define WIDTH (320)
#define HEIGHT (240)
static void
_display_info(Evas_Object *o)
{
int w, h;
printf("playing: %d\n", emotion_object_play_get(o));
printf("meta title: %s\n",
printf("seek position: %0.3f\n",
printf("play length: %0.3f\n",
printf("is seekable: %d\n",
printf("video geometry: %dx%d\n", w, h);
printf("video width / height ratio: %0.3f\n",
printf("\n");
}
static void
_playback_started_cb(void *data EINA_UNUSED, const Efl_Event *ev)
{
printf(">>> Emotion object started playback.\n");
_display_info(ev->object);
}
static void
_playback_finished_cb(void *data EINA_UNUSED, const Efl_Event *ev)
{
printf(">>> Emotion object finished playback.\n");
_display_info(ev->object);
}
static void
_open_done_cb(void *data EINA_UNUSED, const Efl_Event *ev)
{
printf(">>> Emotion object open done.\n");
_display_info(ev->object);
}
static void
_position_update_cb(void *data EINA_UNUSED, const Efl_Event *ev)
{
printf(">>> Emotion object first position update.\n");
efl_event_callback_del(ev->object, EFL_CANVAS_VIDEO_EVENT_POSITION_CHANGE, _position_update_cb, NULL);
_display_info(ev->object);
}
static void
_frame_decode_cb(void *data EINA_UNUSED, const Efl_Event *ev)
{
printf(">>> Emotion object first frame decode.\n");
efl_event_callback_del(ev->object, EFL_CANVAS_VIDEO_EVENT_FRAME_DECODE, _frame_decode_cb, NULL);
_display_info(ev->object);
}
static void
_decode_stop_cb(void *data EINA_UNUSED, const Efl_Event *ev)
{
printf(">>> Emotion object decode stop.\n");
_display_info(ev->object);
}
static void
_frame_resize_cb(void *data EINA_UNUSED, const Efl_Event *ev)
{
printf(">>> Emotion object frame resize.\n");
_display_info(ev->object);
}
EFL_CALLBACKS_ARRAY_DEFINE(emotion_object_example_callbacks,
{ EFL_CANVAS_VIDEO_EVENT_PLAYBACK_START, _playback_started_cb },
{ EFL_CANVAS_VIDEO_EVENT_PLAYBACK_STOP, _playback_finished_cb },
{ EFL_CANVAS_VIDEO_EVENT_OPEN_DONE, _open_done_cb },
{ EFL_CANVAS_VIDEO_EVENT_POSITION_CHANGE, _position_update_cb },
{ EFL_CANVAS_VIDEO_EVENT_FRAME_DECODE, _frame_decode_cb },
{ EFL_CANVAS_VIDEO_EVENT_PLAYBACK_STOP, _decode_stop_cb },
{ EFL_CANVAS_VIDEO_EVENT_FRAME_RESIZE, _frame_resize_cb });
int
main(int argc, const char *argv[])
{
Ecore_Evas *ee;
Evas *e;
Evas_Object *bg, *em;
const char *filename = NULL;
const char *module = NULL;
if (argc < 2)
{
printf("At least one argument is necessary. Usage:\n");
printf("\t%s <filename> [module_name]\n", argv[0]);
goto error;
}
filename = argv[1];
if (argc >= 3)
module = argv[2];
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;
/* the canvas pointer, de facto */
e = ecore_evas_get(ee);
/* adding a background to this example */
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 */
/* Creating the emotion object */
/* Try to load the specified module - NULL for auto-discover */
if (!emotion_object_init(em, module))
fprintf(stderr, "Emotion: \"%s\" module could not be initialized.\n", module);
_display_info(em);
efl_event_callback_array_add(em, emotion_object_example_callbacks(), NULL);
if (!emotion_object_file_set(em, filename))
fprintf(stderr, "Emotion: Could not load the file \"%s\"\n", filename);
evas_object_move(em, 0, 0);
evas_object_resize(em, WIDTH, HEIGHT);
return 0;
error:
return -1;
}
ecore_evas_new
EAPI Ecore_Evas * ecore_evas_new(const char *engine_name, int x, int y, int w, int h, const char *extra_options)
Creates a new Ecore_Evas based on engine name and common parameters.
Definition: ecore_evas.c:1059
ecore_evas_shutdown
EAPI int ecore_evas_shutdown(void)
Shuts down the Ecore_Evas system.
Definition: ecore_evas.c:668
EINA_UNUSED
#define EINA_UNUSED
Definition: eina_types.h:321
ecore_evas_free
EAPI void ecore_evas_free(Ecore_Evas *ee)
Frees an Ecore_Evas.
Definition: ecore_evas.c:1103
ecore_evas_init
EAPI int ecore_evas_init(void)
Inits the Ecore_Evas system.
Definition: ecore_evas.c:604
EFL_CALLBACKS_ARRAY_DEFINE
#define EFL_CALLBACKS_ARRAY_DEFINE(Name,...)
Helper for creating global callback arrays.
Definition: Eo.h:2170
_Efl_Event
A parameter passed in event callbacks holding extra event parameters.
Definition: Eo.h:240
Evas_Object
Efl_Canvas_Object Evas_Object
Definition: Evas_Common.h:180
Ecore_Evas.h
Evas wrapper functions.
emotion_object_size_get
void emotion_object_size_get(const Evas_Object *obj, int *iw, int *ih)
Retrieve the video size of the loaded file.
Definition: emotion_smart.c:810
efl_event_callback_del
EOAPI Eina_Bool efl_event_callback_del(Eo *obj, const Efl_Event_Description *desc, Efl_Event_Cb func, const void *user_data)
Delete a callback with a specific data associated with it for an event.
ecore_evas_get
EAPI Evas * ecore_evas_get(const Ecore_Evas *ee)
Gets an Ecore_Evas's Evas.
Definition: ecore_evas.c:1320
emotion_object_ratio_get
double emotion_object_ratio_get(const Evas_Object *obj)
Retrieve the video aspect ratio of the media file loaded.
Definition: emotion_smart.c:851
emotion_object_seekable_get
Eina_Bool emotion_object_seekable_get(const Evas_Object *obj)
Get whether the media file is seekable.
Definition: emotion_smart.c:778
EMOTION_META_INFO_TRACK_TITLE
track title
Definition: Emotion.h:187
Emotion.h
Emotion Media Library.
_Efl_Event::object
Efl_Object * object
The object the callback was called on.
Definition: Eo.h:242
ecore_main_loop_begin
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1279
evas_object_show
void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1853
Evas
Eo Evas
Definition: Evas_Common.h:158
EINA_TRUE
#define EINA_TRUE
Definition: eina_types.h:508
emotion_object_play_length_get
double emotion_object_play_length_get(const Evas_Object *obj)
Get the length of play for the media file.
Definition: emotion_smart.c:804
emotion_object_play_set
void emotion_object_play_set(Evas_Object *obj, Eina_Bool play)
Set play/pause state of the media file.
Definition: emotion_smart.c:647
evas_object_rectangle_add
Evas_Object * evas_object_rectangle_add(Evas *e)
Adds a rectangle to the given evas.
Definition: evas_object_rectangle.c:78
emotion_object_position_get
double emotion_object_position_get(const Evas_Object *obj)
Get the position in the media file.
Definition: emotion_smart.c:754
evas_object_name_set
void evas_object_name_set(Evas_Object *eo_obj, const char *name)
Sets the name of the given Evas object to the given name.
Definition: evas_name.c:5
emotion_object_play_get
Eina_Bool emotion_object_play_get(const Evas_Object *obj)
Get play/pause state of the media file.
Definition: emotion_smart.c:708
emotion_object_file_set
Eina_Bool emotion_object_file_set(Evas_Object *obj, const char *filename)
Set the file to be played in the Emotion object.
Definition: emotion_smart.c:349
emotion_object_add
Evas_Object * emotion_object_add(Evas *evas)
Add an emotion object to the canvas.
Definition: emotion_smart.c:236
ecore_evas_show
EAPI void ecore_evas_show(Ecore_Evas *ee)
Shows an Ecore_Evas' window.
Definition: ecore_evas.c:1500
evas_object_color_set
void evas_object_color_set(Evas_Object *obj, int r, int g, int b, int a)
Sets the general/main color of the given Evas object to the given one.
Definition: evas_object_main.c:2063
emotion_object_meta_info_get
const char * emotion_object_meta_info_get(const Evas_Object *obj, Emotion_Meta_Info meta)
Retrieve meta information from this file being played.
Definition: emotion_smart.c:1271
efl_event_callback_array_add
#define efl_event_callback_array_add(obj, array, data)
Definition: Eo.h:2216