void PlayerWidget::nextPressed() { if (isHidden()) return; History *history = _msgmigrated ? _migrated : _history; const History::MediaOverview *o = history ? &history->overview[OverviewAudioDocuments] : 0; if (audioPlayer() && o && _index >= 0 && _index < o->size() - 1) { startPlay(FullMsgId(history->channelId(), o->at(_index + 1))); } else if (o && (_index == o->size() - 1) && _msgmigrated && _history->overviewLoaded(OverviewAudioDocuments)) { o = &_history->overview[OverviewAudioDocuments]; if (!o->isEmpty()) { startPlay(FullMsgId(_history->channelId(), o->at(0))); } } }
void PlayerWidget::prevPressed() { if (isHidden()) return; History *history = _msgmigrated ? _migrated : _history; const History::MediaOverview *o = history ? &history->overview[OverviewAudioDocuments] : 0; if (audioPlayer() && o && _index > 0 && _index <= o->size() && !o->isEmpty()) { startPlay(FullMsgId(history->channelId(), o->at(_index - 1))); } else if (!_index && _history && _migrated && !_msgmigrated) { o = &_migrated->overview[OverviewAudioDocuments]; if (!o->isEmpty()) { startPlay(FullMsgId(_migrated->channelId(), o->at(o->size() - 1))); } } }
void PlayerWidget::mediaOverviewUpdated(PeerData *peer, MediaOverviewType type) { if (_history && (_history->peer == peer || (_migrated && _migrated->peer == peer)) && type == OverviewAudioDocuments) { _index = -1; History *history = _msgmigrated ? _migrated : _history; if (history->channelId() == _song.msgId.channel) { for (int i = 0, l = history->overview[OverviewAudioDocuments].size(); i < l; ++i) { if (history->overview[OverviewAudioDocuments].at(i) == _song.msgId.msg) { _index = i; preloadNext(); break; } } } updateControls(); } }
void PlayerWidget::preloadNext() { if (_index < 0) return; History *history = _msgmigrated ? _migrated : _history; const History::MediaOverview *o = &history->overview[OverviewAudioDocuments]; HistoryItem *next = 0; if (_index < o->size() - 1) { next = App::histItemById(history->channelId(), o->at(_index + 1)); } else if (_msgmigrated && _index == o->size() - 1 && _history->overviewLoaded(OverviewAudioDocuments) && _history->overviewCount(OverviewAudioDocuments) > 0) { next = App::histItemById(_history->channelId(), _history->overview[OverviewAudioDocuments].at(0)); } else if (_msgmigrated && _index == o->size() - 1 && !_history->overviewCountLoaded(OverviewAudioDocuments)) { if (App::main()) App::main()->preloadOverview(_history->peer, OverviewAudioDocuments); } if (next) { if (HistoryDocument *document = static_cast<HistoryDocument*>(next->getMedia())) { DocumentData *d = document->getDocument(); if (!d->loaded(true)) { DocumentOpenLink::doOpen(d, ActionOnLoadNone); } } } }