1 #include <Elementary.h>
8 typedef struct _Widget_Data Widget_Data;
28 static const char *widtype = NULL;
30 static const char SIG_FORWARD_CLICKED[] = "forward,clicked";
31 static const char SIG_INFO_CLICKED[] = "info,clicked";
32 static const char SIG_NEXT_CLICKED[] = "next,clicked";
33 static const char SIG_PAUSE_CLICKED[] = "pause,clicked";
34 static const char SIG_PLAY_CLICKED[] = "play,clicked";
35 static const char SIG_PREV_CLICKED[] = "prev,clicked";
36 static const char SIG_REWIND_CLICKED[] = "rewind,clicked";
37 static const char SIG_STOP_CLICKED[] = "stop,clicked";
39 static const Evas_Smart_Cb_Description _signals[] = {
40 { SIG_FORWARD_CLICKED, "" },
41 { SIG_INFO_CLICKED, "" },
42 { SIG_NEXT_CLICKED, "" },
43 { SIG_PAUSE_CLICKED, "" },
44 { SIG_PLAY_CLICKED, "" },
45 { SIG_PREV_CLICKED, "" },
46 { SIG_REWIND_CLICKED, "" },
47 { SIG_STOP_CLICKED, "" },
51 static void _del_hook(Evas_Object *obj);
52 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
53 static void _theme_hook(Evas_Object *obj);
54 static void _sizing_eval(Evas_Object *obj);
55 static void _on_focus_hook(void *data, Evas_Object *obj);
56 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
57 Evas_Callback_Type type, void *event_info);
60 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
62 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
63 Evas_Event_Key_Down *ev = event_info;
64 Widget_Data *wd = elm_widget_data_get(obj);
65 if (!wd) return EINA_FALSE;
66 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
67 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
68 if (!wd->video) return EINA_FALSE;
69 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
73 current = elm_video_play_position_get(wd->video);
74 last = elm_video_play_length_get(wd->video);
78 current += last / 100;
79 elm_video_play_position_set(wd->video, current);
82 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
85 if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
89 current = elm_video_play_position_get(wd->video);
90 last = elm_video_play_length_get(wd->video);
94 current -= last / 100;
95 if (current < 0) current = 0;
96 elm_video_play_position_set(wd->video, current);
99 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
102 if (!strcmp(ev->keyname, "space"))
105 if (elm_video_is_playing(wd->video))
107 if (elm_video_is_playing_get(wd->video))
108 >>>>>>> remotes/origin/upstream
109 elm_video_pause(wd->video);
111 elm_video_play(wd->video);
112 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
115 fprintf(stderr, "keyname: '%s' not handle\n", ev->keyname);
120 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
122 Widget_Data *wd = elm_widget_data_get(obj);
124 if (elm_widget_focus_get(obj))
126 edje_object_signal_emit(wd->layout, "elm,action,focus", "elm");
127 evas_object_focus_set(wd->layout, EINA_TRUE);
131 edje_object_signal_emit(wd->layout, "elm,action,unfocus", "elm");
132 evas_object_focus_set(wd->layout, EINA_FALSE);
137 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
139 Widget_Data *wd = elm_widget_data_get(obj);
141 edje_object_mirrored_set(wd->layout, rtl);
145 _theme_hook(Evas_Object *obj)
147 Widget_Data *wd = elm_widget_data_get(obj);
149 _elm_widget_mirrored_reload(obj);
150 _mirrored_set(obj, elm_widget_mirrored_get(obj));
151 _elm_theme_object_set(obj, wd->layout, "video", "base", elm_widget_style_get(obj));
152 edje_object_scale_set(wd->layout, elm_widget_scale_get(obj) *
155 #define UPDATE_THEME(Obj, Target, Layout, Name) \
158 elm_object_style_set(Target, elm_widget_style_get(Obj)); \
159 if (!edje_object_part_swallow(Layout, Name, Target)) \
160 evas_object_hide(Target); \
161 elm_object_disabled_set(Target, elm_widget_disabled_get(Obj)); \
164 UPDATE_THEME(obj, wd->forward, wd->layout, "media_player/forward");
165 UPDATE_THEME(obj, wd->info, wd->layout, "media_player/info");
166 UPDATE_THEME(obj, wd->next, wd->layout, "media_player/next");
167 UPDATE_THEME(obj, wd->pause, wd->layout, "media_player/pause");
168 UPDATE_THEME(obj, wd->play, wd->layout, "media_player/play");
169 UPDATE_THEME(obj, wd->prev, wd->layout, "media_player/prev");
170 UPDATE_THEME(obj, wd->rewind, wd->layout, "media_player/rewind");
171 UPDATE_THEME(obj, wd->next, wd->layout, "media_player/next");
172 UPDATE_THEME(obj, wd->slider, wd->layout, "media_player/slider");
178 _sizing_eval(Evas_Object *obj)
180 Widget_Data *wd = elm_widget_data_get(obj);
184 edje_object_size_min_get(wd->layout, &w, &h);
185 edje_object_size_min_restricted_calc(wd->layout, &w, &h, w, h);
186 evas_object_size_hint_min_set(obj, w, h);
190 _update_slider(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
192 Evas_Object *player = data;
193 Widget_Data *wd = elm_widget_data_get(player);
199 seekable = elm_video_is_seekable(wd->video);
201 seekable = elm_video_is_seekable_get(wd->video);
202 >>>>>>> remotes/origin/upstream
203 length = elm_video_play_length_get(wd->video);
204 pos = elm_video_play_position_get(wd->video);
206 elm_object_disabled_set(wd->slider, !seekable);
207 elm_slider_min_max_set(wd->slider, 0, length);
208 elm_slider_value_set(wd->slider, pos);
212 _update_position(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
214 Evas_Object *player = data;
215 Widget_Data *wd = elm_widget_data_get(player);
218 elm_video_play_position_set(wd->video, elm_slider_value_get(wd->slider));
222 _forward(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
224 Evas_Object *player = data;
225 Widget_Data *wd = elm_widget_data_get(player);
230 pos = elm_video_play_position_get(wd->video);
231 length = elm_video_play_length_get(wd->video);
234 elm_video_play_position_set(wd->video, pos);
236 edje_object_signal_emit(wd->layout, "elm,button,forward", "elm");
237 evas_object_smart_callback_call(player, SIG_FORWARD_CLICKED, NULL);
241 _info(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
243 Evas_Object *player = data;
244 Widget_Data *wd = elm_widget_data_get(player);
248 edje_object_signal_emit(wd->layout, "elm,button,info", "elm");
249 evas_object_smart_callback_call(player, SIG_INFO_CLICKED, NULL);
253 _next(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
255 Evas_Object *player = data;
256 Widget_Data *wd = elm_widget_data_get(player);
261 pos = elm_video_play_position_get(wd->video);
262 length = elm_video_play_length_get(wd->video);
265 elm_video_play_position_set(wd->video, pos);
267 edje_object_signal_emit(wd->layout, "elm,button,next", "elm");
268 evas_object_smart_callback_call(player, SIG_NEXT_CLICKED, NULL);
272 _pause(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
274 Evas_Object *player = data;
275 Widget_Data *wd = elm_widget_data_get(player);
279 edje_object_signal_emit(wd->layout, "elm,player,pause", "elm");
280 elm_video_pause(wd->video);
282 edje_object_signal_emit(wd->layout, "elm,button,pause", "elm");
283 evas_object_smart_callback_call(player, SIG_PAUSE_CLICKED, NULL);
287 _play(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
289 Evas_Object *player = data;
290 Widget_Data *wd = elm_widget_data_get(player);
293 elm_video_play(wd->video);
294 edje_object_signal_emit(wd->layout, "elm,button,play", "elm");
295 evas_object_smart_callback_call(player, SIG_PLAY_CLICKED, NULL);
299 _prev(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
301 Evas_Object *player = data;
302 Widget_Data *wd = elm_widget_data_get(player);
307 pos = elm_video_play_position_get(wd->video);
308 length = elm_video_play_length_get(wd->video);
311 elm_video_play_position_set(wd->video, pos);
312 evas_object_smart_callback_call(player, SIG_PREV_CLICKED, NULL);
313 edje_object_signal_emit(wd->layout, "elm,button,prev", "elm");
317 _rewind(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
319 Evas_Object *player = data;
320 Widget_Data *wd = elm_widget_data_get(player);
323 elm_video_play_position_set(wd->video, 0);
324 edje_object_signal_emit(wd->layout, "elm,button,rewind", "elm");
325 evas_object_smart_callback_call(player, SIG_REWIND_CLICKED, NULL);
329 _stop(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
331 Evas_Object *player = data;
332 Widget_Data *wd = elm_widget_data_get(player);
336 edje_object_signal_emit(wd->layout, "elm,button,stop", "elm");
337 evas_object_smart_callback_call(player, SIG_STOP_CLICKED, NULL);
341 _play_started(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
343 Evas_Object *player = data;
344 Widget_Data *wd = elm_widget_data_get(player);
348 edje_object_signal_emit(wd->layout, "elm,player,play", "elm");
352 _play_finished(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
354 Evas_Object *player = data;
355 Widget_Data *wd = elm_widget_data_get(player);
359 edje_object_signal_emit(wd->layout, "elm,player,pause", "elm");
363 _cleanup_callback(Widget_Data *wd)
365 if (!wd || !wd->emotion) return;
367 evas_object_smart_callback_del(wd->emotion, "frame_decode",
369 evas_object_smart_callback_del(wd->emotion, "frame_resize",
371 evas_object_smart_callback_del(wd->emotion, "length_change",
373 evas_object_smart_callback_del(wd->emotion, "position_update",
375 evas_object_smart_callback_del(wd->emotion, "playback_started",
377 evas_object_smart_callback_del(wd->emotion, "playback_finished",
379 elm_object_disabled_set(wd->slider, EINA_TRUE);
380 elm_object_disabled_set(wd->forward, EINA_TRUE);
381 elm_object_disabled_set(wd->info, EINA_TRUE);
382 elm_object_disabled_set(wd->next, EINA_TRUE);
383 elm_object_disabled_set(wd->pause, EINA_TRUE);
384 elm_object_disabled_set(wd->play, EINA_TRUE);
385 elm_object_disabled_set(wd->prev, EINA_TRUE);
386 elm_object_disabled_set(wd->rewind, EINA_TRUE);
387 elm_object_disabled_set(wd->next, EINA_TRUE);
393 _track_video(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
395 _cleanup_callback(data);
399 _del_hook(Evas_Object *obj)
401 Widget_Data *wd = elm_widget_data_get(obj);
404 evas_object_smart_callback_del(wd->forward, "clicked", _forward);
405 evas_object_smart_callback_del(wd->info, "clicked", _info);
406 evas_object_smart_callback_del(wd->next, "clicked", _next);
407 evas_object_smart_callback_del(wd->pause, "clicked", _pause);
408 evas_object_smart_callback_del(wd->play, "clicked", _play);
409 evas_object_smart_callback_del(wd->prev, "clicked", _prev);
410 evas_object_smart_callback_del(wd->rewind, "clicked", _rewind);
411 evas_object_smart_callback_del(wd->next, "clicked", _next);
412 _cleanup_callback(wd);
417 _player_button_add(Evas_Object *parent, Evas_Object *obj, Evas_Object *layout, const char *name, Evas_Smart_Cb func)
422 ic = elm_icon_add(parent);
423 elm_icon_standard_set(ic, name);
424 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
425 bt = elm_button_add(parent);
426 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
427 elm_object_part_content_set(bt, "icon", ic);
428 evas_object_size_hint_align_set(bt, 0.0, 0.0);
429 elm_object_style_set(bt, "anchor");
430 evas_object_smart_callback_add(bt, "clicked", func, obj);
431 elm_widget_sub_object_add(obj, bt);
433 if (!edje_object_part_swallow(layout, name, bt))
434 evas_object_hide(bt);
439 _double_to_time(double value)
445 pm = value / 60 - (ph * 60);
446 ps = value - (pm * 60);
447 pf = value * 100 - (ps * 100) - (pm * 60 * 100) - (ph * 60 * 60 * 100);
449 snprintf(buf, sizeof(buf), "%i:%02i:%02i.%02i",
452 snprintf(buf, sizeof(buf), "%02i:%02i.%02i",
455 snprintf(buf, sizeof(buf), "%02i.%02i",
458 return eina_stringshare_add(buf);
463 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
465 if (part && strcmp(part, "video")) return;
467 ELM_CHECK_WIDTYPE(obj, widtype);
468 Widget_Data *wd = elm_widget_data_get(obj);
473 if (!_elm_video_check(content)) return;
475 _cleanup_callback(wd);
485 elm_object_disabled_set(wd->slider, EINA_FALSE);
486 elm_object_disabled_set(wd->forward, EINA_FALSE);
487 elm_object_disabled_set(wd->info, EINA_FALSE);
488 elm_object_disabled_set(wd->next, EINA_FALSE);
489 elm_object_disabled_set(wd->pause, EINA_FALSE);
490 elm_object_disabled_set(wd->play, EINA_FALSE);
491 elm_object_disabled_set(wd->prev, EINA_FALSE);
492 elm_object_disabled_set(wd->rewind, EINA_FALSE);
493 elm_object_disabled_set(wd->next, EINA_FALSE);
495 wd->emotion = elm_video_emotion_get(wd->video);
496 emotion_object_priority_set(wd->emotion, EINA_TRUE);
497 evas_object_event_callback_add(wd->video, EVAS_CALLBACK_DEL,
501 seekable = elm_video_is_seekable(wd->video);
503 seekable = elm_video_is_seekable_get(wd->video);
504 >>>>>>> remotes/origin/upstream
505 length = elm_video_play_length_get(wd->video);
506 pos = elm_video_play_position_get(wd->video);
508 elm_object_disabled_set(wd->slider, !seekable);
509 elm_slider_min_max_set(wd->slider, 0, length);
510 elm_slider_value_set(wd->slider, pos);
513 if (elm_video_is_playing(wd->video)) edje_object_signal_emit(wd->layout, "elm,player,play", "elm");
515 if (elm_video_is_playing_get(wd->video)) edje_object_signal_emit(wd->layout, "elm,player,play", "elm");
516 >>>>>>> remotes/origin/upstream
517 else edje_object_signal_emit(wd->layout, "elm,player,pause", "elm");
519 evas_object_smart_callback_add(wd->emotion, "frame_decode",
520 _update_slider, obj);
521 evas_object_smart_callback_add(wd->emotion, "frame_resize",
522 _update_slider, obj);
523 evas_object_smart_callback_add(wd->emotion, "length_change",
524 _update_slider, obj);
525 evas_object_smart_callback_add(wd->emotion, "position_update",
526 _update_slider, obj);
527 evas_object_smart_callback_add(wd->emotion, "playback_started",
529 evas_object_smart_callback_add(wd->emotion, "playback_finished",
530 _play_finished, obj);
532 /* FIXME: track info from video */
541 elm_player_add(Evas_Object *parent)
548 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
549 ELM_SET_WIDTYPE(widtype, "player");
550 elm_widget_type_set(obj, "player");
551 elm_widget_sub_object_add(parent, obj);
552 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
553 elm_widget_data_set(obj, wd);
554 elm_widget_del_hook_set(obj, _del_hook);
555 elm_widget_theme_hook_set(obj, _theme_hook);
556 elm_widget_can_focus_set(obj, EINA_TRUE);
557 elm_widget_event_hook_set(obj, _event_hook);
558 elm_widget_content_set_hook_set(obj, _content_set_hook);
560 wd->layout = edje_object_add(e);
561 _elm_theme_object_set(obj, wd->layout, "player", "base", "default");
562 elm_widget_resize_object_set(obj, wd->layout);
563 elm_widget_sub_object_add(obj, wd->layout);
564 evas_object_show(wd->layout);
565 evas_object_size_hint_weight_set(wd->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
567 wd->forward = _player_button_add(parent, obj, wd->layout, "media_player/forward", _forward);
568 wd->info = _player_button_add(parent, obj, wd->layout, "media_player/info", _info);
569 wd->next = _player_button_add(parent, obj, wd->layout, "media_player/next", _next);
570 wd->pause = _player_button_add(parent, obj, wd->layout, "media_player/pause", _pause);
571 wd->play = _player_button_add(parent, obj, wd->layout, "media_player/play", _play);
572 wd->prev = _player_button_add(parent, obj, wd->layout, "media_player/prev", _prev);
573 wd->rewind = _player_button_add(parent, obj, wd->layout, "media_player/rewind", _rewind);
574 wd->stop = _player_button_add(parent, obj, wd->layout, "media_player/stop", _stop);
576 wd->slider = elm_slider_add(parent);
577 elm_widget_sub_object_add(obj, wd->slider);
578 elm_slider_indicator_format_function_set(wd->slider, _double_to_time, eina_stringshare_del);
579 elm_slider_units_format_function_set(wd->slider, _double_to_time, eina_stringshare_del);
580 elm_slider_min_max_set(wd->slider, 0, 0);
581 elm_slider_value_set(wd->slider, 0);
582 elm_object_disabled_set(wd->slider, EINA_TRUE);
583 evas_object_size_hint_align_set(wd->slider, EVAS_HINT_FILL, 0.5);
584 evas_object_size_hint_weight_set(wd->slider, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
585 edje_object_part_swallow(wd->layout, "media_player/slider", wd->slider);
586 evas_object_smart_callback_add(wd->slider, "changed", _update_position, obj);
591 _mirrored_set(obj, elm_widget_mirrored_get(obj));
602 elm_player_video_set(Evas_Object *player, Evas_Object *video)
604 _content_set_hook(player, "video", video);