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>
21 #include "playermgr.h"
24 #define SPEED_MIN -5.0
29 Eina_List *media_list;
37 static void _destroy_list(Eina_List *list)
45 EINA_LIST_FREE(list, o) {
51 static Eina_List *_create_list(const char *playlist)
53 Eina_List *list = NULL;
60 fp = fopen(playlist, "r");
64 while (fscanf(fp, "%s\n", buf) != EOF)
65 list = eina_list_append(list, strdup(buf));
72 static int _get_current(Eina_List *list, const char *path)
84 EINA_LIST_FOREACH(list, l, o) {
85 filepath = (const char *)o;
86 if (!strcmp(filepath, path))
94 struct playermgr *playermgr_init(Evas_Object *win,
95 const char *path, const char *playlist)
97 struct playermgr *mgr;
99 mgr = (playermgr *)calloc(1, sizeof(*mgr));
101 _ERR("Allocation fail");
106 mgr->display_mode = E_FULL_SCREEN;
107 mgr->audio_effect = 0;
109 mgr->media_list = _create_list(playlist);
110 if (!mgr->media_list) {
111 _ERR("play list is null");
116 mgr->current = _get_current(mgr->media_list, path);
117 mgr->total = eina_list_count(mgr->media_list);
119 if (player_create(&mgr->player) != PLAYER_ERROR_NONE) {
120 _ERR("PLAYER CREATION ERROR");
129 static int _play_video(struct playermgr *mgr, const char *path)
134 if (player_set_uri(mgr->player, path) != PLAYER_ERROR_NONE) {
135 _ERR("PLAYER SET URI ERROR");
139 xwin = elm_win_xwindow_get(mgr->win);
140 r = player_set_display(mgr->player, PLAYER_DISPLAY_TYPE_X11,
142 if (r != PLAYER_ERROR_NONE) {
143 _ERR("SETTING DISPLAY ERROR");
147 playermgr_set_display_mode(mgr, mgr->display_mode);
149 r = player_prepare(mgr->player);
150 if (r != PLAYER_ERROR_NONE) {
151 if (r == PLAYER_ERROR_NOT_SUPPORTED_FILE)
152 _ERR("PLAYER PREPARE ERROR NOT SUPPORTED FILE %d", r);
153 else if (r == PLAYER_ERROR_INVALID_URI)
154 _ERR("PLAYER PREPARE ERROR INVALID URI %d", r);
156 _ERR("PLAYER PREPARE ERROR");
161 r = player_start(mgr->player);
162 if (r != PLAYER_ERROR_NONE) {
163 _ERR("PLAYER START ERROR");
167 playermgr_set_audio_effect(mgr, mgr->audio_effect);
172 int playermgr_stop_video(struct playermgr *mgr)
174 if (!mgr || !mgr->player) {
175 _ERR("invalid parameter");
179 player_pause(mgr->player);
180 player_stop(mgr->player);
181 player_unprepare(mgr->player);
186 int playermgr_play_video(struct playermgr *mgr)
191 if (!mgr || !mgr->media_list) {
192 _ERR("invalid parameter");
196 r = playermgr_stop_video(mgr);
200 path = playermgr_get_video_path(mgr);
201 r = _play_video(mgr, path);
206 void playermgr_set_prev_video(struct playermgr *mgr)
209 _ERR("invalid parameter");
213 if (mgr->current == 0)
214 mgr->current = mgr->total - 1;
219 Eina_Bool playermgr_set_next_video(struct playermgr *mgr, Eina_Bool repeat)
222 _ERR("invalid parameter");
226 if (mgr->current == mgr->total - 1) {
238 const char *playermgr_get_video_path(struct playermgr *mgr)
242 if (!mgr || !mgr->media_list) {
243 _ERR("invalid parameter");
247 path = (const char *)eina_list_nth(mgr->media_list, mgr->current);
252 void playermgr_fini(struct playermgr *mgr)
258 _destroy_list(mgr->media_list);
261 player_pause(mgr->player);
262 player_stop(mgr->player);
263 player_unprepare(mgr->player);
264 player_destroy(mgr->player);
270 int playermgr_pause(struct playermgr *mgr)
272 if (!mgr || !mgr->player) {
273 _ERR("invalid parameter");
277 if (player_pause(mgr->player) != PLAYER_ERROR_NONE) {
278 _ERR("Player pause error");
285 int playermgr_resume(struct playermgr *mgr)
287 if (!mgr || !mgr->player) {
288 _ERR("invalid parameter");
292 if (player_start(mgr->player) != PLAYER_ERROR_NONE) {
293 _ERR("Player resume error");
300 int playermgr_get_state(struct playermgr *mgr, player_state_e *state)
304 if (!mgr || !mgr->player) {
305 _ERR("invalid parameter");
309 r = player_get_state(mgr->player, state);
310 if (r != PLAYER_ERROR_NONE) {
311 _ERR("Player get state error");
318 int playermgr_get_position(struct playermgr *mgr, int *position)
322 if (!mgr || !mgr->player) {
323 _ERR("invalid parameter");
328 r = player_get_position(mgr->player, position);
329 if (r != PLAYER_ERROR_NONE) {
330 _ERR("Player get position error");
337 int playermgr_seek(struct playermgr *mgr,
338 int sec, player_seek_completed_cb cb, void *data)
342 if (!mgr || !mgr->player) {
343 _ERR("invalid parameter");
348 r = player_seek(mgr->player, sec, false, cb, data);
349 if (r != PLAYER_ERROR_NONE) {
350 _ERR("Player seek error");
357 int playermgr_set_position(struct playermgr *mgr,
358 int sec, player_seek_completed_cb cb, void *data)
362 if (!mgr || !mgr->player) {
363 _ERR("invalid parameter");
368 r = player_set_position(mgr->player, sec, cb, data);
369 if (r != PLAYER_ERROR_NONE) {
370 _ERR("Player set position error");
377 int playermgr_set_playback_rate(struct playermgr *mgr, float speed)
381 if (!mgr || !mgr->player) {
382 _ERR("invalid parameter");
386 if (speed > SPEED_MAX)
388 else if (speed < SPEED_MIN)
391 r = player_set_playback_rate(mgr->player, speed);
392 if (r != PLAYER_ERROR_NONE) {
393 _ERR("Player set playback error");
402 int playermgr_get_playback_rate(struct playermgr *mgr, float *speed)
405 _ERR("invalid parameter");
414 int playermgr_set_looping(struct playermgr *mgr, bool value)
418 if (!mgr || !mgr->player) {
419 _ERR("invalid parameter");
423 r = player_set_looping(mgr->player, value);
424 if (r != PLAYER_ERROR_NONE) {
425 _ERR("Player set looping error");
432 int playermgr_set_audio_effect(struct playermgr *mgr, int value)
434 /* audio_effect not supported, just return 0 */
435 mgr->audio_effect = value;
440 int playermgr_set_display_mode(struct playermgr *mgr, int value)
443 player_display_mode_e mode;
445 if (!mgr || !mgr->player) {
446 _ERR("invalid parameter");
452 mode = PLAYER_DISPLAY_MODE_FULL_SCREEN;
455 mode = PLAYER_DISPLAY_MODE_ORIGIN_SIZE;
458 _ERR("Invalid value");
462 r = player_set_display_mode(mgr->player, mode);
463 if (r != PLAYER_ERROR_NONE) {
464 _ERR("Player display mode set error");
468 mgr->display_mode = value;
473 int playermgr_set_completed_cb(struct playermgr *mgr,
474 player_completed_cb cb, void *data)
478 if (!mgr || !mgr->player) {
479 _ERR("invalid parameter");
483 r = player_set_completed_cb(mgr->player, cb, data);
484 if (r != PLAYER_ERROR_NONE) {
485 _ERR("Player set completed cb error");
492 void playermgr_get_play_count(struct playermgr *mgr, char *str, int len)
495 _ERR("invalid parameter");
499 snprintf(str, len, "%d/%d", mgr->current + 1, mgr->total);