2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Play streaming audio in player.

This commit is contained in:
John Preston
2019-03-01 01:03:25 +04:00
parent f1e0cd6c1d
commit fde8dd9607
44 changed files with 998 additions and 1445 deletions

View File

@@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/media_active_cache.h"
#include "core/mime_type.h"
#include "media/audio/media_audio.h"
#include "media/player/media_player_instance.h"
#include "storage/localstorage.h"
#include "platform/platform_specific.h"
#include "history/history.h"
@@ -27,9 +28,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/image/image_source.h"
#include "mainwindow.h"
#include "core/application.h"
// #TODO streaming ui
#include "media/streaming/media_streaming_player.h"
#include "media/streaming/media_streaming_loader_mtproto.h"
namespace {
@@ -294,52 +292,26 @@ void DocumentOpenClickHandler::Open(
ActionOnLoad action) {
if (!data->date) return;
auto msgId = context ? context->fullId() : FullMsgId();
bool playVoice = data->isVoiceMessage();
bool playMusic = data->isAudioFile();
bool playVideo = data->isVideoFile();
bool playAnimation = data->isAnimation();
auto &location = data->location(true);
if (data->isTheme()) {
if (!location.isEmpty() && location.accessEnable()) {
Core::App().showDocument(data, context);
location.accessDisable();
return;
}
}
if (data->canBePlayed()) {
const auto msgId = context ? context->fullId() : FullMsgId();
const auto playVoice = data->isVoiceMessage();
const auto playAnimation = data->isAnimation();
const auto &location = data->location(true);
if (data->isTheme() && !location.isEmpty() && location.accessEnable()) {
Core::App().showDocument(data, context);
location.accessDisable();
return;
} else if (data->canBePlayed()) {
if (data->isAudioFile()) {
Media::Player::instance()->playPause({ data, msgId });
} else {
Core::App().showDocument(data, context);
}
return;
}
if (!location.isEmpty() || (!data->data().isEmpty() && (playVoice || playMusic || playVideo || playAnimation))) {
if (!location.isEmpty() || (!data->data().isEmpty() && (playVoice || playAnimation))) {
using State = Media::Player::State;
if (playVoice) {
auto state = Media::Player::mixer()->currentState(AudioMsgId::Type::Voice);
if (state.id == AudioMsgId(data, msgId) && !Media::Player::IsStoppedOrStopping(state.state)) {
if (Media::Player::IsPaused(state.state) || state.state == State::Pausing) {
Media::Player::mixer()->resume(state.id);
} else {
Media::Player::mixer()->pause(state.id);
}
} else {
auto audio = AudioMsgId(data, msgId);
Media::Player::mixer()->play(audio);
Media::Player::Updated().notify(audio);
data->owner().markMediaRead(data);
}
} else if (playMusic) {
auto state = Media::Player::mixer()->currentState(AudioMsgId::Type::Song);
if (state.id == AudioMsgId(data, msgId) && !Media::Player::IsStoppedOrStopping(state.state)) {
if (Media::Player::IsPaused(state.state) || state.state == State::Pausing) {
Media::Player::mixer()->resume(state.id);
} else {
Media::Player::mixer()->pause(state.id);
}
} else {
auto song = AudioMsgId(data, msgId);
Media::Player::mixer()->play(song);
Media::Player::Updated().notify(song);
}
Media::Player::instance()->playPause({ data, msgId });
} else if (data->size < App::kImageSizeLimit) {
if (!data->data().isEmpty() && playAnimation) {
if (action == ActionOnLoadPlayInline && context) {
@@ -750,35 +722,8 @@ void DocumentData::performActionOnLoad() {
}
}
using State = Media::Player::State;
if (playVoice) {
if (loaded()) {
auto state = Media::Player::mixer()->currentState(AudioMsgId::Type::Voice);
if (state.id == AudioMsgId(this, _actionOnLoadMsgId) && !Media::Player::IsStoppedOrStopping(state.state)) {
if (Media::Player::IsPaused(state.state) || state.state == State::Pausing) {
Media::Player::mixer()->resume(state.id);
} else {
Media::Player::mixer()->pause(state.id);
}
} else if (Media::Player::IsStopped(state.state)) {
Media::Player::mixer()->play(AudioMsgId(this, _actionOnLoadMsgId));
_owner->markMediaRead(this);
}
}
} else if (playMusic) {
if (loaded()) {
auto state = Media::Player::mixer()->currentState(AudioMsgId::Type::Song);
if (state.id == AudioMsgId(this, _actionOnLoadMsgId) && !Media::Player::IsStoppedOrStopping(state.state)) {
if (Media::Player::IsPaused(state.state) || state.state == State::Pausing) {
Media::Player::mixer()->resume(state.id);
} else {
Media::Player::mixer()->pause(state.id);
}
} else if (Media::Player::IsStopped(state.state)) {
auto song = AudioMsgId(this, _actionOnLoadMsgId);
Media::Player::mixer()->play(song);
Media::Player::Updated().notify(song);
}
}
if (playVoice || playMusic) {
DocumentOpenClickHandler::Open({}, this, item, ActionOnLoadNone);
} else if (playAnimation) {
if (loaded()) {
if (_actionOnLoad == ActionOnLoadPlayInline && item) {

View File

@@ -173,9 +173,14 @@ bool ReplyPreview::empty() const {
} // namespace Data
uint32 AudioMsgId::CreateExternalPlayId() {
static auto Result = uint32(0);
return ++Result ? Result : ++Result;
}
AudioMsgId AudioMsgId::ForVideo() {
auto result = AudioMsgId();
result._playId = rand_value<uint32>();
result._externalPlayId = CreateExternalPlayId();
result._type = Type::Video;
return result;
}

View File

@@ -363,12 +363,14 @@ public:
AudioMsgId(
DocumentData *audio,
const FullMsgId &msgId,
uint32 playId = 0)
uint32 externalPlayId = 0)
: _audio(audio)
, _contextId(msgId)
, _playId(playId) {
, _externalPlayId(externalPlayId) {
setTypeFromAudio();
}
[[nodiscard]] static uint32 CreateExternalPlayId();
[[nodiscard]] static AudioMsgId ForVideo();
Type type() const {
@@ -380,8 +382,8 @@ public:
FullMsgId contextId() const {
return _contextId;
}
uint32 playId() const {
return _playId;
uint32 externalPlayId() const {
return _externalPlayId;
}
explicit operator bool() const {
@@ -394,7 +396,7 @@ private:
DocumentData *_audio = nullptr;
Type _type = Type::Unknown;
FullMsgId _contextId;
uint32 _playId = 0;
uint32 _externalPlayId = 0;
};
@@ -408,13 +410,13 @@ inline bool operator<(const AudioMsgId &a, const AudioMsgId &b) {
} else if (b.contextId() < a.contextId()) {
return false;
}
return (a.playId() < b.playId());
return (a.externalPlayId() < b.externalPlayId());
}
inline bool operator==(const AudioMsgId &a, const AudioMsgId &b) {
return (a.audio() == b.audio())
&& (a.contextId() == b.contextId())
&& (a.playId() == b.playId());
&& (a.externalPlayId() == b.externalPlayId());
}
inline bool operator!=(const AudioMsgId &a, const AudioMsgId &b) {