-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add slider in video player to control playback pos
- Loading branch information
Showing
16 changed files
with
251 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,62 @@ | ||
|
||
#include "network/item/duration.hpp" | ||
#include "Player.hpp" | ||
|
||
static const float MIN_TIME_WIDTH = 100; | ||
|
||
Player::Player(gana::NavigationManager &nav, std::shared_ptr<JellyfinClient> client, const Item &item) | ||
{ | ||
_player.set_source(client->get_stream_url(item.get_id())); | ||
_player.signal_file_loaded.connect(*this, &Player::on_file_loaded); | ||
add_child(&_player); | ||
set_process(); | ||
|
||
_ctn.add_spacer(8, true); | ||
|
||
_lbl_current_time.set_text("-"); | ||
_lbl_current_time.set_min_size(gana::Vector2f(MIN_TIME_WIDTH, 0)); | ||
_lbl_current_time.set_text_align(gana::BaseLabel::TextAlign::CENTER); | ||
_ctn_duration_bar.add_child(&_lbl_current_time); | ||
|
||
_slider_bar.signal_value_changed.connect(*this, &Player::on_slider_value_changed); | ||
_slider_bar.set_expand(); | ||
_ctn_duration_bar.add_child(&_slider_bar); | ||
|
||
_lbl_duration.set_text("-"); | ||
_lbl_duration.set_min_size(gana::Vector2f(MIN_TIME_WIDTH, 0)); | ||
_lbl_duration.set_text_align(gana::BaseLabel::TextAlign::CENTER); | ||
_ctn_duration_bar.add_child(&_lbl_duration); | ||
|
||
_ctn_duration_bar.set_hsizing(gana::Node::Sizing::FILL); | ||
_ctn_duration_bar.set_margin(16, 0, 16, 0); | ||
_ctn.add_child(&_ctn_duration_bar); | ||
|
||
_ctn.set_anchor(gana::Node::Anchor::FULL_RECT); | ||
add_child(&_ctn); | ||
|
||
set_anchor(gana::Node::Anchor::FULL_RECT); | ||
} | ||
|
||
Player::~Player() | ||
{} | ||
|
||
void Player::process() | ||
{ | ||
gana::Logger::info("time pos %d/%d", _player.get_time_pos(), _player.get_duration()); | ||
uint64_t time = _player.get_time_pos(); | ||
_slider_bar.set_value(time); | ||
_lbl_current_time.set_text(mpv_tick_to_duration(time)); | ||
} | ||
|
||
void Player::on_file_loaded() | ||
{ | ||
set_process(); | ||
uint64_t time = _player.get_time_pos(); | ||
_slider_bar.set_max_value(_player.get_duration()); | ||
_slider_bar.set_value(time); | ||
_lbl_current_time.set_text(mpv_tick_to_duration(time)); | ||
_lbl_duration.set_text(mpv_tick_to_duration(_player.get_duration())); | ||
} | ||
|
||
void Player::on_slider_value_changed(uint value) | ||
{ | ||
_player.set_time_pos(value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
#include "gana/theme/color.hpp" | ||
#include "gana/App.hpp" | ||
#include "Slider.hpp" | ||
|
||
static const gana::Vector2f MIN_SIZE = gana::Vector2f(20, 20); | ||
static const int BAR_HEIGTH = 12; | ||
|
||
Slider::Slider(): _value(0), _max_value(0), _percentage(0) | ||
{ | ||
set_min_size(MIN_SIZE); | ||
} | ||
|
||
Slider::~Slider() | ||
{} | ||
|
||
void Slider::draw(NVGcontext *ctx) | ||
{ | ||
float y = get_draw_positon().y + (get_draw_size().y - BAR_HEIGTH) / 2; | ||
nvgBeginPath(ctx); | ||
nvgRoundedRect(ctx, get_draw_positon().x, y, get_draw_size().x, BAR_HEIGTH, BAR_HEIGTH / 2); | ||
nvgFillColor(ctx, gana::Color(40, 40, 40, 225).nvg_color()); | ||
nvgFill(ctx); | ||
nvgBeginPath(ctx); | ||
nvgRoundedRect(ctx, get_draw_positon().x, y, get_draw_size().x * _percentage, BAR_HEIGTH, BAR_HEIGTH / 2); | ||
nvgFillColor(ctx, gana::theme::PRIMARY.nvg_color()); | ||
nvgFill(ctx); | ||
|
||
nvgBeginPath(ctx); | ||
nvgCircle(ctx, _center_sliding_point.x, _center_sliding_point.y, MIN_SIZE.y / 2); | ||
nvgFillColor(ctx, gana::Color(255, 40, 40).nvg_color()); | ||
nvgFill(ctx); | ||
} | ||
|
||
void Slider::process_event(gana::Event &evt) | ||
{ | ||
if (evt.is_touch_down() && evt.get_position().distance(_center_sliding_point) < MIN_SIZE.y) { | ||
_app->set_focused_node(this); | ||
evt.handle = true; | ||
} else if (has_focus() && (evt.type == sf::Event::TouchMoved || evt.type == sf::Event::MouseMoved)) { | ||
if (evt.get_position().x > get_draw_positon().x && evt.get_position().x < get_draw_positon().x + get_draw_size().x) { | ||
_percentage = (evt.get_position().x - get_draw_positon().x) / get_draw_size().x; | ||
_value = _max_value * _percentage; | ||
update_percentage(); | ||
} | ||
} else if (has_focus()) { | ||
signal_value_changed.emit(_value); | ||
_app->set_focused_node(nullptr); | ||
} | ||
} | ||
|
||
void Slider::set_max_value(uint value) | ||
{ | ||
if (has_focus()) | ||
return; | ||
_max_value = value; | ||
update_percentage(); | ||
} | ||
|
||
void Slider::set_value(uint value) | ||
{ | ||
if (has_focus()) | ||
return; | ||
_value = value; | ||
update_percentage(); | ||
} | ||
|
||
void Slider::update_percentage() | ||
{ | ||
_percentage = (float)_value / (float)_max_value; | ||
_center_sliding_point.x = get_draw_positon().x + get_draw_size().x * _percentage; | ||
_center_sliding_point.y = get_draw_positon().y + MIN_SIZE.y / 2; | ||
} |
Oops, something went wrong.