PDA

View Full Version : volume control



masuk
1st February 2011, 12:36
hi

i want to display windows volume control wizard with a button click. i also want to control volume (microphone and speaker) using slider.how to do these??

advance thanx

squidge
1st February 2011, 13:19
You could implement the IAudioVolumeLevel interface?

http://msdn.microsoft.com/en-us/library/dd371019%28v=vs.85%29.aspx

masuk
1st February 2011, 17:28
how to implement??
give some link or reference.

thanks

squidge
1st February 2011, 19:49
I included a link/reference in my post. Perhaps you missed it?

masuk
2nd February 2011, 08:47
how to implement in qt??

BalaQT
2nd February 2011, 09:53
hi masuk,

In windows XP u can use windows.h (api)

hope it helps
Bala

masuk
2nd February 2011, 11:16
hi bala
can you give sample source code??

squidge
2nd February 2011, 13:23
You implement as per any other COM object, using REFIID IID_IAudioVolumeLevel.

If you don't want the complexity of COM objects, then the best thing to do is just alter your own volume output only, rather than trying to adjust the system volume.

masuk
5th February 2011, 09:24
hi all,

i need Qt documentation/samples to solve.

thanks

aamer4yu
5th February 2011, 11:48
i need Qt documentation/samples to solve.
You mean you want working code ?

masuk
5th February 2011, 12:53
I need Qt documentation. how can i add windows api,how to adjust with slider.

thanks

squidge
5th February 2011, 13:20
You can use windows API calls in the same way regardless of whether you use Qt or not, as Qt is just another library that you use, like Win API.

Qt itself does not support altering the system volume control.

masuk
5th February 2011, 18:23
i tried this


#include "form1.h"
#include "ui_form1.h"

#include <phonon/AudioOutput>
#include <phonon/MediaObject>
#include <phonon/VolumeSlider>

Form1::Form1(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form1)
{
ui->setupUi(this);

connect(ui->horizontalSlider,SIGNAL(sliderMoved(int)),this,SLO T(setAudioOutput()));

Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory);
Phonon::createPath(mediaObject, audioOutput);

Phonon::VolumeSlider *volumeSlider = new Phonon::VolumeSlider;
volumeSlider->setAudioOutput(audioOutput);
}


but showing these errors:


cpp:59: undefined reference to `_imp___ZN6Phonon11MediaObjectC1EP7QObject'

cpp:60: undefined reference to `_imp___ZN6Phonon11AudioOutputC1ENS_8CategoryEP7QO bject'

cpp:61: undefined reference to `_imp___ZN6Phonon10createPathEPNS_9MediaNodeES1_'

cpp:61: undefined reference to `_imp___ZN6Phonon4PathD1Ev'

cpp:63: undefined reference to `_imp___ZN6Phonon12VolumeSliderC1EP7QWidget'

cpp:64: undefined reference to `_imp___ZN6Phonon12VolumeSlider14setAudioOutputEPN S_11AudioOutputE'

cpp:59: undefined reference to `_imp___ZN6Phonon11MediaObjectC1EP7QObject'

cpp:60: undefined reference to `_imp___ZN6Phonon11AudioOutputC1ENS_8CategoryEP7QO bject'

cpp:61: undefined reference to `_imp___ZN6Phonon10createPathEPNS_9MediaNodeES1_'

cpp:61: undefined reference to `_imp___ZN6Phonon4PathD1Ev'

cpp:63: undefined reference to `_imp___ZN6Phonon12VolumeSliderC1EP7QWidget'

cpp:64: undefined reference to `_imp___ZN6Phonon12VolumeSlider14setAudioOutputEPN S_11AudioOutputE'

collect2: ld returned 1 exit status



Is possible to solve in this way?

thanks

nish
5th February 2011, 18:31
did you made changes to your .pro file to link to phonon?

masuk
5th February 2011, 18:50
hi
thanks nish.
after link to phonon there is no error. but i can not solve my problem means when i moved slider(horizontal slider) it does not change the volume level of "windows volume control"

thanks

squidge
5th February 2011, 20:26
That is correct, phonon only changes the volume control of application. To change the system volume control, it is more difficult and requires WinAPI.

masuk
6th February 2011, 05:40
i tried this


#include "form1.h"
#include "ui_form1.h"

#include <phonon/AudioOutput>
#include <phonon/MediaObject>
#include <phonon/VolumeSlider>
#include <QLibrary>
#include <windows.h>

Form1::Form1(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form1)
{
ui->setupUi(this);
QLibrary myLib("C:/Windows/System32/MMSYSTEM.DLL");

myLib.load();

if (myLib.isLoaded())
{
connect(ui->horizontalSlider,SIGNAL(sliderMoved(int)),this,SLO T(setAudioOutput()));
}

//Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
//Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory);
//Phonon::createPath(mediaObject, audioOutput);
//mediaObject->setCurrentSource(Phonon::MediaSource("C:/Windows/Suiystem32/MMSYSTEM.DLL"));
//Phonon::VolumeSlider *volumeSlider = new Phonon::VolumeSlider;
//volumeSlider->setAudioOutput(audioOutput);
}

void Form1::showForm2() //<----error show here
{
Form2 *frm2 = new Form2; //<----error show here
frm2->show(); //<----error show here
}



As phonon only changes the volume control of application so i comments those lines.

But when use #include<windows.h> these errors shown:


form1.cpp: In member function 'void Form1::showForm2()':

form1.cpp:182: error: expected unqualified-id before numeric constant

form1.cpp:182: error: expected initializer before numeric constant

form1.cpp:183: error: base operand of '->' is not a pointer


this is .pro file


QT += core gui
QT += phonon

LIBS += -luser32 -lshell32 -lgdi32

TARGET = untitled2
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp \
form1.cpp

HEADERS += mainwindow.h \
form1.h

FORMS += mainwindow.ui \
form1.ui


my problem is not solved."is the signal and slot is right that i used for horizontal slider" and "is the selected .dll is right to solve my problem"?

thanks

squidge
6th February 2011, 09:57
Where is Form2 defined?

masuk
6th February 2011, 11:04
Hi squidge

actually in my program i defined #include "form2.h" but in post that missed.


#include "form1.h"
#include "ui_form1.h"
#include "form2.h"
#include <phonon/AudioOutput>
#include <phonon/MediaObject>
#include <phonon/VolumeSlider>
#include <QLibrary>
#include <windows.h>

Form1::Form1(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form1)
{
ui->setupUi(this);
QLibrary myLib("C:/Windows/System32/MMSYSTEM.DLL");

myLib.load();

if (myLib.isLoaded())
{
connect(ui->horizontalSlider,SIGNAL(sliderMoved(int)),this,SLO T(setAudioOutput()));
}

//Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
//Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory);
//Phonon::createPath(mediaObject, audioOutput);
//mediaObject->setCurrentSource(Phonon::MediaSource("C:/Windows/Suiystem32/MMSYSTEM.DLL"));
//Phonon::VolumeSlider *volumeSlider = new Phonon::VolumeSlider;
//volumeSlider->setAudioOutput(audioOutput);
}

void Form1::showForm2() //<----error show here
{
Form2 *frm2 = new Form2; //<----error show here
frm2->show(); //<----error show here
}


but my problem is not solved.....:(

thanks

squidge
6th February 2011, 11:48
Ok, I'm confused. The error is on line 182, but there are only 36 lines in your post.

Secondly, what is content of Form2.h ?

masuk
6th February 2011, 12:20
hi
i only posted the reqired code. this is my full code:
form1.cpp


#include "form1.h"
#include "ui_form1.h"

#include "form2.h"

#include <QPixmap>
#include <QPalette>
#include <QDesktopWidget>
#include <QRect>
#include <QSize>
#include <QApplication>

//#include <QIcon>

#include <QMouseEvent>


#include <phonon/MediaObject>
#include <phonon/AudioOutput>
#include <phonon/VolumeSlider>
#include <QLibrary>
#include <windows.h>

Form1::Form1(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form1)
{
ui->setupUi(this);

connect(ui->pushButton_24,SIGNAL(clicked()),this,SLOT(showMini mized()));

// These three line is used for remove 'window title bar'
this->setWindowFlags(Qt::MSWindowsFixedSizeDialogHint);
this->setWindowFlags(Qt::CustomizeWindowHint);
this->setWindowFlags(Qt::FramelessWindowHint);


//this->setWindowFlags(Qt::SplashScreen);

//background image using 'pixmap' and 'palette'
this->setFixedSize(270,350);

QPixmap pixmap1("E:/workplace/image/two.JPG");
QPalette p = palette();

//resize image if it is larger than screen size.
QDesktopWidget* desktopWidget = QApplication::desktop();
QRect rect = desktopWidget->availableGeometry();

QSize size(rect.width() , rect.height());
//resize as per your requirement..
//QPixmap pixmap(pixmap1.scaled(size));
QPixmap pixmap(pixmap1.scaled(270,350));

p.setBrush(QPalette::Background, pixmap);
setPalette(p);

//ui->pushButton->setIcon(QIcon("E:/workplace/image/01.gif"));


//connect(ui->horizontalSlider,SIGNAL(volumeChanged(Phonon::Medi aObject,Phonon::AudioOutput)),
//this,SLOT(setVolumeDecibel(Phonon::MediaObject,Pho non::AudioOutput)));


QLibrary myLib("C:/Windows/System32/MMSYSTEM.DLL");

myLib.load();

if (myLib.isLoaded())
{
connect(ui->horizontalSlider,SIGNAL(sliderMoved(int)),this,SLO T(setAudioOutput()));
}

//Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
//Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory);
//Phonon::createPath(mediaObject, audioOutput);
//mediaObject->setCurrentSource(Phonon::MediaSource("C:/Windows/Suiystem32/MMSYSTEM.DLL"));
//Phonon::VolumeSlider *volumeSlider = new Phonon::VolumeSlider;
//volumeSlider->setAudioOutput(audioOutput);

}

Form1::~Form1()
{
delete ui;
}

void Form1::one()
{
text1+="1";
//text1+=ui->pushButton->text();
ui->lineEdit->setText(text1);
}

void Form1::two()
{
text1+="2";
//text1+=ui->pushButton_4->text();
ui->lineEdit->setText(text1);
}

void Form1::three()
{
text1+="3";
//text1+=ui->pushButton_3->text();
ui->lineEdit->setText(text1);
}

void Form1::four()
{
text1+="4";
//text1+=ui->pushButton_2->text();
ui->lineEdit->setText(text1);
}

void Form1::five()
{
text1+="5";
//text1+=ui->pushButton_5->text();
ui->lineEdit->setText(text1);
}

void Form1::six()
{
text1+="6";
//text1+=ui->pushButton_6->text();
ui->lineEdit->setText(text1);
}

void Form1::seven()
{
text1+="7";
//text1+=ui->pushButton_7->text();
ui->lineEdit->setText(text1);
}

void Form1::eight()
{
text1+="8";
//text1+=ui->pushButton_8->text();
ui->lineEdit->setText(text1);
}

void Form1::nine()
{
text1+="9";
//text1+=ui->pushButton_9->text();
ui->lineEdit->setText(text1);
}

void Form1::star()
{
text1+="*";
//text1+=ui->pushButton_10->text();
ui->lineEdit->setText(text1);
}

void Form1::zero()
text1+="0";
//text1+=ui->pushButton_11->text();
ui->lineEdit->setText(text1);
}

void Form1::hash()
{
text1+="#";
//text1+=ui->pushButton_12->text();
ui->lineEdit->setText(text1);
}

void Form1::clear()
{
text1 = "";
ui->lineEdit->clear();
}

void Form1::showForm2()
{
Form2 *frm2 = new Form2;
frm2->show();
//this->close();
//this->destroy();

}


void Form1::closeSecondWindow()
{
this->close();
}

void Form1::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton)
{
move(event->globalPos() - m_dragPosition);
event->accept();
}
}
void Form1::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
m_dragPosition = event->globalPos() - frameGeometry().topLeft();
event->accept();
}
}


i have another form named form2.this is not matter. i need to access the windows volume control with sliders(horizontal slider)

squidge
6th February 2011, 16:09
I don't see any code for accessing windows volume control, and I don't see any definitions for Form2, which is probably why the compiler is complaining.

masuk
10th February 2011, 06:25
i can't get any solution for control system volume level. as phonon use only for control application volume.i need source code how to control system(xp,vista,linux) volume using slider(horizontal slider).

thanks