PDA

View Full Version : Set Volume Level on Embedded Linux with Qt 4.8



hakanaktanasis
26th June 2019, 13:13
Hi,

i am trying to set Volume Level using Phonon Library and VolumeSlider widget.
it works and changes the current volume level but after closing form and play a sound file, nothing changes in volume level.

here my code:

//on constructor of form:

mediaObject = new Phonon::MediaObject(this);
mediaObject->setCurrentSource(Phonon::MediaSource("/home/root/aaa.wav"));
audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);

Phonon::Path path = Phonon::createPath(mediaObject, audioOutput);

connect(audioOutput,SIGNAL(volumeChanged(qreal)),t his,SLOT(volumeChanged(qreal)));

volumeSlider = new Phonon::VolumeSlider;
volumeSlider->setAudioOutput(audioOutput);
ui->verticalLayoutSound->addWidget(volumeSlider,1,Qt::AlignCenter);
volumeSlider->setGeometry(0,0,200,30);
volumeSlider->setOrientation(Qt::Orientation::Vertical);
volumeSlider->setMouseTracking(true);
volumeSlider->setUpdatesEnabled(true);
volumeSlider->show();

//and slot:

void formDiagnostic::volumeChanged(qreal newLevel)
{
qreal volumeLevel = audioOutput->volume();
qDebug() << "Volume Changed To:" << volumeLevel;//this works
}

thanx in advance..

hakanaktanasis
12th July 2019, 11:38
i solved the problem parsing command with QProcess.
i used my sound device commands.
"amixer get PCM" to get the sound level information
"amixer set PCM 100%" to set the level information.