Q_LOGGING_CATEGORY(mpvBackend, "MPV")
Q_LOGGING_CATEGORY(mpvLog, "MPV Log")
+static constexpr const char VOLUME[] = "volume";
+
BackendMpv::BackendMpv(QObject *parent) : QObject{parent} {
#ifdef Q_OS_UNIX
setlocale(LC_NUMERIC, "C");
qCDebug(mpvBackend) << "register playback-time"
<< mpv_observe_property(m_handle, 0, "playback-time",
MPV_FORMAT_DOUBLE);
- qCDebug(mpvBackend) << "register ao-volume"
- << mpv_observe_property(m_handle, 0, "ao-volume",
+ qCDebug(mpvBackend) << "register" << VOLUME
+ << mpv_observe_property(m_handle, 0, VOLUME,
MPV_FORMAT_DOUBLE);
qCDebug(mpvBackend) << "request log messages"
<< mpv_request_log_messages(m_handle, "info");
+ {
+ double maxVolume = 130.0;
+ mpv_set_property(m_handle, "max-volume", MPV_FORMAT_DOUBLE, &maxVolume);
+ mpv_get_property(m_handle, "max-volume", MPV_FORMAT_DOUBLE, &maxVolume);
+ maxVolume /= 100.0;
+ m_player->playbackMaxVolumeChanged(maxVolume);
+ }
}
MpvInstance::~MpvInstance() {
void MpvInstance::setVolume(Volume volume) {
double percantageVolume = volume * 100;
- int error = mpv_set_property(m_handle, "ao-volume", MPV_FORMAT_DOUBLE,
- &percantageVolume);
+ int error =
+ mpv_set_property(m_handle, VOLUME, MPV_FORMAT_DOUBLE, &percantageVolume);
if (error) {
qCDebug(mpvBackend)
<< "Audio output not yet ready, setting volume at a later time";
m_player->playbackPositionChanged(
static_cast<PlayerPluginInterface::TimeStamp>(
readProperty<MPV_FORMAT_DOUBLE>(property)));
- } else if (strcmp(property->name, "ao-volume") == 0) {
+ } else if (strcmp(property->name, VOLUME) == 0) {
if (m_volumeToSet > 0) {
qCDebug(mpvBackend)
<< "Requested volume still not set, skipping this update";
Player::Volume Player::volume() const { return m_volume; }
+Player::Volume Player::maxVolume() const { return m_maxVolume; }
+
bool Player::muted() const { return m_muted; }
Player::AudioStreams Player::availableAudioStreams() const {
void Player::seek(Player::TimeStamp position) { m_backend->seek(position); }
void Player::setVolume(Volume volume) {
- volume = qBound(Volume{}, volume, MAX_VOLUME);
+ volume = qBound(Volume{}, volume, m_maxVolume);
m_backend->setVolume(volume);
}
if (qFuzzyCompare(m_position, position))
return;
- qCDebug(playerCategory) << "Duration changed to" << position;
+ qCDebug(playerCategory) << "Position changed to" << position;
m_position = position;
emit positionChanged(position);
}
void Player::playbackVolumeChanged(Player::Volume volume) {
- qCDebug(playerCategory) << "Volume changed to" << volume;
if (qFuzzyCompare(m_volume, volume))
return;
- qCDebug(playerCategory) << "Volume changed to!!" << volume;
+ qCDebug(playerCategory) << "Volume changed to" << volume;
m_volume = volume;
emit volumeChanged(volume);
}
+void Player::playbackMaxVolumeChanged(Player::Volume volume) {
+ if (qFuzzyCompare(m_maxVolume, volume))
+ return;
+
+ qCDebug(playerCategory) << "maxVolume changed to" << volume;
+ m_maxVolume = volume;
+ emit maxVolumeChanged(volume);
+}
+
void Player::streamsChanged() {}
void Player::reqisterQmlTypes() {
Q_PROPERTY(Player::PlayState state READ state NOTIFY stateChanged)
Q_PROPERTY(double volume READ volume WRITE setVolume NOTIFY volumeChanged)
+ Q_PROPERTY(double maxVolume READ maxVolume NOTIFY maxVolumeChanged)
Q_PROPERTY(bool muted READ muted WRITE setMuted NOTIFY mutedChanged)
Q_PROPERTY(Player::StreamIndex currentAudioStream READ currentAudioStream
PlayState state() const;
Volume volume() const;
+ Volume maxVolume() const;
bool muted() const;
StreamIndex currentAudioStream() const;
signals:
void stateChanged(PlayState state);
void volumeChanged(Volume volume);
+ void maxVolumeChanged(Volume maxVolume);
void mutedChanged(bool muted);
void availableAudioStreamsChanged(AudioStreams availableAudioStreams);
void playbackDurationChanged(TimeStamp) override;
void playbackPositionChanged(TimeStamp) override;
void playbackVolumeChanged(Volume) override;
+ void playbackMaxVolumeChanged(Volume) override;
void streamsChanged() override;
public:
QUrl m_nextSource;
PlayState m_state = PlayState::Stopped;
Volume m_volume = MAX_VOLUME;
+ Volume m_maxVolume = MAX_VOLUME;
AudioStreams m_availableAudioStreams;
StreamIndex m_currentAudioStream = StreamIndex{};
StreamIndex m_currentVideoStream = StreamIndex{};
virtual void playbackDurationChanged(TimeStamp) = 0;
virtual void playbackPositionChanged(TimeStamp) = 0;
virtual void playbackVolumeChanged(Volume) = 0;
+ virtual void playbackMaxVolumeChanged(Volume) = 0;
virtual void streamsChanged() = 0;
};
VolumeSlider {
height: fullscreenButton.height
width: 100
+ maxVolume: controlledPlayer ? controlledPlayer.maxVolume : 1
volume: controlledPlayer ? controlledPlayer.volume : 1
onVolumeChangeRequested: controlledPlayer.setVolume(volume)
}