2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <Elementary.h>
20 #include <efl_extension.h>
21 #include <AppCommon.h>
27 #include "playermgr.h"
28 #include "timeout_handler.h"
29 #include "mediadata.h"
33 #include "view_player.h"
35 #define BTN_ID "BTN_ID"
37 #define TEXT_NOVIDEO N_("No Video")
38 #define TEXT_NORES N_("---- x ----")
39 #define TEXT_NODATE N_("----.--.--")
40 #define TEXT_NOSOURCE N_("-")
42 #define CONTROL_BTNS 7
44 static const char *_control_name[] = {
60 typedef void (*btn_event_cb)(void *dt);
67 struct playermgr *player;
68 struct control_data *control;
69 struct volume_data *volume;
70 struct slider_data *slider;
72 struct timeout_handler *timeout_handle;
76 Ecore_Timer *drawanim_timer;
97 void CPlayerView::m_UpdateInfoBar(void)
104 elm_object_part_text_set(obj, PART_TITLETEXT, _(TEXT_NOVIDEO));
107 elm_object_part_text_set(obj, PART_DATETEXT, _(TEXT_NODATE));
110 elm_object_part_text_set(obj, PART_SOURCETEXT, _(TEXT_NOSOURCE));
113 elm_object_part_text_set(obj, PART_RESOLUTIONTEXT, _(TEXT_NORES));
116 void CPlayerView::m_UpdateInfoBar(struct mediadata *md)
122 const struct videodata *vd;
125 name = mediadata_get_displayname(md);
127 elm_object_part_text_set(m->base, PART_TITLETEXT, name);
130 video_time = mediadata_get_modifiedtime(md);
132 if (video_time > 0) {
133 localtime_r(&video_time, &tm);
134 strftime(buf, sizeof(buf), "%Y.%m.%d", &tm);
136 snprintf(buf, sizeof(buf), "%s", _(TEXT_NODATE));
139 elm_object_part_text_set(m->base, PART_DATETEXT, buf);
142 /* TODO: temporary, get actual values and set */
143 elm_object_part_text_set(m->base, PART_SOURCETEXT, _("TV"));
146 playermgr_get_play_count(m->player, buf, sizeof(buf));
147 elm_object_part_text_set(m->base, PART_CURRENTTEXT, buf);
150 vd = mediadata_get_video_info(md);
152 snprintf(buf, sizeof(buf), "%dx%d",
153 videodata_get_width(vd),
154 videodata_get_height(vd));
156 m->duration = videodata_get_duration(vd);
158 snprintf(buf, sizeof(buf), "%s", _(TEXT_NORES));
162 elm_object_part_text_set(m->base, PART_RESOLUTIONTEXT, buf);
165 bool CPlayerView::m_PlayVideo(void)
167 struct mediadata *md;
171 r = playermgr_play_video(m->player);
175 path = playermgr_get_video_path(m->player);
177 md = mediadata_create(path);
180 mediadata_destroy(md);
183 slider_reset(m->slider, m->duration);
184 control_signal_emit(m->control, E_PLAYPAUSE_BTN, SIG_SET_PAUSE, "");
188 timeout_handler_reset(m->timeout_handle);
194 void CPlayerView::sm_EvtRewindBtn(void *dt)
202 data = (SPlayerView *)dt;
204 r = playermgr_set_rew(data->player, data->duration);
207 slider_pause(data->slider);
208 control_signal_emit(data->control, E_PLAYPAUSE_BTN,
213 void CPlayerView::sm_EvtForwardBtn(void *dt)
221 data = (SPlayerView *)dt;
223 r = playermgr_set_ff(data->player, data->duration);
226 slider_pause(data->slider);
227 control_signal_emit(data->control, E_PLAYPAUSE_BTN,
232 void CPlayerView::sm_EvtPrevBtn(void *dt)
235 update_action action;
240 data = (SPlayerView *)dt;
242 playermgr_stop_ffrew(data->player);
243 playermgr_set_prev_video(data->player);
245 action = ACTION_PLAY;
246 CViewMgr::GetInstance()->UpdateView(data->id, (void *)&action);
249 void CPlayerView::sm_EvtNextBtn(void *dt)
252 update_action action;
257 data = (SPlayerView *)dt;
259 playermgr_stop_ffrew(data->player);
260 playermgr_set_next_video(data->player, EINA_TRUE);
262 action = ACTION_PLAY;
263 CViewMgr::GetInstance()->UpdateView(data->id, (void *)&action);
266 void CPlayerView::sm_EvtReapeatBtn(void *dt)
273 data = (SPlayerView *)dt;
275 switch (data->repeat) {
277 data->repeat = E_REPEAT_ONE;
280 data->repeat = E_REPEAT_NONE;
283 data->repeat = E_REPEAT_ALL;
290 void CPlayerView::sm_EvtSettingBtn(void *dt)
294 void CPlayerView::sm_EvtPlayBtn(void *dt)
297 player_state_e state;
303 data = (SPlayerView *)dt;
305 if (playermgr_get_ffrew(data->player)) {
306 playermgr_stop_ffrew(data->player);
307 playermgr_resume(data->player);
308 slider_resume(data->slider);
312 r = playermgr_get_state(data->player, &state);
317 case PLAYER_STATE_PLAYING:
318 playermgr_pause(data->player);
319 slider_pause(data->slider);
322 case PLAYER_STATE_PAUSED:
323 playermgr_resume(data->player);
324 slider_resume(data->slider);
331 void CPlayerView::sm_EvtControlBtn(void *dt, const char *ev)
334 btn_event_cb cbs[] = {
348 data = (SPlayerView *)dt;
350 for (i = 0; i < CONTROL_BTNS; i++) {
351 if (!strcmp(_control_name[i], ev))
356 void CPlayerView::sm_CbPlayComplete(void *dt)
359 update_action action;
365 data = (SPlayerView *)dt;
368 if (data->repeat == E_REPEAT_NONE)
369 r = playermgr_set_next_video(data->player, EINA_FALSE);
370 else if (data->repeat == E_REPEAT_ALL)
371 r = playermgr_set_next_video(data->player, EINA_TRUE);
376 action = ACTION_PLAY;
377 CViewMgr::GetInstance()->UpdateView(data->id, (void *)&action);
380 void CPlayerView::sm_CbShowViewFinish(void *dt, Evas_Object *obj,
381 const char *emission, const char *source)
388 data = (SPlayerView *)dt;
390 control_show(data->control);
393 void CPlayerView::m_ShowBar(void)
395 volume_hide_bar(m->volume);
398 elm_object_signal_emit(m->base, SIG_SHOW_VIEW, "");
399 m->bar_hidden = false;
400 slider_resume(m->slider);
404 void CPlayerView::m_HideBar(void)
406 elm_object_signal_emit(m->base, SIG_HIDE_VIEW, "");
407 m->bar_hidden = true;
409 slider_pause(m->slider);
410 control_hide(m->control);
413 void CPlayerView::sm_CbTimeoutEvent(void *dt, int type, void *ev)
420 data = (SPlayerView *)dt;
423 update_action action;
425 action = ACTION_HIDE;
426 CViewMgr::GetInstance()->UpdateView(data->id, (void *)&action);
430 void CPlayerView::sm_EvtBack(void *dt, Evas_Object *obj, void *ev)
437 data = (SPlayerView *)dt;
439 if (data->bar_hidden) {
440 update_action action;
442 action = ACTION_SHOW;
443 CViewMgr::GetInstance()->UpdateView(data->id, (void *)&action);
449 void CPlayerView::sm_EvtVolume(SPlayerView *data, int val)
451 if (!data->bar_hidden) {
452 update_action action;
454 action = ACTION_HIDE;
455 CViewMgr::GetInstance()->UpdateView(data->id, (void *)&action);
458 volume_handle_key(data->volume, (enum volume_val)val);
461 void CPlayerView::sm_CbEcoreEvent(void *dt, int type, void *ei)
469 data = (SPlayerView *)dt;
472 if (type == ECORE_EVENT_KEY_UP) {
473 Evas_Event_Key_Up *ev;
475 ev = (Evas_Event_Key_Up *)ei;
479 if (!strcmp(ev->keyname, KEY_VOLUMEUP))
480 sm_EvtVolume(data, E_VOLUME_UP);
481 else if (!strcmp(ev->keyname, KEY_VOLUMEDOWN))
482 sm_EvtVolume(data, E_VOLUME_DOWN);
483 else if (!strcmp(ev->keyname, KEY_MUTE))
484 sm_EvtVolume(data, E_VOLUME_MUTE);
487 } else if (type == ECORE_EVENT_MOUSE_MOVE) {
492 update_action action;
494 action = ACTION_SHOW;
495 CViewMgr::GetInstance()->UpdateView(data->id, (void *)&action);
499 bool CPlayerView::m_AddControls(void)
501 if (!control_add_bar(m->control, m->base, _control_name, CONTROL_BTNS))
504 m->repeat = E_REPEAT_ALL;
506 control_handler_init(m->control, sm_EvtControlBtn, m);
508 if (!slider_add_bar(m->slider, m->base, m->player))
511 if (!volume_add_bar(m->volume, m->win))
514 m->timeout_handle = timeout_handler_init(TIMEOUT_VIDEOPLAYER,
515 sm_CbTimeoutEvent, m, sm_CbEcoreEvent, m);
517 eext_object_event_callback_add(m->base,
518 EEXT_CALLBACK_BACK, sm_EvtBack, m);
520 if (!m->timeout_handle)
526 Eina_Bool CPlayerView::sm_CbDrawAnimation(void *dt)
531 return ECORE_CALLBACK_CANCEL;
533 data = (SPlayerView *)dt;
535 elm_object_signal_emit(data->base, SIG_SHOW_VIEW, "");
536 control_focus_set(data->control, E_PLAYPAUSE_BTN, EINA_TRUE);
538 data->drawanim_timer = NULL;
540 return ECORE_CALLBACK_CANCEL;
543 void CPlayerView::m_PlayerInit(SPlayerParam *param)
547 r = mediadata_init();
549 _ERR("mediadata init failed");
552 m->id = strdup(param->id);
554 m->player = playermgr_init(m->win, param->filepath, param->playlist);
556 _ERR("player init failed");
558 m->control = control_init();
560 _ERR("control init failed");
562 m->volume = volume_init();
564 _ERR("volume init failed");
566 m->slider = slider_init();
568 _ERR("slider init failed");
571 bool CPlayerView::m_UiInit(void)
575 base = elm_layout_add(m->win);
577 _ERR("failed to add layout");
583 if (!elm_layout_file_set(base, EDJEFILE, GRP_VIDEO_PLAYER)) {
584 _ERR("failed to layout file set");
588 if (!m_AddControls()) {
589 _ERR("failed to add controls");
593 evas_object_size_hint_weight_set(base,
594 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
596 elm_win_resize_object_add(m->win, base);
598 evas_object_show(base);
600 elm_object_focus_allow_set(base, EINA_FALSE);
605 bool CPlayerView::Create(void *data)
613 win = CViewMgr::GetInstance()->Window();
618 _ERR("alloc failed");
625 m_PlayerInit((SPlayerParam *)data);
634 if (!m_PlayVideo()) {
635 _ERR("failed to play video");
639 control_hide(m->control);
640 elm_object_signal_emit(m->base, SIG_SHOW_VIEW, "");
642 CBaseView::Create(NULL);
646 playermgr_set_completed_cb(m->player, sm_CbPlayComplete, m);
648 elm_object_signal_callback_add(m->base, "show,view,finish", "",
649 sm_CbShowViewFinish, m);
651 m->drawanim_timer = ecore_timer_add(0.8, sm_CbDrawAnimation, m);
652 if (!m->drawanim_timer) {
653 _ERR("failed to add draw timer");
657 CBaseView::Create(NULL);
662 void CPlayerView::Destroy(void)
666 CBaseView::Destroy();
668 if (m->drawanim_timer)
669 ecore_timer_del(m->drawanim_timer);
673 playermgr_fini(m->player);
675 volume_fini(m->volume);
676 slider_fini(m->slider);
677 control_fini(m->control);
679 timeout_handler_fini(m->timeout_handle);
687 Evas_Object *CPlayerView::Base(void)
694 void CPlayerView::t_OnShow(void)
698 evas_object_show(m->base);
701 void CPlayerView::t_OnHide(void)
703 evas_object_hide(m->base);
706 void CPlayerView::t_OnPause(void)
711 void CPlayerView::t_OnUpdate(void *dt)
713 update_action *action;
718 action = (update_action *)dt;