Commit a3940b13 authored by Ludovic Fauvet's avatar Ludovic Fauvet

audio player: add popup to change playback speed

parent f7751f35
......@@ -69,6 +69,7 @@
#define VIDEOPLAYER_EDJ get_resource_path( EDJPATH "/video_player.edj")
#define AUDIOPLAYERMINI_EDJ get_resource_path( EDJPATH "/audio_player_mini.edj")
#define AUDIOPLAYER_EDJ get_resource_path( EDJPATH "/audio_player.edj")
#define AUDIOPLAYERSPEED_EDJ get_resource_path( EDJPATH "/audio_player_speed.edj")
#define ABOUT_EDJ get_resource_path( EDJPATH "/about.edj")
#define THEME_EDJ get_resource_path( EDJPATH "/theme.edj")
......
/*****************************************************************************
* Copyright © 2015 VideoLAN, VideoLabs SAS
*****************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*
* By committing to this project, you allow VideoLAN and VideoLabs to relicense
* the code to a different OSI approved license, in case it is required for
* compatibility with the Store
*****************************************************************************/
collections
{
base_scale: 1.8;
group
{
name: "audio_player_speed";
parts {
part{
name: "hub_background";
type: RECT;
description{
state: "default" 0.0;
color: 245 245 245 255; // grey
}
}
part {
name: "swallow.title";
type: TEXT;
description {
state: "default" 0.0;
color: 0 0 0 255; // black
visible: 1;
rel1 {
relative: 0.2 0.1;
to: "hub_background";
}
rel2 {
relative: 0.8 0.2;
to: "hub_background";
}
text {
text: "Speed";
size: 30;
ellipsis: 0;
}
}
}
part {
name: "swallow.left";
type: TEXT;
description {
state: "default" 0.0;
color: 0 0 0 255; // black
visible: 1;
rel1 {
relative: 0.0 -0.6;
to: "swallow.speed";
}
rel2 {
relative: 0.2 0.0;
to: "swallow.speed";
}
text {
text: "0.25x";
size: 22;
ellipsis: 0;
}
}
}
part {
name: "swallow.value";
type: TEXT;
description {
state: "default" 0.0;
color: 0 0 0 255; // black
visible: 1;
rel1 {
relative: 0.4 -0.6;
to: "swallow.speed";
}
rel2 {
relative: 0.6 0.0;
to: "swallow.speed";
}
text {
text: "1x";
size: 22;
ellipsis: 0;
}
}
}
part {
name: "swallow.right";
type: TEXT;
description {
state: "default" 0.0;
color: 0 0 0 255; // black
visible: 1;
rel1 {
relative: 0.8 -0.6;
to: "swallow.speed";
}
rel2 {
relative: 1.0 0.0;
to: "swallow.speed";
}
text {
text: "4x";
size: 22;
ellipsis: 0;
}
}
}
part{
name: "swallow.speed";
type: SWALLOW;
description {
state: "pause" 0.0;
rel1 {
relative: 0.0 0.6;
to: "hub_background";
}
rel2 {
relative: 1.0 0.9;
to: "hub_background";
}
max: -1 50;
min: 1 50;
}
}
} //parts
}
}
......@@ -27,6 +27,7 @@
#include "common.h"
#include <Elementary.h>
#include <math.h>
#include "playback_service.h"
#include "interface.h"
......@@ -55,6 +56,8 @@ struct audio_player {
Evas_Object *fs_save_btn, *fs_playlist_btn, *fs_more_btn;
Evas_Object *fs_repeat_btn, *fs_shuffle_btn;
Evas_Object *speed_popup_layout, *speed_popup_progress;
Ecore_Timer *long_press_timer;
};
......@@ -84,6 +87,75 @@ const char *audio_popup_icon_names[] = {
"sleep",
};
double
audio_player_convert_slider_rate(double slider_value)
{
return pow(4, (slider_value / 100) - 1);
}
static void
audio_player_speed_slider_drag_stop_cb(void *data, Evas_Object *obj, void *event_info)
{
audio_player *mpd = data;
/* */
double value = elm_slider_value_get(mpd->speed_popup_progress);
/* */
playback_service_set_play_speed(mpd->p_ps, audio_player_convert_slider_rate(value));
}
static void
audio_player_speed_slider_changed_cb(void *data, Evas_Object *obj, void *event_info)
{
audio_player *mpd = data;
char buf[8];
/* */
double value = elm_slider_value_get(mpd->speed_popup_progress);
/* Update the UI */
sprintf(buf, "%.2fx", audio_player_convert_slider_rate(value));
elm_object_part_text_set(mpd->speed_popup_layout, "swallow.value", buf);
}
static double
audio_player_get_speed_value(audio_player *mpd)
{
// Note: 1.0 represents the normal speed, 2 double speed, 0.5 half speed and so on.
double rate = playback_service_get_play_speed(mpd->p_ps);
return 100 * (1 + log(rate) / log(4));
}
static void
audio_player_popup_playback_speed(audio_player *mpd)
{
Evas_Object *layout;
/* */
mpd->popup = elm_popup_add(intf_get_main_naviframe(mpd->intf));
elm_popup_orient_set(mpd->popup, ELM_POPUP_ORIENT_CENTER);
/* */
mpd->speed_popup_layout = layout = elm_layout_add(mpd->popup);
/* */
elm_layout_file_set(layout, AUDIOPLAYERSPEED_EDJ, "audio_player_speed");
evas_object_show(layout);
/* */
Evas_Object *slider = mpd->speed_popup_progress = elm_slider_add(layout);
elm_slider_horizontal_set(slider, EINA_TRUE);
elm_slider_min_max_set(slider, 0, 200);
elm_slider_value_set(slider, audio_player_get_speed_value(mpd));
elm_object_part_content_set(layout, "swallow.speed", slider);
evas_object_smart_callback_add(slider, "changed", audio_player_speed_slider_changed_cb, mpd);
evas_object_smart_callback_add(slider, "slider,drag,stop", audio_player_speed_slider_drag_stop_cb, mpd);
/* */
elm_object_content_set(mpd->popup, layout);
evas_object_show(mpd->popup);
}
static char *
gl_text_get_cb(void *data, Evas_Object *obj, const char *part)
......@@ -156,7 +228,7 @@ popup_selected_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
/* Update the button state (pressed or not) */
apd->mpd->more_state = false;
//TODO : Add a Playback Speed fcn of the current list
audio_player_popup_playback_speed(apd->mpd);
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment