System volume control with Python, QT : PySide.phonon.Phonon.AudioOutputDevice
I would like to access (r/w) the Master Volume Control. I am currently using Windows 7.
There are "low-level" possibilities of controlling it: Vista/win7 application volume control interface
An older variant uses ctypes
and Windows DLL:
http://mail.python.org/pipermail/python-win32/2006-March/004436.html
and probably derived work (requires pymedia
):
http:// code.google.com/p/palarm/downloads/detail?name=alarmwaveout.py&can=2&q=
For cross-platform this doesn't work anyway, so I thought of using a toolkit. QT, pyQT or PySide came to mind, as I've been wanting to experiment with QT:
#!/usr/bin/python
import sys
from PySide.QtCore import *
from PySide.QtGui import *
import PySide.phonon
app = QApplication(sys.argv)
devicelist = PySide.phonon.Phonon.BackendCapabilities.availableAudioOutputDevices()
print "Listing available audio output devices:"
for device in devicelist:
print " device:", device
print " description:", device.description()
print " index:", device.index()
print " isValid:", device.isValid()
print " name:", devi开发者_StackOverflow中文版ce.name()
print " property:", device.property( str( device.name() ) )
print " propertyNames:", device.propertyNames()
print
#~ audiodev = PySide.phonon.Phonon.AudioOutput()
#~ slider = PySide.phonon.Phonon.VolumeSlider(audiodev)
slider = PySide.phonon.Phonon.VolumeSlider( None )
slider.setOrientation( Qt.Vertical )
slider.show()
app.exec_()
sys.exit()
But I don't understand how to connect the VolumeSlider to an audio device (in this case, the Master ("Speakers") or default).
精彩评论