mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 10:11:41 -05:00
Handle voice playlist in Media::Player::Instance.
This allows video and voice messages to autoplay one after another.
This commit is contained in:
parent
b9119e5ef6
commit
611a3e2f8a
8 changed files with 243 additions and 148 deletions
|
@ -1675,6 +1675,17 @@ void HistoryDocument::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool
|
||||||
HistoryFileMedia::clickHandlerPressedChanged(p, pressed);
|
HistoryFileMedia::clickHandlerPressedChanged(p, pressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HistoryDocument::playInline(bool autoplay) {
|
||||||
|
if (_data->voice()) {
|
||||||
|
DocumentOpenClickHandler::doOpen(_data, _parent, ActionOnLoadPlayInline);
|
||||||
|
return true;
|
||||||
|
} else if (_data->song()) {
|
||||||
|
Media::Player::instance()->play(AudioMsgId(_data, _parent->fullId()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void HistoryDocument::attachToParent() {
|
void HistoryDocument::attachToParent() {
|
||||||
App::regDocumentItem(_data, _parent);
|
App::regDocumentItem(_data, _parent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -411,6 +411,8 @@ public:
|
||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool playInline(bool autoplay) override;
|
||||||
|
|
||||||
void attachToParent() override;
|
void attachToParent() override;
|
||||||
void detachFromParent() override;
|
void detachFromParent() override;
|
||||||
|
|
||||||
|
|
|
@ -1604,7 +1604,7 @@ void MainWidget::closeBothPlayers() {
|
||||||
Media::Player::instance()->usePanelPlayer().notify(false, true);
|
Media::Player::instance()->usePanelPlayer().notify(false, true);
|
||||||
_playerPanel->hideIgnoringEnterEvents();
|
_playerPanel->hideIgnoringEnterEvents();
|
||||||
_playerPlaylist->hideIgnoringEnterEvents();
|
_playerPlaylist->hideIgnoringEnterEvents();
|
||||||
Media::Player::instance()->stop();
|
Media::Player::instance()->stop(AudioMsgId::Type::Song);
|
||||||
|
|
||||||
Shortcuts::disableMediaShortcuts();
|
Shortcuts::disableMediaShortcuts();
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,12 +102,12 @@ CoverWidget::CoverWidget(QWidget *parent) : TWidget(parent)
|
||||||
_playback->setValue(value, false);
|
_playback->setValue(value, false);
|
||||||
});
|
});
|
||||||
_playPause->setClickedCallback([this] {
|
_playPause->setClickedCallback([this] {
|
||||||
instance()->playPauseCancelClicked();
|
instance()->playPauseCancelClicked(AudioMsgId::Type::Song);
|
||||||
});
|
});
|
||||||
|
|
||||||
updateRepeatTrackIcon();
|
updateRepeatTrackIcon();
|
||||||
_repeatTrack->setClickedCallback([this] {
|
_repeatTrack->setClickedCallback([this] {
|
||||||
instance()->toggleRepeat();
|
instance()->toggleRepeat(AudioMsgId::Type::Song);
|
||||||
});
|
});
|
||||||
|
|
||||||
updateVolumeToggleIcon();
|
updateVolumeToggleIcon();
|
||||||
|
@ -232,7 +232,7 @@ void CoverWidget::updateLabelPositions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoverWidget::updateRepeatTrackIcon() {
|
void CoverWidget::updateRepeatTrackIcon() {
|
||||||
_repeatTrack->setIconOverride(instance()->repeatEnabled() ? nullptr : &st::mediaPlayerRepeatInactiveIcon);
|
_repeatTrack->setIconOverride(instance()->repeatEnabled(AudioMsgId::Type::Song) ? nullptr : &st::mediaPlayerRepeatInactiveIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoverWidget::handleSongUpdate(const TrackState &state) {
|
void CoverWidget::handleSongUpdate(const TrackState &state) {
|
||||||
|
@ -305,7 +305,7 @@ void CoverWidget::updateTimeLabel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoverWidget::handleSongChange() {
|
void CoverWidget::handleSongChange() {
|
||||||
auto ¤t = instance()->current();
|
auto ¤t = instance()->current(AudioMsgId::Type::Song);
|
||||||
auto song = current.audio()->song();
|
auto song = current.audio()->song();
|
||||||
if (!song) {
|
if (!song) {
|
||||||
return;
|
return;
|
||||||
|
@ -325,8 +325,8 @@ void CoverWidget::handleSongChange() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoverWidget::handlePlaylistUpdate() {
|
void CoverWidget::handlePlaylistUpdate() {
|
||||||
auto ¤t = instance()->current();
|
auto ¤t = instance()->current(AudioMsgId::Type::Song);
|
||||||
auto &playlist = instance()->playlist();
|
auto &playlist = instance()->playlist(AudioMsgId::Type::Song);
|
||||||
auto index = playlist.indexOf(current.contextId());
|
auto index = playlist.indexOf(current.contextId());
|
||||||
if (!current || index < 0) {
|
if (!current || index < 0) {
|
||||||
destroyPrevNextButtons();
|
destroyPrevNextButtons();
|
||||||
|
|
|
@ -49,7 +49,9 @@ void finish() {
|
||||||
Audio::Finish();
|
Audio::Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
Instance::Instance() {
|
Instance::Instance()
|
||||||
|
: _songData(AudioMsgId::Type::Song, OverviewMusicFiles)
|
||||||
|
, _voiceData(AudioMsgId::Type::Voice, OverviewRoundVoiceFiles) {
|
||||||
subscribe(Media::Player::Updated(), [this](const AudioMsgId &audioId) {
|
subscribe(Media::Player::Updated(), [this](const AudioMsgId &audioId) {
|
||||||
handleSongUpdate(audioId);
|
handleSongUpdate(audioId);
|
||||||
});
|
});
|
||||||
|
@ -80,18 +82,36 @@ Instance::Instance() {
|
||||||
handleAuthSessionChange();
|
handleAuthSessionChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AudioMsgId::Type Instance::getActiveType() const {
|
||||||
|
auto voiceData = getData(AudioMsgId::Type::Voice);
|
||||||
|
if (voiceData->current) {
|
||||||
|
auto state = mixer()->currentState(voiceData->type);
|
||||||
|
if (IsActive(state.state)) {
|
||||||
|
return voiceData->type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return AudioMsgId::Type::Song;
|
||||||
|
}
|
||||||
|
|
||||||
void Instance::notifyPeerUpdated(const Notify::PeerUpdate &update) {
|
void Instance::notifyPeerUpdated(const Notify::PeerUpdate &update) {
|
||||||
if (!_history) {
|
checkPeerUpdate(AudioMsgId::Type::Song, update);
|
||||||
|
checkPeerUpdate(AudioMsgId::Type::Voice, update);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Instance::checkPeerUpdate(AudioMsgId::Type type, const Notify::PeerUpdate &update) {
|
||||||
|
if (auto data = getData(type)) {
|
||||||
|
if (!data->history) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!(update.mediaTypesMask & (1 << OverviewMusicFiles))) {
|
if (!(update.mediaTypesMask & (1 << data->overview))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (update.peer != _history->peer && (!_migrated || update.peer != _migrated->peer)) {
|
if (update.peer != data->history->peer && (!data->migrated || update.peer != data->migrated->peer)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rebuildPlaylist();
|
rebuildPlaylist(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::handleSongUpdate(const AudioMsgId &audioId) {
|
void Instance::handleSongUpdate(const AudioMsgId &audioId) {
|
||||||
|
@ -101,98 +121,106 @@ void Instance::handleSongUpdate(const AudioMsgId &audioId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::setCurrent(const AudioMsgId &audioId) {
|
void Instance::setCurrent(const AudioMsgId &audioId) {
|
||||||
if (audioId.type() == AudioMsgId::Type::Song) {
|
if (auto data = getData(audioId.type())) {
|
||||||
if (_current != audioId) {
|
if (data->current != audioId) {
|
||||||
_current = audioId;
|
data->current = audioId;
|
||||||
_isPlaying = false;
|
data->isPlaying = false;
|
||||||
|
|
||||||
auto history = _history, migrated = _migrated;
|
auto history = data->history;
|
||||||
auto item = _current ? App::histItemById(_current.contextId()) : nullptr;
|
auto migrated = data->migrated;
|
||||||
|
auto item = data->current ? App::histItemById(data->current.contextId()) : nullptr;
|
||||||
if (item) {
|
if (item) {
|
||||||
_history = item->history()->peer->migrateTo() ? App::history(item->history()->peer->migrateTo()) : item->history();
|
data->history = item->history()->peer->migrateTo() ? App::history(item->history()->peer->migrateTo()) : item->history();
|
||||||
_migrated = _history->peer->migrateFrom() ? App::history(_history->peer->migrateFrom()) : nullptr;
|
data->migrated = data->history->peer->migrateFrom() ? App::history(data->history->peer->migrateFrom()) : nullptr;
|
||||||
} else {
|
} else {
|
||||||
_history = _migrated = nullptr;
|
data->history = nullptr;
|
||||||
|
data->migrated = nullptr;
|
||||||
}
|
}
|
||||||
_songChangedNotifier.notify(true);
|
_songChangedNotifier.notify(true);
|
||||||
if (_history != history || _migrated != migrated) {
|
if (data->history != history || data->migrated != migrated) {
|
||||||
rebuildPlaylist();
|
rebuildPlaylist(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (audioId.type() == AudioMsgId::Type::Voice) {
|
|
||||||
if (_currentVoice != audioId) {
|
|
||||||
_currentVoice = audioId;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::rebuildPlaylist() {
|
void Instance::rebuildPlaylist(Data *data) {
|
||||||
_playlist.clear();
|
Expects(data != nullptr);
|
||||||
if (_history && _history->loadedAtBottom()) {
|
|
||||||
auto &historyOverview = _history->overview[OverviewMusicFiles];
|
data->playlist.clear();
|
||||||
if (_migrated && _migrated->loadedAtBottom() && _history->loadedAtTop()) {
|
if (data->history && data->history->loadedAtBottom()) {
|
||||||
auto &migratedOverview = _migrated->overview[OverviewMusicFiles];
|
auto &historyOverview = data->history->overview[data->overview];
|
||||||
_playlist.reserve(migratedOverview.size() + historyOverview.size());
|
if (data->migrated && data->migrated->loadedAtBottom() && data->history->loadedAtTop()) {
|
||||||
|
auto &migratedOverview = data->migrated->overview[data->overview];
|
||||||
|
data->playlist.reserve(migratedOverview.size() + historyOverview.size());
|
||||||
for_const (auto msgId, migratedOverview) {
|
for_const (auto msgId, migratedOverview) {
|
||||||
_playlist.push_back(FullMsgId(_migrated->channelId(), msgId));
|
data->playlist.push_back(FullMsgId(data->migrated->channelId(), msgId));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_playlist.reserve(historyOverview.size());
|
data->playlist.reserve(historyOverview.size());
|
||||||
}
|
}
|
||||||
for_const (auto msgId, historyOverview) {
|
for_const (auto msgId, historyOverview) {
|
||||||
_playlist.push_back(FullMsgId(_history->channelId(), msgId));
|
data->playlist.push_back(FullMsgId(data->history->channelId(), msgId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_playlistChangedNotifier.notify(true);
|
_playlistChangedNotifier.notify(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::moveInPlaylist(int delta) {
|
void Instance::moveInPlaylist(Data *data, int delta) {
|
||||||
auto index = _playlist.indexOf(_current.contextId());
|
Expects(data != nullptr);
|
||||||
|
|
||||||
|
auto index = data->playlist.indexOf(data->current.contextId());
|
||||||
auto newIndex = index + delta;
|
auto newIndex = index + delta;
|
||||||
if (!_current || index < 0 || newIndex < 0 || newIndex >= _playlist.size()) {
|
if (!data->current || index < 0 || newIndex < 0 || newIndex >= data->playlist.size()) {
|
||||||
rebuildPlaylist();
|
rebuildPlaylist(data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto msgId = _playlist[newIndex];
|
auto msgId = data->playlist[newIndex];
|
||||||
if (auto item = App::histItemById(msgId)) {
|
if (auto item = App::histItemById(msgId)) {
|
||||||
if (auto media = item->getMedia()) {
|
if (auto media = item->getMedia()) {
|
||||||
if (auto document = media->getDocument()) {
|
media->playInline();
|
||||||
if (auto song = document->song()) {
|
|
||||||
play(AudioMsgId(document, msgId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Instance *instance() {
|
Instance *instance() {
|
||||||
t_assert(SingleInstance != nullptr);
|
Expects(SingleInstance != nullptr);
|
||||||
return SingleInstance;
|
return SingleInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::play() {
|
void Instance::play(AudioMsgId::Type type) {
|
||||||
auto state = mixer()->currentState(AudioMsgId::Type::Song);
|
auto state = mixer()->currentState(type);
|
||||||
if (state.id) {
|
if (state.id) {
|
||||||
if (IsStopped(state.state)) {
|
if (IsStopped(state.state)) {
|
||||||
mixer()->play(state.id);
|
play(state.id);
|
||||||
} else {
|
} else {
|
||||||
mixer()->resume(state.id);
|
mixer()->resume(state.id);
|
||||||
}
|
}
|
||||||
} else if (_current) {
|
} else if (auto data = getData(type)) {
|
||||||
mixer()->play(_current);
|
if (data->current) {
|
||||||
|
play(data->current);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::play(const AudioMsgId &audioId) {
|
void Instance::play(const AudioMsgId &audioId) {
|
||||||
if (!audioId || !audioId.audio()->song()) {
|
if (!audioId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (audioId.audio()->song() || audioId.audio()->voice()) {
|
||||||
mixer()->play(audioId);
|
mixer()->play(audioId);
|
||||||
setCurrent(audioId);
|
setCurrent(audioId);
|
||||||
if (audioId.audio()->loading()) {
|
if (audioId.audio()->loading()) {
|
||||||
documentLoadProgress(audioId.audio());
|
documentLoadProgress(audioId.audio());
|
||||||
}
|
}
|
||||||
|
} else if (audioId.audio()->isRoundVideo()) {
|
||||||
|
if (auto item = App::histItemById(audioId.contextId())) {
|
||||||
|
if (auto media = item->getMedia()) {
|
||||||
|
media->playInline();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::pause(AudioMsgId::Type type) {
|
void Instance::pause(AudioMsgId::Type type) {
|
||||||
|
@ -202,69 +230,71 @@ void Instance::pause(AudioMsgId::Type type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::stop() {
|
void Instance::stop(AudioMsgId::Type type) {
|
||||||
auto state = mixer()->currentState(AudioMsgId::Type::Song);
|
auto state = mixer()->currentState(type);
|
||||||
if (state.id) {
|
if (state.id) {
|
||||||
mixer()->stop(state.id);
|
mixer()->stop(state.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::playPause() {
|
void Instance::playPause(AudioMsgId::Type type) {
|
||||||
auto state = mixer()->currentState(AudioMsgId::Type::Song);
|
auto state = mixer()->currentState(type);
|
||||||
if (state.id) {
|
if (state.id) {
|
||||||
if (IsStopped(state.state)) {
|
if (IsStopped(state.state)) {
|
||||||
mixer()->play(state.id);
|
play(state.id);
|
||||||
} else if (IsPaused(state.state) || state.state == State::Pausing) {
|
} else if (IsPaused(state.state) || state.state == State::Pausing) {
|
||||||
mixer()->resume(state.id);
|
mixer()->resume(state.id);
|
||||||
} else {
|
} else {
|
||||||
mixer()->pause(state.id);
|
mixer()->pause(state.id);
|
||||||
}
|
}
|
||||||
} else if (_current) {
|
} else if (auto data = getData(type)) {
|
||||||
mixer()->play(_current);
|
if (data->current) {
|
||||||
|
play(data->current);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::next() {
|
void Instance::next(AudioMsgId::Type type) {
|
||||||
moveInPlaylist(1);
|
if (auto data = getData(type)) {
|
||||||
|
moveInPlaylist(data, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::previous() {
|
void Instance::previous(AudioMsgId::Type type) {
|
||||||
moveInPlaylist(-1);
|
if (auto data = getData(type)) {
|
||||||
|
moveInPlaylist(data, -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::playPauseCancelClicked() {
|
void Instance::playPauseCancelClicked(AudioMsgId::Type type) {
|
||||||
if (isSeeking(AudioMsgId::Type::Song)) {
|
if (isSeeking(type)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto state = mixer()->currentState(AudioMsgId::Type::Song);
|
auto state = mixer()->currentState(type);
|
||||||
auto stopped = (IsStopped(state.state) || state.state == State::Finishing);
|
auto stopped = (IsStopped(state.state) || state.state == State::Finishing);
|
||||||
auto showPause = !stopped && (state.state == State::Playing || state.state == State::Resuming || state.state == State::Starting);
|
auto showPause = !stopped && (state.state == State::Playing || state.state == State::Resuming || state.state == State::Starting);
|
||||||
auto audio = state.id.audio();
|
auto audio = state.id.audio();
|
||||||
if (audio && audio->loading()) {
|
if (audio && audio->loading()) {
|
||||||
audio->cancel();
|
audio->cancel();
|
||||||
} else if (showPause) {
|
} else if (showPause) {
|
||||||
pause(AudioMsgId::Type::Song);
|
pause(type);
|
||||||
} else {
|
} else {
|
||||||
play();
|
play(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::startSeeking(AudioMsgId::Type type) {
|
void Instance::startSeeking(AudioMsgId::Type type) {
|
||||||
if (type == AudioMsgId::Type::Song) {
|
if (auto data = getData(type)) {
|
||||||
_seeking = _current;
|
data->seeking = data->current;
|
||||||
} else if (type == AudioMsgId::Type::Voice) {
|
|
||||||
_seekingVoice = _currentVoice;
|
|
||||||
}
|
}
|
||||||
pause(type);
|
pause(type);
|
||||||
emitUpdate(type, [](const AudioMsgId &playing) { return true; });
|
emitUpdate(type, [](const AudioMsgId &playing) { return true; });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::stopSeeking(AudioMsgId::Type type) {
|
void Instance::stopSeeking(AudioMsgId::Type type) {
|
||||||
if (type == AudioMsgId::Type::Song) {
|
if (auto data = getData(type)) {
|
||||||
_seeking = AudioMsgId();
|
data->seeking = AudioMsgId();
|
||||||
} else if (type == AudioMsgId::Type::Voice) {
|
|
||||||
_seekingVoice = AudioMsgId();
|
|
||||||
}
|
}
|
||||||
emitUpdate(type, [](const AudioMsgId &playing) { return true; });
|
emitUpdate(type, [](const AudioMsgId &playing) { return true; });
|
||||||
}
|
}
|
||||||
|
@ -285,37 +315,39 @@ void Instance::emitUpdate(AudioMsgId::Type type, CheckCallback check) {
|
||||||
setCurrent(state.id);
|
setCurrent(state.id);
|
||||||
_updatedNotifier.notify(state, true);
|
_updatedNotifier.notify(state, true);
|
||||||
|
|
||||||
if (type == AudioMsgId::Type::Song) {
|
if (auto data = getData(type)) {
|
||||||
if (_isPlaying && state.state == State::StoppedAtEnd) {
|
if (data->isPlaying && state.state == State::StoppedAtEnd) {
|
||||||
if (_repeatEnabled) {
|
if (data->repeatEnabled) {
|
||||||
mixer()->play(_current);
|
play(data->current);
|
||||||
} else {
|
} else {
|
||||||
next();
|
next(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto isPlaying = !IsStopped(state.state);
|
auto isPlaying = !IsStopped(state.state);
|
||||||
if (_isPlaying != isPlaying) {
|
if (data->isPlaying != isPlaying) {
|
||||||
_isPlaying = isPlaying;
|
data->isPlaying = isPlaying;
|
||||||
if (_isPlaying) {
|
if (data->isPlaying) {
|
||||||
preloadNext();
|
preloadNext(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::preloadNext() {
|
void Instance::preloadNext(Data *data) {
|
||||||
if (!_current) {
|
Expects(data != nullptr);
|
||||||
|
|
||||||
|
if (!data->current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto index = _playlist.indexOf(_current.contextId());
|
auto index = data->playlist.indexOf(data->current.contextId());
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto nextIndex = index + 1;
|
auto nextIndex = index + 1;
|
||||||
if (nextIndex >= _playlist.size()) {
|
if (nextIndex >= data->playlist.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (auto item = App::histItemById(_playlist[nextIndex])) {
|
if (auto item = App::histItemById(data->playlist[nextIndex])) {
|
||||||
if (auto media = item->getMedia()) {
|
if (auto media = item->getMedia()) {
|
||||||
if (auto document = media->getDocument()) {
|
if (auto document = media->getDocument()) {
|
||||||
if (!document->loaded(DocumentData::FilePathResolveSaveFromDataSilent)) {
|
if (!document->loaded(DocumentData::FilePathResolveSaveFromDataSilent)) {
|
||||||
|
@ -327,14 +359,8 @@ void Instance::preloadNext() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::handleLogout() {
|
void Instance::handleLogout() {
|
||||||
_current = _seeking = AudioMsgId();
|
*getData(AudioMsgId::Type::Voice) = Data(AudioMsgId::Type::Voice, OverviewRoundVoiceFiles);
|
||||||
_history = nullptr;
|
*getData(AudioMsgId::Type::Song) = Data(AudioMsgId::Type::Song, OverviewMusicFiles);
|
||||||
_migrated = nullptr;
|
|
||||||
|
|
||||||
_repeatEnabled = _isPlaying = false;
|
|
||||||
|
|
||||||
_playlist.clear();
|
|
||||||
|
|
||||||
_usePanelPlayer.notify(false, true);
|
_usePanelPlayer.notify(false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,41 +38,69 @@ struct TrackState;
|
||||||
|
|
||||||
class Instance : private base::Subscriber {
|
class Instance : private base::Subscriber {
|
||||||
public:
|
public:
|
||||||
void play();
|
void play(AudioMsgId::Type type);
|
||||||
void pause(AudioMsgId::Type type);
|
void pause(AudioMsgId::Type type);
|
||||||
void stop();
|
void stop(AudioMsgId::Type type);
|
||||||
void playPause();
|
void playPause(AudioMsgId::Type type);
|
||||||
void next();
|
void next(AudioMsgId::Type type);
|
||||||
void previous();
|
void previous(AudioMsgId::Type type);
|
||||||
|
|
||||||
void playPauseCancelClicked();
|
void play() {
|
||||||
|
play(getActiveType());
|
||||||
|
}
|
||||||
|
void pause() {
|
||||||
|
pause(getActiveType());
|
||||||
|
}
|
||||||
|
void stop() {
|
||||||
|
stop(getActiveType());
|
||||||
|
}
|
||||||
|
void playPause() {
|
||||||
|
playPause(getActiveType());
|
||||||
|
}
|
||||||
|
void next() {
|
||||||
|
next(getActiveType());
|
||||||
|
}
|
||||||
|
void previous() {
|
||||||
|
previous(getActiveType());
|
||||||
|
}
|
||||||
|
|
||||||
|
void playPauseCancelClicked(AudioMsgId::Type type);
|
||||||
|
|
||||||
void play(const AudioMsgId &audioId);
|
void play(const AudioMsgId &audioId);
|
||||||
const AudioMsgId ¤t() const {
|
AudioMsgId current(AudioMsgId::Type type) const {
|
||||||
return _current;
|
if (auto data = getData(type)) {
|
||||||
|
return data->current;
|
||||||
|
}
|
||||||
|
return AudioMsgId();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool repeatEnabled() const {
|
bool repeatEnabled(AudioMsgId::Type type) const {
|
||||||
return _repeatEnabled;
|
if (auto data = getData(type)) {
|
||||||
|
return data->repeatEnabled;
|
||||||
}
|
}
|
||||||
void toggleRepeat() {
|
return false;
|
||||||
_repeatEnabled = !_repeatEnabled;
|
}
|
||||||
|
void toggleRepeat(AudioMsgId::Type type) {
|
||||||
|
if (auto data = getData(type)) {
|
||||||
|
data->repeatEnabled = !data->repeatEnabled;
|
||||||
_repeatChangedNotifier.notify();
|
_repeatChangedNotifier.notify();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool isSeeking(AudioMsgId::Type type) const {
|
bool isSeeking(AudioMsgId::Type type) const {
|
||||||
if (type == AudioMsgId::Type::Song) {
|
if (auto data = getData(type)) {
|
||||||
return (_seeking == _current);
|
return (data->seeking == data->current);
|
||||||
} else if (type == AudioMsgId::Type::Voice) {
|
|
||||||
return (_seekingVoice == _currentVoice);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
void startSeeking(AudioMsgId::Type type);
|
void startSeeking(AudioMsgId::Type type);
|
||||||
void stopSeeking(AudioMsgId::Type type);
|
void stopSeeking(AudioMsgId::Type type);
|
||||||
|
|
||||||
const QList<FullMsgId> &playlist() const {
|
QList<FullMsgId> playlist(AudioMsgId::Type type) const {
|
||||||
return _playlist;
|
if (auto data = getData(type)) {
|
||||||
|
return data->playlist;
|
||||||
|
}
|
||||||
|
return QList<FullMsgId>();
|
||||||
}
|
}
|
||||||
|
|
||||||
base::Observable<bool> &usePanelPlayer() {
|
base::Observable<bool> &usePanelPlayer() {
|
||||||
|
@ -105,29 +133,57 @@ private:
|
||||||
Instance();
|
Instance();
|
||||||
friend void start();
|
friend void start();
|
||||||
|
|
||||||
|
struct Data {
|
||||||
|
Data(AudioMsgId::Type type, MediaOverviewType overview) : type(type), overview(overview) {
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioMsgId::Type type;
|
||||||
|
MediaOverviewType overview;
|
||||||
|
AudioMsgId current;
|
||||||
|
AudioMsgId seeking;
|
||||||
|
History *history = nullptr;
|
||||||
|
History *migrated = nullptr;
|
||||||
|
bool repeatEnabled = false;
|
||||||
|
QList<FullMsgId> playlist;
|
||||||
|
bool isPlaying = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
AudioMsgId::Type getActiveType() const;
|
||||||
|
|
||||||
// Observed notifications.
|
// Observed notifications.
|
||||||
void notifyPeerUpdated(const Notify::PeerUpdate &update);
|
void notifyPeerUpdated(const Notify::PeerUpdate &update);
|
||||||
void handleSongUpdate(const AudioMsgId &audioId);
|
void handleSongUpdate(const AudioMsgId &audioId);
|
||||||
|
|
||||||
|
void checkPeerUpdate(AudioMsgId::Type type, const Notify::PeerUpdate &update);
|
||||||
void setCurrent(const AudioMsgId &audioId);
|
void setCurrent(const AudioMsgId &audioId);
|
||||||
void rebuildPlaylist();
|
void rebuildPlaylist(Data *data);
|
||||||
void moveInPlaylist(int delta);
|
void moveInPlaylist(Data *data, int delta);
|
||||||
void preloadNext();
|
void preloadNext(Data *data);
|
||||||
void handleLogout();
|
void handleLogout();
|
||||||
|
|
||||||
template <typename CheckCallback>
|
template <typename CheckCallback>
|
||||||
void emitUpdate(AudioMsgId::Type type, CheckCallback check);
|
void emitUpdate(AudioMsgId::Type type, CheckCallback check);
|
||||||
|
|
||||||
AudioMsgId _current, _seeking;
|
Data *getData(AudioMsgId::Type type) {
|
||||||
History *_history = nullptr;
|
if (type == AudioMsgId::Type::Song) {
|
||||||
History *_migrated = nullptr;
|
return &_songData;
|
||||||
|
} else if (type == AudioMsgId::Type::Voice) {
|
||||||
|
return &_voiceData;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool _repeatEnabled = false;
|
const Data *getData(AudioMsgId::Type type) const {
|
||||||
|
if (type == AudioMsgId::Type::Song) {
|
||||||
|
return &_songData;
|
||||||
|
} else if (type == AudioMsgId::Type::Voice) {
|
||||||
|
return &_voiceData;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
QList<FullMsgId> _playlist;
|
Data _songData;
|
||||||
bool _isPlaying = false;
|
Data _voiceData;
|
||||||
|
|
||||||
AudioMsgId _currentVoice, _seekingVoice;
|
|
||||||
|
|
||||||
base::Observable<bool> _usePanelPlayer;
|
base::Observable<bool> _usePanelPlayer;
|
||||||
base::Observable<bool> _titleButtonOver;
|
base::Observable<bool> _titleButtonOver;
|
||||||
|
|
|
@ -156,7 +156,7 @@ void ListWidget::itemRemoved(HistoryItem *item) {
|
||||||
|
|
||||||
QRect ListWidget::getCurrentTrackGeometry() const {
|
QRect ListWidget::getCurrentTrackGeometry() const {
|
||||||
auto top = marginTop();
|
auto top = marginTop();
|
||||||
auto current = instance()->current();
|
auto current = instance()->current(AudioMsgId::Type::Song);
|
||||||
auto fullMsgId = current.contextId();
|
auto fullMsgId = current.contextId();
|
||||||
for_const (auto layout, _list) {
|
for_const (auto layout, _list) {
|
||||||
auto layoutHeight = layout->height();
|
auto layoutHeight = layout->height();
|
||||||
|
@ -183,7 +183,7 @@ int ListWidget::marginTop() const {
|
||||||
void ListWidget::playlistUpdated() {
|
void ListWidget::playlistUpdated() {
|
||||||
auto newHeight = 0;
|
auto newHeight = 0;
|
||||||
|
|
||||||
auto &playlist = instance()->playlist();
|
auto &playlist = instance()->playlist(AudioMsgId::Type::Song);
|
||||||
auto playlistSize = playlist.size();
|
auto playlistSize = playlist.size();
|
||||||
auto existingSize = _list.size();
|
auto existingSize = _list.size();
|
||||||
if (playlistSize > existingSize) {
|
if (playlistSize > existingSize) {
|
||||||
|
|
|
@ -115,7 +115,7 @@ Widget::Widget(QWidget *parent) : TWidget(parent)
|
||||||
_playback->setValue(value, false);
|
_playback->setValue(value, false);
|
||||||
});
|
});
|
||||||
_playPause->setClickedCallback([this] {
|
_playPause->setClickedCallback([this] {
|
||||||
instance()->playPauseCancelClicked();
|
instance()->playPauseCancelClicked(AudioMsgId::Type::Song);
|
||||||
});
|
});
|
||||||
|
|
||||||
updateVolumeToggleIcon();
|
updateVolumeToggleIcon();
|
||||||
|
@ -128,7 +128,7 @@ Widget::Widget(QWidget *parent) : TWidget(parent)
|
||||||
|
|
||||||
updateRepeatTrackIcon();
|
updateRepeatTrackIcon();
|
||||||
_repeatTrack->setClickedCallback([this] {
|
_repeatTrack->setClickedCallback([this] {
|
||||||
instance()->toggleRepeat();
|
instance()->toggleRepeat(AudioMsgId::Type::Song);
|
||||||
});
|
});
|
||||||
|
|
||||||
subscribe(instance()->repeatChangedNotifier(), [this] {
|
subscribe(instance()->repeatChangedNotifier(), [this] {
|
||||||
|
@ -305,7 +305,7 @@ void Widget::updateLabelsGeometry() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::updateRepeatTrackIcon() {
|
void Widget::updateRepeatTrackIcon() {
|
||||||
auto repeating = instance()->repeatEnabled();
|
auto repeating = instance()->repeatEnabled(AudioMsgId::Type::Song);
|
||||||
_repeatTrack->setIconOverride(repeating ? nullptr : &st::mediaPlayerRepeatDisabledIcon, repeating ? nullptr : &st::mediaPlayerRepeatDisabledIconOver);
|
_repeatTrack->setIconOverride(repeating ? nullptr : &st::mediaPlayerRepeatDisabledIcon, repeating ? nullptr : &st::mediaPlayerRepeatDisabledIconOver);
|
||||||
_repeatTrack->setRippleColorOverride(repeating ? nullptr : &st::mediaPlayerRepeatDisabledRippleBg);
|
_repeatTrack->setRippleColorOverride(repeating ? nullptr : &st::mediaPlayerRepeatDisabledRippleBg);
|
||||||
}
|
}
|
||||||
|
@ -381,7 +381,7 @@ void Widget::updateTimeLabel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::handleSongChange() {
|
void Widget::handleSongChange() {
|
||||||
auto ¤t = instance()->current();
|
auto ¤t = instance()->current(AudioMsgId::Type::Song);
|
||||||
auto song = current.audio()->song();
|
auto song = current.audio()->song();
|
||||||
|
|
||||||
TextWithEntities textWithEntities;
|
TextWithEntities textWithEntities;
|
||||||
|
@ -398,8 +398,8 @@ void Widget::handleSongChange() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::handlePlaylistUpdate() {
|
void Widget::handlePlaylistUpdate() {
|
||||||
auto ¤t = instance()->current();
|
auto ¤t = instance()->current(AudioMsgId::Type::Song);
|
||||||
auto &playlist = instance()->playlist();
|
auto &playlist = instance()->playlist(AudioMsgId::Type::Song);
|
||||||
auto index = playlist.indexOf(current.contextId());
|
auto index = playlist.indexOf(current.contextId());
|
||||||
if (!current || index < 0) {
|
if (!current || index < 0) {
|
||||||
destroyPrevNextButtons();
|
destroyPrevNextButtons();
|
||||||
|
|
Loading…
Add table
Reference in a new issue