diff --git a/src/PlayerViewModel.cpp b/src/PlayerViewModel.cpp index 339e37d..541ca83 100644 --- a/src/PlayerViewModel.cpp +++ b/src/PlayerViewModel.cpp @@ -8,6 +8,8 @@ namespace winrt::Player::implementation { PlayerViewModel::PlayerViewModel() { volume_ = SettingsHelper::GetVolume(); + position_ = 0.; + duration_ = 0.; } double PlayerViewModel::Volume() { @@ -16,6 +18,24 @@ namespace winrt::Player::implementation uint32_t PlayerViewModel::Index() { return index_; } + double PlayerViewModel::Position() { + return position_; + } + void PlayerViewModel::Position(double value) { + if (value != position_) { + position_ = value; + propertyChanged_(*this, winrt::Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"Position" }); + } + } + double PlayerViewModel::Duration() { + return duration_; + } + void PlayerViewModel::Duration(double value) { + if (value != duration_) { + duration_ = value; + propertyChanged_(*this, winrt::Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"Duration" }); + } + } void PlayerViewModel::Index(uint32_t value) { if (value != index_) { index_ = value; @@ -32,6 +52,14 @@ namespace winrt::Player::implementation winrt::hstring PlayerViewModel::DoubleToString(double value) { return fast_io::wconcat_winrt_hstring(value); } + winrt::hstring PlayerViewModel::DurationToString(double value) { + auto const hms{ std::chrono::hh_mm_ss{std::chrono::nanoseconds{static_cast(value) * 100}} }; + auto hours{ hms.hours().count() }; + if (hours) + return fast_io::wconcat_winrt_hstring(fast_io::mnp::right(hours, 2, L'0'), fast_io::mnp::chvw(L':'), fast_io::mnp::right(hms.minutes().count(), 2, L'0'), fast_io::mnp::chvw(L':'), fast_io::mnp::right(hms.seconds().count(), 2, L'0')); + else + return fast_io::wconcat_winrt_hstring(fast_io::mnp::right(hms.minutes().count(), 2, L'0'), fast_io::mnp::chvw(L':'), fast_io::mnp::right(hms.seconds().count(), 2, L'0')); + } winrt::event_token PlayerViewModel::PropertyChanged(winrt::Microsoft::UI::Xaml::Data::PropertyChangedEventHandler const& handler) { return propertyChanged_.add(handler); diff --git a/src/PlayerViewModel.h b/src/PlayerViewModel.h index b31de46..be55377 100644 --- a/src/PlayerViewModel.h +++ b/src/PlayerViewModel.h @@ -10,12 +10,19 @@ namespace winrt::Player::implementation void Volume(double value); uint32_t Index(); void Index(uint32_t value); + double Position(); + void Position(double value); + double Duration(); + void Duration(double value); winrt::event_token PropertyChanged(winrt::Microsoft::UI::Xaml::Data::PropertyChangedEventHandler const& handler); void PropertyChanged(winrt::event_token const& token) noexcept; static winrt::hstring DoubleToString(double); + static winrt::hstring DurationToString(double); private: double volume_; uint32_t index_; + double position_; + double duration_; winrt::event propertyChanged_; }; } diff --git a/src/PlayerViewModel.idl b/src/PlayerViewModel.idl index ab7385d..a7f1139 100644 --- a/src/PlayerViewModel.idl +++ b/src/PlayerViewModel.idl @@ -7,6 +7,9 @@ namespace Player PlayerViewModel(); Double Volume; UInt32 Index; + Double Position; + Double Duration; static String DoubleToString(Double volume); + static String DurationToString(Double duration); } } diff --git a/src/RootPage.xaml b/src/RootPage.xaml index 7239f03..19dffcf 100644 --- a/src/RootPage.xaml +++ b/src/RootPage.xaml @@ -188,18 +188,23 @@ HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="11" - Text="0:00:00" /> + Text="{x:Bind local:PlayerViewModel.DurationToString(local:RootPage.PlayerViewModel.Position), Mode=OneWay}" /> + HorizontalAlignment="Stretch" + IsThumbToolTipEnabled="False" + Maximum="{x:Bind local:RootPage.PlayerViewModel.Duration, Mode=OneWay}" + StepFrequency="1000" + Value="{x:Bind local:RootPage.PlayerViewModel.Position, Mode=TwoWay}" /> + Text="{x:Bind local:PlayerViewModel.DurationToString(local:RootPage.PlayerViewModel.Duration), Mode=OneWay}" />