Show record init errors.

This commit is contained in:
John Preston 2024-10-18 18:59:47 +04:00
parent 7060c0e6d7
commit 302e9371c8
5 changed files with 38 additions and 5 deletions

View file

@ -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.";

View file

@ -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();

View file

@ -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<Error> {
return _errors.events();
}
bool VoiceRecordBar::isLockPresent() const {
return _lockShowing.current();
}

View file

@ -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<bool()>;
using Error = ::Media::Capture::Error;
VoiceRecordBar(
not_null<Ui::RpWidget*> parent,
@ -88,6 +93,7 @@ public:
[[nodiscard]] rpl::producer<not_null<QEvent*>> lockViewportEvents() const;
[[nodiscard]] rpl::producer<> updateSendButtonTypeRequests() const;
[[nodiscard]] rpl::producer<> recordingTipRequests() const;
[[nodiscard]] rpl::producer<Error> errors() const;
void requestToSendWithOptions(Api::SendOptions options);
@ -173,6 +179,7 @@ private:
rpl::event_stream<VoiceToSend> _sendVoiceRequests;
rpl::event_stream<> _cancelRequests;
rpl::event_stream<> _listenChanges;
rpl::event_stream<Error> _errors;
int _centerY = 0;
QRect _redCircleRect;

View file

@ -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(),