EFL: Write a Dvd player in 17 lines
[60 mn of reading - published 5/18/2005 5:37:58 PM - Target : Confirmé]
|
   
|
Author
3 Emotion: write a Dvd player in 17 lines of code
3.1 EFL Installation
This article will not provide installation instructions. There are a lot of existing documentaion: http://get-e.org
3.2 The code
Instead of beginning with a traditional “Hello World”, why not write a Dvd player?! This is a Rasterman idea (the main developer of the EFL) to show off the power and the simplicity of Emotion.
|
#include “Evas.h”
#include “Ecore.h”
#include “Ecore_Evas.h”
#include “Emotion.h” //substitute the "" with braquets
int main(int argc, char **argv){
Evas_Object *video;
Ecore_Evas *ee;
ecore_evas_init();
ecore_evas_show(ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 800, 600));
video = emotion_object_add(ecore_evas_get(ee));
emotion_object_file_set(video, "dvd:/");
emotion_object_play_set(video, 1);
evas_object_resize(video, 800, 600);
evas_object_show(video);
ecore_main_loop_begin();
ecore_evas_shutdown();
} |
To compile:
|
$ gcc my_dvd_player.c -o my_dvd_player \
`emotion-config --cflags --libs` |
3.2 Details
First, let’s talk about the inclusions. We need Evas, Ecore_Evas and Emotion:
|
#include “Evas.h”
#include “Ecore.h”
#include “Ecore_Evas.h”
#include “Emotion.h” //substitute with braquets |
Thanks to Emotion, the video will be an Evas Object. We need an Ecore_Evas object which will allow us to easily create a window with an Evas canvas into it. The ecore_evas_init() function start the Ecore_Evas system.
|
Evas_Object *video; //video object
Ecore_Evas *ee; //Evas window
ecore_evas_init();
|
We create an 800x600 Evas window with Ecore_Evas. And we show it:
|
ecore_evas_show(ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 800, 600)); |
If we did not want to write an 17 lines Dvd player, we would have wrote this :
|
ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 800, 600);
ecore_evas_show(ee);
|
This is more comprehensive. The ecore_evas_software_x11_new() function use the software_X11 backend to create the Evas canvas. We could have used the gl_X11 (OpenGl acceleration) or the fb (framebuffer).
The evas_object_show() function ... shows the Ecore_Evas window.
Now, we know how to create a X11 window with the EFL. We could have displayed a “Hello World” but we will display a Video:
|
video = emotion_object_add(ecore_evas_get(ee));
emotion_object_file_set(video, "dvd:/");
emotion_object_play_set(video, 1);
|
The emotion API is easy to understand. An Emotion object is an Evas object. We create it in our Evas canvas. The ecore_evas_get() returns the Evas canvas of our window.
The emotion_object_file_set() sets the file to play. Here, we set “dvd:/” wich will read the content of /dev/dvd. We can choose any video file or stream. Emotion can read all files that Xine can read. Even Mp3!
The video starts by setting to 1 a boolean. Now, we just have to resize the video to the size of the window and then show it.
|
evas_object_resize(video, 800, 600);
evas_object_show(video);
|
That’s all! We just have to begin the main loop. When the main loop ends, the Ecore_Evas system will be stopped.
|
ecore_main_loop_begin();
ecore_evas_shutdown();
|

Figure 7. our tiny player can handle menu navigation!
|