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>
19 #include <AppCommon.h>
22 #include "playermgr.h"
30 #define TIME_INTERVAL 1.0
32 static int _speed[] = {
42 Eina_List *media_list;
52 Ecore_Timer *ffrew_timer;
55 static void _destroy_list(Eina_List *list)
60 EINA_LIST_FREE(list, o) {
66 static Eina_List *_create_list(const char *playlist)
68 Eina_List *list = NULL;
75 fp = fopen(playlist, "r");
79 while (fscanf(fp, "%s\n", buf) != EOF)
80 list = eina_list_append(list, strdup(buf));
87 static int _get_current(Eina_List *list, const char *path)
99 EINA_LIST_FOREACH(list, l, o) {
100 filepath = (const char *)o;
101 if (!strcmp(filepath, path))
109 bool CPlayer::Create(Evas_Object *win, const char *path, const char *playlist)
115 _ERR("allocation fail");
120 m->display_mode = E_FULL_SCREEN;
125 m->media_list = _create_list(playlist);
126 if (!m->media_list) {
127 _ERR("play list is null");
132 m->current = _get_current(m->media_list, path);
133 m->total = eina_list_count(m->media_list);
135 if (player_create(&m->player) != PLAYER_ERROR_NONE) {
136 _ERR("PLAYER CREATION ERROR");
144 void CPlayer::Destroy(void)
148 ecore_timer_del(m->ffrew_timer);
151 _destroy_list(m->media_list);
154 player_pause(m->player);
155 player_stop(m->player);
156 player_unprepare(m->player);
157 player_destroy(m->player);
164 bool CPlayer::m_Play(const char *path)
171 if (player_set_uri(m->player, path) != PLAYER_ERROR_NONE) {
172 _ERR("PLAYER SET URI ERROR");
176 r = player_set_display(m->player, PLAYER_DISPLAY_TYPE_OVERLAY,
177 GET_DISPLAY(m->win));
178 if (r != PLAYER_ERROR_NONE) {
179 _ERR("SETTING DISPLAY ERROR: %d", r);
183 SetDisplayMode(m->display_mode);
184 SetAudioEffect(m->audio_effect);
186 r = player_prepare(m->player);
187 if (r != PLAYER_ERROR_NONE) {
188 _ERR("PLAYER PREPARE ERROR: %d", r);
192 r = player_start(m->player);
193 if (r != PLAYER_ERROR_NONE) {
194 _ERR("PLAYER START ERROR: %d", r);
201 bool CPlayer::Stop(void)
206 player_pause(m->player);
207 player_stop(m->player);
208 player_unprepare(m->player);
213 bool CPlayer::Play(void)
226 _ERR("video path is NULL");
235 bool CPlayer::Prev(void)
240 m->current = m->total - 1;
247 bool CPlayer::Next(bool repeat)
251 if (m->current == m->total - 1) {
263 const char *CPlayer::GetPath(void)
269 if (!m->media_list) {
270 _ERR("invalid parameter");
274 path = (const char *)eina_list_nth(m->media_list, m->current);
279 bool CPlayer::Pause(void)
281 player_state_e state;
287 if (state == PLAYER_STATE_PAUSED)
290 if (player_pause(m->player) != PLAYER_ERROR_NONE) {
291 _ERR("Player pause error");
298 bool CPlayer::Resume(void)
300 player_state_e state;
306 if (state == PLAYER_STATE_PLAYING)
309 if (player_start(m->player) != PLAYER_ERROR_NONE) {
310 _ERR("Player resume error");
317 bool CPlayer::GetState(player_state_e *state)
324 r = player_get_state(m->player, state);
325 if (r != PLAYER_ERROR_NONE) {
326 _ERR("Player get state error");
333 bool CPlayer::GetPosition(int *ms)
340 r = player_get_play_position(m->player, ms);
341 if (r != PLAYER_ERROR_NONE) {
342 _ERR("Player get position error");
349 bool CPlayer::SetPosition(int ms, player_seek_completed_cb cb, void *data)
356 r = player_set_play_position(m->player, ms, false, cb, data);
357 if (r != PLAYER_ERROR_NONE) {
358 _ERR("Player set position error");
365 bool CPlayer::SetAudioEffect(int value)
369 /* audio_effect not supported, just return 0 */
370 m->audio_effect = value;
375 bool CPlayer::SetDisplayMode(int value)
381 player_display_mode_e mode;
383 /* display mode not supported, set to full screen forced */
384 mode = PLAYER_DISPLAY_MODE_FULL_SCREEN;
386 r = player_set_display_mode(m->player, mode);
387 if (r != PLAYER_ERROR_NONE) {
388 _ERR("Player display mode set error");
392 m->display_mode = value;
397 bool CPlayer::SetCompletedCb(player_completed_cb cb, void *data)
404 r = player_set_completed_cb(m->player, cb, data);
405 if (r != PLAYER_ERROR_NONE) {
406 _ERR("Player set completed cb error");
413 int CPlayer::GetTotal(void)
420 int CPlayer::GetCurrent(void)
427 Eina_Bool CPlayer::sm_CbFFRew(void *dt)
434 return ECORE_CALLBACK_CANCEL;
442 return ECORE_CALLBACK_CANCEL;
444 p->GetPosition(&pos);
447 pos = pos + _speed[m->ff_speed];
448 if (pos > m->duration)
450 } else if (m->rew_speed) {
451 pos = pos - _speed[m->rew_speed];
456 p->SetPosition(pos, NULL, NULL);
458 if (m->rew_speed && pos <= 0) {
459 m->rew_speed = SPEED_MIN;
460 return ECORE_CALLBACK_CANCEL;
463 if (m->ff_speed && pos >= m->duration) {
464 m->ff_speed = SPEED_MIN;
465 return ECORE_CALLBACK_CANCEL;
468 if (ecore_timer_interval_get(m->ffrew_timer) != TIME_INTERVAL)
469 ecore_timer_interval_set(m->ffrew_timer, TIME_INTERVAL);
471 return ECORE_CALLBACK_RENEW;
474 void CPlayer::m_StartFFRew(void)
478 if (!m->ffrew_timer) {
479 m->ffrew_timer = ecore_timer_add(0.0, sm_CbFFRew, this);
481 ecore_timer_interval_set(m->ffrew_timer, 0.0);
482 ecore_timer_reset(m->ffrew_timer);
486 bool CPlayer::SetFF(int duration)
492 m->duration = duration;
493 m->rew_speed = SPEED_MIN;
495 if (m->ff_speed == SPEED_MAX)
499 if (m->ff_speed == SPEED_MIN) {
509 bool CPlayer::SetRew(int duration)
515 m->duration = duration;
516 m->ff_speed = SPEED_MIN;
518 if (m->rew_speed == SPEED_MAX)
522 if (m->rew_speed == SPEED_MIN) {
532 bool CPlayer::GetFFRew(void)
536 if (m->ff_speed || m->rew_speed)
542 void CPlayer::StopFFRew(void)
546 m->ff_speed = SPEED_MIN;
547 m->rew_speed = SPEED_MIN;
549 ecore_timer_del(m->ffrew_timer);
550 m->ffrew_timer = NULL;