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");
121 m->ffrew_timer = NULL;
122 m->display_mode = E_FULL_SCREEN;
127 m->media_list = _create_list(playlist);
128 if (!m->media_list) {
129 _ERR("play list is null");
136 m->current = _get_current(m->media_list, path);
137 m->total = eina_list_count(m->media_list);
139 if (player_create(&m->player) != PLAYER_ERROR_NONE) {
140 _ERR("PLAYER CREATION ERROR");
150 void CPlayer::Destroy(void)
154 ecore_timer_del(m->ffrew_timer);
157 _destroy_list(m->media_list);
160 player_pause(m->player);
161 player_stop(m->player);
162 player_unprepare(m->player);
163 player_destroy(m->player);
170 bool CPlayer::m_Play(const char *path)
176 r = player_set_uri(m->player, path);
177 if (r != PLAYER_ERROR_NONE) {
178 _ERR("PLAYER SET URI ERROR: %d", r);
182 r = player_set_display(m->player, PLAYER_DISPLAY_TYPE_OVERLAY,
183 GET_DISPLAY(m->win));
184 if (r != PLAYER_ERROR_NONE) {
185 _ERR("SETTING DISPLAY ERROR: %d", r);
189 SetDisplayMode(m->display_mode);
190 SetAudioEffect(m->audio_effect);
192 r = player_prepare(m->player);
193 if (r != PLAYER_ERROR_NONE) {
194 _ERR("PLAYER PREPARE ERROR: %d", r);
198 r = player_start(m->player);
199 if (r != PLAYER_ERROR_NONE) {
200 _ERR("PLAYER START ERROR: %d", r);
207 bool CPlayer::Stop(void)
212 player_pause(m->player);
213 player_stop(m->player);
214 player_unprepare(m->player);
219 bool CPlayer::Play(void)
237 bool CPlayer::Prev(void)
242 m->current = m->total - 1;
249 bool CPlayer::Next(bool repeat)
253 if (m->current == m->total - 1) {
265 const char *CPlayer::GetPath(void)
268 ASSERT(m->media_list);
272 path = (const char *)eina_list_nth(m->media_list, m->current);
278 bool CPlayer::Pause(void)
283 player_state_e state;
286 if (state == PLAYER_STATE_PAUSED)
289 if (player_pause(m->player) != PLAYER_ERROR_NONE) {
290 _ERR("Player pause error");
297 bool CPlayer::Resume(void)
302 player_state_e state;
305 if (state == PLAYER_STATE_PLAYING)
308 if (player_start(m->player) != PLAYER_ERROR_NONE) {
309 _ERR("Player resume error");
316 bool CPlayer::GetState(player_state_e *state)
323 r = player_get_state(m->player, state);
324 if (r != PLAYER_ERROR_NONE) {
325 _ERR("Player get state error");
332 bool CPlayer::GetPosition(int *ms)
339 r = player_get_play_position(m->player, ms);
340 if (r != PLAYER_ERROR_NONE) {
341 _ERR("Player get position error");
348 bool CPlayer::SetPosition(int ms, player_seek_completed_cb cb, void *data)
355 r = player_set_play_position(m->player, ms, false, cb, data);
356 if (r != PLAYER_ERROR_NONE) {
357 _ERR("Player set position error");
364 bool CPlayer::SetAudioEffect(int value)
368 /* audio_effect not supported, just return 0 */
369 m->audio_effect = value;
374 bool CPlayer::SetDisplayMode(int value)
380 player_display_mode_e mode;
382 /* display mode not supported, set to full screen forced */
383 mode = PLAYER_DISPLAY_MODE_FULL_SCREEN;
385 r = player_set_display_mode(m->player, mode);
386 if (r != PLAYER_ERROR_NONE) {
387 _ERR("Player display mode set error");
391 m->display_mode = value;
396 bool CPlayer::SetCompletedCb(player_completed_cb cb, void *data)
403 r = player_set_completed_cb(m->player, cb, data);
404 if (r != PLAYER_ERROR_NONE) {
405 _ERR("Player set completed cb error");
412 int CPlayer::GetTotal(void)
419 int CPlayer::GetCurrent(void)
426 Eina_Bool CPlayer::sm_CbFFRew(void *dt)
440 return ECORE_CALLBACK_CANCEL;
442 p->GetPosition(&pos);
445 pos = pos + _speed[m->ff_speed];
446 if (pos > m->duration)
448 } else if (m->rew_speed) {
449 pos = pos - _speed[m->rew_speed];
454 p->SetPosition(pos, NULL, NULL);
456 if (m->rew_speed && pos <= 0) {
457 m->rew_speed = SPEED_MIN;
458 return ECORE_CALLBACK_CANCEL;
461 if (m->ff_speed && pos >= m->duration) {
462 m->ff_speed = SPEED_MIN;
463 return ECORE_CALLBACK_CANCEL;
466 if (ecore_timer_interval_get(m->ffrew_timer) != TIME_INTERVAL)
467 ecore_timer_interval_set(m->ffrew_timer, TIME_INTERVAL);
469 return ECORE_CALLBACK_RENEW;
472 void CPlayer::m_StartFFRew(void)
476 if (!m->ffrew_timer) {
477 m->ffrew_timer = ecore_timer_add(0.0, sm_CbFFRew, this);
479 ecore_timer_interval_set(m->ffrew_timer, 0.0);
480 ecore_timer_reset(m->ffrew_timer);
484 bool CPlayer::SetFF(int duration)
490 m->duration = duration;
491 m->rew_speed = SPEED_MIN;
493 if (m->ff_speed == SPEED_MAX)
497 if (m->ff_speed == SPEED_MIN) {
507 bool CPlayer::SetRew(int duration)
513 m->duration = duration;
514 m->ff_speed = SPEED_MIN;
516 if (m->rew_speed == SPEED_MAX)
520 if (m->rew_speed == SPEED_MIN) {
530 bool CPlayer::GetFFRew(void)
534 if (m->ff_speed || m->rew_speed)
540 void CPlayer::StopFFRew(void)
544 m->ff_speed = SPEED_MIN;
545 m->rew_speed = SPEED_MIN;
547 ecore_timer_del(m->ffrew_timer);
548 m->ffrew_timer = NULL;