Sound plugins using pycanberra and gst-python
This commit is contained in:
parent
1f47a4060e
commit
53c3eeb8f7
3
setup.py
3
setup.py
|
@ -304,6 +304,9 @@ if __name__ == "__main__":
|
|||
'[gir, notify2]'
|
||||
],
|
||||
'bitmessage.notification.sound': [
|
||||
'theme.canberra = pybitmessage.plugins.sound_canberra',
|
||||
'file.gstreamer = pybitmessage.plugins.sound_gstreamer'
|
||||
'[gir]',
|
||||
'file.fallback = pybitmessage.plugins.sound_playfile'
|
||||
'[sound]'
|
||||
],
|
||||
|
|
21
src/plugins/sound_canberra.py
Normal file
21
src/plugins/sound_canberra.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from pybitmessage.bitmessageqt import sound
|
||||
|
||||
import pycanberra
|
||||
|
||||
_canberra = pycanberra.Canberra()
|
||||
|
||||
_theme = {
|
||||
sound.SOUND_UNKNOWN: 'message-new-email',
|
||||
sound.SOUND_CONNECTED: 'network-connectivity-established',
|
||||
sound.SOUND_DISCONNECTED: 'network-connectivity-lost',
|
||||
sound.SOUND_CONNECTION_GREEN: 'network-connectivity-established'
|
||||
}
|
||||
|
||||
|
||||
def connect_plugin(category, label=None):
|
||||
try:
|
||||
_canberra.play(0, pycanberra.CA_PROP_EVENT_ID, _theme[category], None)
|
||||
except (KeyError, pycanberra.CanberraException):
|
||||
pass
|
14
src/plugins/sound_gstreamer.py
Normal file
14
src/plugins/sound_gstreamer.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import gi
|
||||
gi.require_version('Gst', '1.0')
|
||||
from gi.repository import Gst # noqa: E402
|
||||
|
||||
Gst.init(None)
|
||||
_player = Gst.ElementFactory.make("playbin", "player")
|
||||
|
||||
|
||||
def connect_plugin(sound_file):
|
||||
_player.set_state(Gst.State.NULL)
|
||||
_player.set_property("uri", "file://" + sound_file)
|
||||
_player.set_state(Gst.State.PLAYING)
|
Reference in New Issue
Block a user