-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtestSound.py
More file actions
34 lines (29 loc) · 908 Bytes
/
testSound.py
File metadata and controls
34 lines (29 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python
import sys
from PyQt4 import QtGui, QtCore
from PyQt4.phonon import Phonon
"""make a sound """
class Window(QtGui.QPushButton):
def __init__(self):
QtGui.QPushButton.__init__(self, 'Play')
self.clicked.connect(self.play)
# make a MediaSource for this sound
self.mediaObject = Phonon.MediaObject()
self.audioOutput = Phonon.AudioOutput(Phonon.MusicCategory)
Phonon.createPath(self.mediaObject, self.audioOutput)
self.mediaSource = Phonon.MediaSource("sound/sound.wav")
def play(self, event):
if self.mediaObject.state() == Phonon.PlayingState:
print("stop")
self.mediaObject.stop()
else:
print("play")
self.mediaObject.setCurrentSource(self.mediaSource)
self.mediaObject.play()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
app.setApplicationName('Phonon')
win = Window()
win.resize(200, 100)
win.show()
sys.exit(app.exec_())