Migrate Media::Player::Instance to rpl.
This commit is contained in:
parent
92e2b91f81
commit
74cfaff100
|
@ -634,11 +634,13 @@ HistoryWidget::HistoryWidget(
|
|||
}
|
||||
}, lifetime());
|
||||
|
||||
subscribe(Media::Player::instance()->switchToNextNotifier(), [this](const Media::Player::Instance::Switch &pair) {
|
||||
if (pair.from.type() == AudioMsgId::Type::Voice) {
|
||||
using MediaSwitch = Media::Player::Instance::Switch;
|
||||
Media::Player::instance()->switchToNextEvents(
|
||||
) | rpl::filter([=](const MediaSwitch &pair) {
|
||||
return (pair.from.type() == AudioMsgId::Type::Voice);
|
||||
}) | rpl::start_with_next([=](const MediaSwitch &pair) {
|
||||
scrollToCurrentVoiceMessage(pair.from.contextId(), pair.to);
|
||||
}
|
||||
});
|
||||
}, lifetime());
|
||||
|
||||
using PeerUpdateFlag = Data::PeerUpdate::Flag;
|
||||
session().changes().peerUpdates(
|
||||
|
|
|
@ -333,20 +333,8 @@ MainWidget::MainWidget(
|
|||
|
||||
QCoreApplication::instance()->installEventFilter(this);
|
||||
|
||||
subscribe(Media::Player::instance()->playerWidgetOver(), [this](bool over) {
|
||||
if (over) {
|
||||
if (_playerPlaylist->isHidden()) {
|
||||
auto position = mapFromGlobal(QCursor::pos()).x();
|
||||
auto bestPosition = _playerPlaylist->bestPositionFor(position);
|
||||
if (rtl()) bestPosition = position + 2 * (position - bestPosition) - _playerPlaylist->width();
|
||||
updateMediaPlaylistPosition(bestPosition);
|
||||
}
|
||||
_playerPlaylist->showFromOther();
|
||||
} else {
|
||||
_playerPlaylist->hideFromOther();
|
||||
}
|
||||
});
|
||||
subscribe(Media::Player::instance()->tracksFinishedNotifier(), [this](AudioMsgId::Type type) {
|
||||
Media::Player::instance()->tracksFinished(
|
||||
) | rpl::start_with_next([=](AudioMsgId::Type type) {
|
||||
if (type == AudioMsgId::Type::Voice) {
|
||||
const auto songState = Media::Player::instance()->getState(AudioMsgId::Type::Song);
|
||||
if (!songState.id || IsStoppedOrStopping(songState.state)) {
|
||||
|
@ -358,7 +346,7 @@ MainWidget::MainWidget(
|
|||
closeBothPlayers();
|
||||
}
|
||||
}
|
||||
});
|
||||
}, lifetime());
|
||||
|
||||
_controller->adaptive().changes(
|
||||
) | rpl::start_with_next([=] {
|
||||
|
@ -846,6 +834,21 @@ void MainWidget::createPlayer() {
|
|||
not_null<const HistoryItem*> item) {
|
||||
_controller->showPeerHistoryAtItem(item);
|
||||
});
|
||||
|
||||
_player->entity()->togglePlaylistRequests(
|
||||
) | rpl::start_with_next([=](bool shown) {
|
||||
if (!shown) {
|
||||
_playerPlaylist->hideFromOther();
|
||||
return;
|
||||
} else if (_playerPlaylist->isHidden()) {
|
||||
auto position = mapFromGlobal(QCursor::pos()).x();
|
||||
auto bestPosition = _playerPlaylist->bestPositionFor(position);
|
||||
if (rtl()) bestPosition = position + 2 * (position - bestPosition) - _playerPlaylist->width();
|
||||
updateMediaPlaylistPosition(bestPosition);
|
||||
}
|
||||
_playerPlaylist->showFromOther();
|
||||
}, _player->lifetime());
|
||||
|
||||
_playerVolume.create(this);
|
||||
Media::Player::PrepareVolumeDropdown(
|
||||
_playerVolume.data(),
|
||||
|
|
|
@ -299,12 +299,12 @@ FloatController::Item::Item(
|
|||
FloatController::FloatController(not_null<FloatDelegate*> delegate)
|
||||
: _delegate(delegate)
|
||||
, _parent(_delegate->floatPlayerWidget()) {
|
||||
subscribe(Media::Player::instance()->trackChangedNotifier(), [=](
|
||||
AudioMsgId::Type type) {
|
||||
if (type == AudioMsgId::Type::Voice) {
|
||||
Media::Player::instance()->trackChanged(
|
||||
) | rpl::filter([=](AudioMsgId::Type type) {
|
||||
return (type == AudioMsgId::Type::Voice);
|
||||
}) | rpl::start_with_next([=] {
|
||||
checkCurrent();
|
||||
}
|
||||
});
|
||||
}, _lifetime);
|
||||
|
||||
startDelegateHandling();
|
||||
}
|
||||
|
|
|
@ -262,6 +262,8 @@ private:
|
|||
rpl::event_stream<FullMsgId> _closeEvents;
|
||||
rpl::lifetime _delegateLifetime;
|
||||
|
||||
rpl::lifetime _lifetime;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Player
|
||||
|
|
|
@ -182,7 +182,7 @@ void Instance::setCurrent(const AudioMsgId &audioId) {
|
|||
data->migrated = nullptr;
|
||||
data->session = nullptr;
|
||||
}
|
||||
_trackChangedNotifier.notify(data->type, true);
|
||||
_trackChanged.fire_copy(data->type);
|
||||
refreshPlaylist(data);
|
||||
}
|
||||
}
|
||||
|
@ -369,7 +369,7 @@ bool Instance::moveInPlaylist(
|
|||
if (const auto media = item->media()) {
|
||||
if (const auto document = media->document()) {
|
||||
if (autonext) {
|
||||
_switchToNextNotifier.notify({
|
||||
_switchToNextStream.fire({
|
||||
data->current,
|
||||
item->fullId()
|
||||
});
|
||||
|
@ -558,8 +558,8 @@ void Instance::stop(AudioMsgId::Type type) {
|
|||
|
||||
void Instance::stopAndClear(not_null<Data*> data) {
|
||||
stop(data->type);
|
||||
_tracksFinishedNotifier.notify(data->type);
|
||||
*data = Data(data->type, data->overview);
|
||||
_tracksFinished.fire_copy(data->type);
|
||||
}
|
||||
|
||||
void Instance::playPause(AudioMsgId::Type type) {
|
||||
|
@ -744,15 +744,19 @@ void Instance::emitUpdate(AudioMsgId::Type type, CheckCallback check) {
|
|||
streamed->progress.updateState(state);
|
||||
}
|
||||
}
|
||||
auto finished = false;
|
||||
_updatedNotifier.fire_copy({state});
|
||||
if (data->isPlaying && state.state == State::StoppedAtEnd) {
|
||||
if (data->repeat.current() == RepeatMode::One) {
|
||||
play(data->current);
|
||||
} else if (!moveInPlaylist(data, 1, true)) {
|
||||
_tracksFinishedNotifier.notify(type);
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
data->isPlaying = !IsStopped(state.state);
|
||||
if (finished) {
|
||||
_tracksFinished.fire_copy(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -188,31 +188,30 @@ public:
|
|||
FullMsgId to;
|
||||
};
|
||||
|
||||
base::Observable<Switch> &switchToNextNotifier() {
|
||||
return _switchToNextNotifier;
|
||||
[[nodiscard]] rpl::producer<Switch> switchToNextEvents() const {
|
||||
return _switchToNextStream.events();
|
||||
}
|
||||
base::Observable<bool> &playerWidgetOver() {
|
||||
return _playerWidgetOver;
|
||||
[[nodiscard]] rpl::producer<AudioMsgId::Type> tracksFinished() const {
|
||||
return _tracksFinished.events();
|
||||
}
|
||||
base::Observable<AudioMsgId::Type> &tracksFinishedNotifier() {
|
||||
return _tracksFinishedNotifier;
|
||||
}
|
||||
base::Observable<AudioMsgId::Type> &trackChangedNotifier() {
|
||||
return _trackChangedNotifier;
|
||||
[[nodiscard]] rpl::producer<AudioMsgId::Type> trackChanged() const {
|
||||
return _trackChanged.events();
|
||||
}
|
||||
|
||||
rpl::producer<> playlistChanges(AudioMsgId::Type type) const;
|
||||
[[nodiscard]] rpl::producer<> playlistChanges(
|
||||
AudioMsgId::Type type) const;
|
||||
|
||||
rpl::producer<TrackState> updatedNotifier() const {
|
||||
[[nodiscard]] rpl::producer<TrackState> updatedNotifier() const {
|
||||
return _updatedNotifier.events();
|
||||
}
|
||||
|
||||
rpl::producer<> stops(AudioMsgId::Type type) const;
|
||||
rpl::producer<> startsPlay(AudioMsgId::Type type) const;
|
||||
[[nodiscard]] rpl::producer<> stops(AudioMsgId::Type type) const;
|
||||
[[nodiscard]] rpl::producer<> startsPlay(AudioMsgId::Type type) const;
|
||||
|
||||
rpl::producer<Seeking> seekingChanges(AudioMsgId::Type type) const;
|
||||
[[nodiscard]] rpl::producer<Seeking> seekingChanges(
|
||||
AudioMsgId::Type type) const;
|
||||
|
||||
bool pauseGifByRoundVideo() const;
|
||||
[[nodiscard]] bool pauseGifByRoundVideo() const;
|
||||
|
||||
void documentLoadProgress(DocumentData *document);
|
||||
|
||||
|
@ -323,11 +322,9 @@ private:
|
|||
Data _voiceData;
|
||||
bool _roundPlaying = false;
|
||||
|
||||
base::Observable<Switch> _switchToNextNotifier;
|
||||
base::Observable<bool> _playerWidgetOver;
|
||||
base::Observable<AudioMsgId::Type> _tracksFinishedNotifier;
|
||||
base::Observable<AudioMsgId::Type> _trackChangedNotifier;
|
||||
|
||||
rpl::event_stream<Switch> _switchToNextStream;
|
||||
rpl::event_stream<AudioMsgId::Type> _tracksFinished;
|
||||
rpl::event_stream<AudioMsgId::Type> _trackChanged;
|
||||
rpl::event_stream<AudioMsgId::Type> _playerStopped;
|
||||
rpl::event_stream<AudioMsgId::Type> _playerStartedPlay;
|
||||
rpl::event_stream<TrackState> _updatedNotifier;
|
||||
|
|
|
@ -324,23 +324,26 @@ Widget::Widget(QWidget *parent, not_null<Main::Session*> session)
|
|||
instance()->updateVoicePlaybackSpeed();
|
||||
}, lifetime());
|
||||
|
||||
subscribe(instance()->trackChangedNotifier(), [this](AudioMsgId::Type type) {
|
||||
if (type == _type) {
|
||||
instance()->trackChanged(
|
||||
) | rpl::filter([=](AudioMsgId::Type type) {
|
||||
return (type == _type);
|
||||
}) | rpl::start_with_next([=](AudioMsgId::Type type) {
|
||||
handleSongChange();
|
||||
updateControlsVisibility();
|
||||
updateLabelsGeometry();
|
||||
}
|
||||
});
|
||||
subscribe(instance()->tracksFinishedNotifier(), [this](AudioMsgId::Type type) {
|
||||
if (type == AudioMsgId::Type::Voice) {
|
||||
}, lifetime());
|
||||
|
||||
instance()->tracksFinished(
|
||||
) | rpl::filter([=](AudioMsgId::Type type) {
|
||||
return (type == AudioMsgId::Type::Voice);
|
||||
}) | rpl::start_with_next([=](AudioMsgId::Type type) {
|
||||
_voiceIsActive = false;
|
||||
const auto currentSong = instance()->current(AudioMsgId::Type::Song);
|
||||
const auto songState = instance()->getState(AudioMsgId::Type::Song);
|
||||
if (currentSong == songState.id && !IsStoppedOrStopping(songState.state)) {
|
||||
setType(AudioMsgId::Type::Song);
|
||||
}
|
||||
}
|
||||
});
|
||||
}, lifetime());
|
||||
|
||||
instance()->updatedNotifier(
|
||||
) | rpl::start_with_next([=](const TrackState &state) {
|
||||
|
@ -521,8 +524,7 @@ void Widget::updateOverLabelsState(bool over) {
|
|||
_labelsOver = over;
|
||||
auto pressShowsItem = _labelsOver && (_type == AudioMsgId::Type::Voice);
|
||||
setCursor(pressShowsItem ? style::cur_pointer : style::cur_default);
|
||||
auto showPlaylist = over && (_type == AudioMsgId::Type::Song);
|
||||
instance()->playerWidgetOver().notify(showPlaylist, true);
|
||||
_togglePlaylistRequests.fire(over && (_type == AudioMsgId::Type::Song));
|
||||
}
|
||||
|
||||
void Widget::updatePlayPrevNextPositions() {
|
||||
|
|
|
@ -50,12 +50,16 @@ public:
|
|||
void showShadow();
|
||||
void hideShadow();
|
||||
|
||||
QPoint getPositionForVolumeWidget() const;
|
||||
[[nodiscard]] QPoint getPositionForVolumeWidget() const;
|
||||
void volumeWidgetCreated(Dropdown *widget);
|
||||
|
||||
QPoint getPositionForRepeatWidget() const;
|
||||
[[nodiscard]] QPoint getPositionForRepeatWidget() const;
|
||||
void repeatWidgetCreated(Dropdown *widget);
|
||||
|
||||
[[nodiscard]] rpl::producer<bool> togglePlaylistRequests() const {
|
||||
return _togglePlaylistRequests.events();
|
||||
}
|
||||
|
||||
~Widget();
|
||||
|
||||
protected:
|
||||
|
@ -114,6 +118,7 @@ private:
|
|||
|
||||
bool _labelsOver = false;
|
||||
bool _labelsDown = false;
|
||||
rpl::event_stream<bool> _togglePlaylistRequests;
|
||||
|
||||
class PlayButton;
|
||||
class SpeedButton;
|
||||
|
|
|
@ -96,8 +96,7 @@ SystemMediaControlsManager::SystemMediaControlsManager(
|
|||
_lifetimeDownload.destroy();
|
||||
}, _lifetime);
|
||||
|
||||
auto trackChanged = base::ObservableViewer(
|
||||
mediaPlayer->trackChangedNotifier()
|
||||
auto trackChanged = mediaPlayer->trackChanged(
|
||||
) | rpl::filter([=](AudioMsgId::Type audioType) {
|
||||
return audioType == type;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue