diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 70ad59585..5478c34fc 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -3248,6 +3248,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_record_lock_discard" = "Discard"; "lng_record_voice_tip" = "Hold to record audio. Click to switch to video."; "lng_record_video_tip" = "Hold to record video. Click to switch to audio."; +"lng_record_audio_problem" = "Could not start audio recording. Please check your microphone."; +"lng_record_video_problem" = "Could not start video recording. Please check your camera."; "lng_record_once_first_tooltip" = "Click to set this message to **Play Once**."; "lng_record_once_active_tooltip" = "The recipient will be able to listen only once."; "lng_will_be_notified" = "Subscribers will be notified when you post."; diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 0170f1a88..aab9559ca 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -2429,6 +2429,24 @@ void ComposeControls::initVoiceRecordBar() { } }, _wrap->lifetime()); + _voiceRecordBar->errors( + ) | rpl::start_with_next([=](::Media::Capture::Error error) { + using Error = ::Media::Capture::Error; + switch (error) { + case Error::AudioInit: + case Error::AudioTimeout: + _show->showToast(tr::lng_record_audio_problem(tr::now)); + break; + case Error::VideoInit: + case Error::VideoTimeout: + _show->showToast(tr::lng_record_video_problem(tr::now)); + break; + default: + _show->showToast(u"Unknown error."_q); + break; + } + }, _wrap->lifetime()); + _voiceRecordBar->updateSendButtonTypeRequests( ) | rpl::start_with_next([=] { updateSendButtonType(); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp index 87c2147e0..436e38167 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp @@ -50,9 +50,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace HistoryView::Controls { namespace { -using SendActionUpdate = VoiceRecordBar::SendActionUpdate; -using VoiceToSend = VoiceRecordBar::VoiceToSend; - constexpr auto kAudioVoiceUpdateView = crl::time(200); constexpr auto kAudioVoiceMaxLength = 100 * 60; // 100 minutes constexpr auto kMaxSamples @@ -1703,8 +1700,9 @@ void VoiceRecordBar::startRecording() { if (update.finished) { stop(update.samples >= kMinSamples); } - }, [=] { + }, [=](Error error) { stop(false); + _errors.fire_copy(error); }, _recordingLifetime); } _recordingLifetime.add([=] { @@ -2025,6 +2023,10 @@ rpl::producer<> VoiceRecordBar::recordingTipRequests() const { return _recordingTipRequests.events(); } +auto VoiceRecordBar::errors() const -> rpl::producer { + return _errors.events(); +} + bool VoiceRecordBar::isLockPresent() const { return _lockShowing.current(); } diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h index 3d6f1a878..c2db218bf 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h @@ -21,6 +21,10 @@ namespace style { struct RecordBar; } // namespace style +namespace Media::Capture { +enum class Error : uchar; +} // namespace Media::Capture + namespace Ui { class AbstractButton; class SendButton; @@ -57,6 +61,7 @@ public: using SendActionUpdate = Controls::SendActionUpdate; using VoiceToSend = Controls::VoiceToSend; using FilterCallback = Fn; + using Error = ::Media::Capture::Error; VoiceRecordBar( not_null parent, @@ -88,6 +93,7 @@ public: [[nodiscard]] rpl::producer> lockViewportEvents() const; [[nodiscard]] rpl::producer<> updateSendButtonTypeRequests() const; [[nodiscard]] rpl::producer<> recordingTipRequests() const; + [[nodiscard]] rpl::producer errors() const; void requestToSendWithOptions(Api::SendOptions options); @@ -173,6 +179,7 @@ private: rpl::event_stream _sendVoiceRequests; rpl::event_stream<> _cancelRequests; rpl::event_stream<> _listenChanges; + rpl::event_stream _errors; int _centerY = 0; QRect _redCircleRect; diff --git a/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp b/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp index 26c75ce83..12dc6fd93 100644 --- a/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp +++ b/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp @@ -26,7 +26,8 @@ constexpr auto kUpdateEach = crl::time(100); constexpr auto kAudioFrequency = 48'000; constexpr auto kAudioBitRate = 32'000; constexpr auto kVideoBitRate = 3 * 1024 * 1024; -constexpr auto kMaxDuration = 10 * crl::time(1000); +constexpr auto kMinDuration = crl::time(200); +constexpr auto kMaxDuration = 60 * crl::time(1000); constexpr auto kInitTimeout = 5 * crl::time(1000); using namespace FFmpeg; @@ -384,6 +385,9 @@ RoundVideoResult RoundVideoRecorder::Private::finish() { return {}; } finishEncoding(); + if (_resultDuration < kMinDuration) { + return {}; + } return { .content = _result, .waveform = QByteArray(),