This example shows how to setup a simple Emotion object, make it start playing and register a callback that tells when the playback started.

See \mbox{\hyperlink{emotion_basic_example_8c-example}{the full code here}}.



We start this example by including some header files that will be necessary to work with Emotion, and to display some debug messages\+:


\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{// gcc -o emotion\_basic\_example emotion\_basic\_example.c `pkg-config --libs --cflags emotion evas ecore
       ecore-evas eo`}

\textcolor{preprocessor}{#define EFL\_BETA\_API\_SUPPORT}
\textcolor{preprocessor}{#define EFL\_EO\_API\_SUPPORT}
\textcolor{preprocessor}{#include <Eo.h>}

\textcolor{preprocessor}{#include <Ecore.h>}
\textcolor{preprocessor}{#include <\mbox{\hyperlink{Ecore__Evas_8h}{Ecore\_Evas.h}}>}
\textcolor{preprocessor}{#include <Evas.h>}
\textcolor{preprocessor}{#include <\mbox{\hyperlink{Emotion_8h}{Emotion.h}}>}
\textcolor{preprocessor}{#include <stdio.h>}

\end{DoxyCodeInclude}


Then a callback will be declared, to be called when the object starts its playback\+:


\begin{DoxyCodeInclude}

\textcolor{preprocessor}{#define WIDTH  (320)}
\textcolor{preprocessor}{#define HEIGHT (240)}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_playback\_started\_cb(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keyword}{const} \mbox{\hyperlink{struct__Efl__Event}{Efl\_Event}} *ev 
      \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})
\{
    printf(\textcolor{stringliteral}{"Emotion object started playback.\(\backslash\)n"});
\}

\end{DoxyCodeInclude}


Some basic setup of our canvas, window and background is necessary before displaying our object on it. This setup also includes reading the file to be opened from the program\textquotesingle{}s argument list. Since this is not directly related to Emotion itself, we are just displaying the code for this without an explanation for it\+:


\begin{DoxyCodeInclude}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{int} argc, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *argv[])
\{
   Ecore\_Evas *ee;
   \mbox{\hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas}} *e;
   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *bg, *em;
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *filename = NULL;

   \textcolor{keywordflow}{if} (argc < 2)
     \{
        printf(\textcolor{stringliteral}{"One argument is necessary. Usage:\(\backslash\)n"});
        printf(\textcolor{stringliteral}{"\(\backslash\)t%s <filename>\(\backslash\)n"}, argv[0]);
     \}

   filename = argv[1];

   \textcolor{keywordflow}{if} (!\mbox{\hyperlink{group__Ecore__Evas__Group_ga32ddbb6457033ad435a177eb0c4fe235}{ecore\_evas\_init}}())
     \textcolor{keywordflow}{return} EXIT\_FAILURE;

   \textcolor{comment}{/* this will give you a window with an Evas canvas under the first}
\textcolor{comment}{    * engine available */}
   ee = \mbox{\hyperlink{group__Ecore__Evas__Group_gac7f2cdbcb79635c34317c1183dd04cb0}{ecore\_evas\_new}}(NULL, 10, 10, WIDTH, HEIGHT, NULL);
   \textcolor{keywordflow}{if} (!ee)
     \textcolor{keywordflow}{goto} \mbox{\hyperlink{namespaceefl_1_1eina_1_1log__level_a0eec9fe47d243634f680b56a7d768ec7}{error}};

   \mbox{\hyperlink{group__Ecore__Evas__Group_ga4953047ff97d4f1b0d75a7d513d4f317}{ecore\_evas\_show}}(ee);

   \textcolor{comment}{/* the canvas pointer, de facto */}
   e = \mbox{\hyperlink{group__Ecore__Evas__Group_ga75a7cc694b6069e78df47dab0b0f2d20}{ecore\_evas\_get}}(ee);

   \textcolor{comment}{/* adding a background to this example */}
   bg = \mbox{\hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}}(e);
   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga88bfcce07ad3bcef31687e29075ae2d2}{evas\_object\_name\_set}}(bg, \textcolor{stringliteral}{"our dear rectangle"});
   \mbox{\hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}}(bg, 255, 255, 255, 255); \textcolor{comment}{/* white bg */}
   evas\_object\_move(bg, 0, 0); \textcolor{comment}{/* at canvas' origin */}
   evas\_object\_resize(bg, WIDTH, HEIGHT); \textcolor{comment}{/* covers full canvas */}
   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(bg);

\end{DoxyCodeInclude}


Finally, we start the Emotion part. First we have to create the object in this canvas, and initialize it\+:


\begin{DoxyCodeInclude}

   \textcolor{comment}{/* Creating the emotion object */}
   em = \mbox{\hyperlink{group__Emotion__Init_ga51d2cabe845ba350dc01a18bb5fb9e24}{emotion\_object\_add}}(e);
   emotion\_object\_init(em, NULL);

\end{DoxyCodeInclude}


Notice that we didn\textquotesingle{}t specify which module will be used, so emotion will use the first module found. There\textquotesingle{}s no guarantee of the order that the modules will be found, so if you need to use one of them specifically, please be explicit in the second argument of the function emotion\+\_\+object\+\_\+init().

Now the callback can be registered to this object. It\textquotesingle{}s a normal Evas smart object callback, so we add it with \mbox{\hyperlink{group__Evas__Smart__Object__Group_ga18a8b179f94d21b2b09e19db11741061}{evas\+\_\+object\+\_\+smart\+\_\+callback\+\_\+add()}}\+:


\begin{DoxyCodeInclude}

   \mbox{\hyperlink{group__Efl__Events_ga235d09eb720fe8ba8dbab3e40068f664}{efl\_event\_callback\_add}}
     (em, EFL\_CANVAS\_VIDEO\_EVENT\_PLAYBACK\_START, \_playback\_started\_cb, NULL);

\end{DoxyCodeInclude}


The object itself is ready for use, but we need to load a file to it. This is done by the following function\+:


\begin{DoxyCodeInclude}

   \mbox{\hyperlink{group__Emotion__Init_gad0ff500d058ed35d41b7f6370556fe49}{emotion\_object\_file\_set}}(em, filename);

\end{DoxyCodeInclude}


This object can play audio or video files. For the latter, the image must be displayed in our canvas, and that\textquotesingle{}s why we need to add the object to the canvas. So, like any other Evas object in the canvas, we have to specify its position and size, and explicitly set its visibility. These are the position and dimension where the video will be displayed\+:


\begin{DoxyCodeInclude}

   evas\_object\_move(em, 0, 0);
   evas\_object\_resize(em, WIDTH, HEIGHT);
   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(em);

\end{DoxyCodeInclude}


Since the basic steps were done, we can now start playing our file. For this, we can just call the basic playback control function, and then we can go to the main loop and watch the audio/video playing\+:


\begin{DoxyCodeInclude}

   \mbox{\hyperlink{group__Emotion__Play_gae87e56d49df5652d940b0df0a9be97d7}{emotion\_object\_play\_set}}(em, \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});

   \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}}();

\end{DoxyCodeInclude}


The rest of the code doesn\textquotesingle{}t contain anything special\+:


\begin{DoxyCodeInclude}

   \mbox{\hyperlink{group__Ecore__Evas__Group_gad3ec61f2aa03df4d3dbfd0d311e0c8dc}{ecore\_evas\_free}}(ee);
   \mbox{\hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}}();
   \textcolor{keywordflow}{return} 0;

\mbox{\hyperlink{namespaceefl_1_1eina_1_1log__level_a0eec9fe47d243634f680b56a7d768ec7}{error}}:
   fprintf(stderr, \textcolor{stringliteral}{"you got to have at least one evas engine built and linked"}
                   \textcolor{stringliteral}{" up to ecore-evas for this example to run properly.\(\backslash\)n"});

   \mbox{\hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}}();
   \textcolor{keywordflow}{return} -1;
\}

\end{DoxyCodeInclude}


This code just free the canvas, shutdown the library, and has an entry point for exiting on error. 