mirror of https://github.com/procxx/kepka.git
Save playback position in long audio files.
This commit is contained in:
parent
2637c860e9
commit
72d8cd7ef0
|
@ -42,8 +42,22 @@ constexpr auto kIdsLimit = 32;
|
|||
// Preload next messages if we went further from current than that.
|
||||
constexpr auto kIdsPreloadAfter = 28;
|
||||
|
||||
constexpr auto kMinLengthForSavePosition = 20 * TimeId(60); // 20 minutes.
|
||||
|
||||
} // namespace
|
||||
|
||||
struct Instance::Streamed {
|
||||
Streamed(
|
||||
AudioMsgId id,
|
||||
std::shared_ptr<Streaming::Document> document);
|
||||
|
||||
AudioMsgId id;
|
||||
Streaming::Instance instance;
|
||||
View::PlaybackProgress progress;
|
||||
bool clearing = false;
|
||||
rpl::lifetime lifetime;
|
||||
};
|
||||
|
||||
void start(not_null<Audio::Instance*> instance) {
|
||||
Audio::Start(instance);
|
||||
Capture::Start();
|
||||
|
@ -58,17 +72,23 @@ void finish(not_null<Audio::Instance*> instance) {
|
|||
Audio::Finish(instance);
|
||||
}
|
||||
|
||||
struct Instance::Streamed {
|
||||
Streamed(
|
||||
AudioMsgId id,
|
||||
std::shared_ptr<Streaming::Document> document);
|
||||
|
||||
AudioMsgId id;
|
||||
Streaming::Instance instance;
|
||||
View::PlaybackProgress progress;
|
||||
bool clearing = false;
|
||||
rpl::lifetime lifetime;
|
||||
};
|
||||
void SaveLastPlaybackPosition(
|
||||
not_null<DocumentData*> document,
|
||||
const TrackState &state) {
|
||||
const auto time = (state.position == kTimeUnknown
|
||||
|| state.length == kTimeUnknown
|
||||
|| state.state == State::PausedAtEnd
|
||||
|| IsStopped(state.state))
|
||||
? TimeId(0)
|
||||
: (state.length >= kMinLengthForSavePosition * state.frequency)
|
||||
? (state.position / state.frequency) * crl::time(1000)
|
||||
: TimeId(0);
|
||||
auto &session = document->session();
|
||||
if (session.settings().mediaLastPlaybackPosition(document->id) != time) {
|
||||
session.settings().setMediaLastPlaybackPosition(document->id, time);
|
||||
session.saveSettingsDelayed();
|
||||
}
|
||||
}
|
||||
|
||||
Instance::Streamed::Streamed(
|
||||
AudioMsgId id,
|
||||
|
@ -174,6 +194,9 @@ void Instance::clearStreamed(not_null<Data*> data) {
|
|||
return;
|
||||
}
|
||||
data->streamed->clearing = true;
|
||||
SaveLastPlaybackPosition(
|
||||
data->current.audio(),
|
||||
data->streamed->instance.player().prepareLegacyState());
|
||||
data->streamed->instance.stop();
|
||||
data->isPlaying = false;
|
||||
requestRoundVideoResize();
|
||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_shared_media.h"
|
||||
|
||||
class AudioMsgId;
|
||||
class DocumentData;
|
||||
|
||||
namespace Media {
|
||||
namespace Audio {
|
||||
|
@ -36,13 +37,17 @@ enum class Error;
|
|||
namespace Media {
|
||||
namespace Player {
|
||||
|
||||
class Instance;
|
||||
struct TrackState;
|
||||
|
||||
void start(not_null<Audio::Instance*> instance);
|
||||
void finish(not_null<Audio::Instance*> instance);
|
||||
|
||||
class Instance;
|
||||
Instance *instance();
|
||||
void SaveLastPlaybackPosition(
|
||||
not_null<DocumentData*> document,
|
||||
const TrackState &state);
|
||||
|
||||
struct TrackState;
|
||||
Instance *instance();
|
||||
|
||||
class Instance : private base::Subscriber {
|
||||
public:
|
||||
|
|
|
@ -81,8 +81,6 @@ constexpr auto kIdsLimit = 48;
|
|||
// Preload next messages if we went further from current than that.
|
||||
constexpr auto kIdsPreloadAfter = 28;
|
||||
|
||||
constexpr auto kMinLengthForSavePosition = 20 * TimeId(60); // 20 minutes.
|
||||
|
||||
Images::Options VideoThumbOptions(not_null<DocumentData*> document) {
|
||||
const auto result = Images::Option::Smooth | Images::Option::Blurred;
|
||||
return (document && document->isVideoMessage())
|
||||
|
@ -439,21 +437,9 @@ bool OverlayWidget::documentBubbleShown() const {
|
|||
|
||||
void OverlayWidget::clearStreaming(bool savePosition) {
|
||||
if (_streamed && _doc && savePosition) {
|
||||
using State = Media::Player::State;
|
||||
const auto state = _streamed->instance.player().prepareLegacyState();
|
||||
const auto time = (state.position == kTimeUnknown
|
||||
|| state.length == kTimeUnknown
|
||||
|| state.state == State::PausedAtEnd
|
||||
|| Media::Player::IsStopped(state.state))
|
||||
? TimeId(0)
|
||||
: (state.length >= kMinLengthForSavePosition * state.frequency)
|
||||
? (state.position / state.frequency) * crl::time(1000)
|
||||
: TimeId(0);
|
||||
auto &session = _doc->session();
|
||||
if (session.settings().mediaLastPlaybackPosition(_doc->id) != time) {
|
||||
session.settings().setMediaLastPlaybackPosition(_doc->id, time);
|
||||
session.saveSettingsDelayed();
|
||||
}
|
||||
Media::Player::SaveLastPlaybackPosition(
|
||||
_doc,
|
||||
_streamed->instance.player().prepareLegacyState());
|
||||
}
|
||||
_fullScreenVideo = false;
|
||||
_streamed = nullptr;
|
||||
|
|
Loading…
Reference in New Issue