Added setting to control the output device in libVLC
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import config
|
||||
from utils import get_extractors
|
||||
from wxUI.configuration import configurationDialog
|
||||
from . import player
|
||||
|
||||
class configuration(object):
|
||||
|
||||
@@ -12,10 +13,16 @@ class configuration(object):
|
||||
self.save()
|
||||
|
||||
def create_config(self):
|
||||
self.view.create_general()
|
||||
self.output_devices = player.player.get_output_devices()
|
||||
self.view.create_general(output_devices=[i["name"] for i in self.output_devices])
|
||||
current_output_device = config.app["main"]["output_device"]
|
||||
for i in self.output_devices:
|
||||
# here we must compare against the str version of the vlc's device identifier.
|
||||
if str(i["id"]) == current_output_device:
|
||||
self.view.set_value("general", "output_device", i["name"])
|
||||
break
|
||||
extractors = get_extractors()
|
||||
for i in extractors:
|
||||
print(i)
|
||||
if hasattr(i, "settings"):
|
||||
panel = getattr(i, "settings")(self.view.notebook)
|
||||
self.view.notebook.AddPage(panel, panel.name)
|
||||
@@ -25,6 +32,18 @@ class configuration(object):
|
||||
self.view.realize()
|
||||
|
||||
def save(self):
|
||||
selected_output_device = self.view.get_value("general", "output_device")
|
||||
selected_device_id = None
|
||||
for i in self.output_devices:
|
||||
# Vlc returns everything as bytes object whereas WX works with string objects, so I need to convert the wx returned string to bytes before
|
||||
# Otherwise the comparison will be false.
|
||||
# toDo: Check if utf-8 would be enough or we'd have to use the fylesystem encode for handling this.
|
||||
if i["name"] == bytes(selected_output_device, "utf-8"):
|
||||
selected_device_id = i["id"]
|
||||
break
|
||||
if config.app["main"]["output_device"] != selected_device_id:
|
||||
config.app["main"]["output_device"] = selected_device_id
|
||||
player.player.set_output_device(config.app["main"]["output_device"])
|
||||
for i in range(0, self.view.notebook.GetPageCount()):
|
||||
page = self.view.notebook.GetPage(i)
|
||||
if hasattr(page, "save"):
|
||||
|
@@ -5,6 +5,7 @@ import random
|
||||
import vlc
|
||||
import logging
|
||||
import config
|
||||
import time
|
||||
from pubsub import pub
|
||||
from utils import call_threaded
|
||||
|
||||
@@ -33,6 +34,27 @@ class audioPlayer(object):
|
||||
self.event_manager.event_attach(vlc.EventType.MediaPlayerEndReached, self.end_callback)
|
||||
self.event_manager.event_attach(vlc.EventType.MediaPlayerEncounteredError, self.playback_error)
|
||||
log.debug("Bound media playback events.")
|
||||
# configure output device
|
||||
self.set_output_device(config.app["main"]["output_device"])
|
||||
|
||||
def get_output_devices(self):
|
||||
""" Retrieve enabled output devices so we can switch or use those later. """
|
||||
log.debug("Retrieving output devices...")
|
||||
devices = []
|
||||
mods = self.player.audio_output_device_enum()
|
||||
if mods:
|
||||
mod = mods
|
||||
while mod:
|
||||
mod = mod.contents
|
||||
devices.append(dict(id=mod.device, name=mod.description))
|
||||
mod = mod.next
|
||||
vlc.libvlc_audio_output_device_list_release(mods)
|
||||
return devices
|
||||
|
||||
def set_output_device(self, device_id):
|
||||
""" Set Output device to be ued in LibVLC"""
|
||||
log.debug("Setting output audio device to {device}...".format(device=device_id,))
|
||||
self.player.audio_output_device_set(None, device_id)
|
||||
|
||||
def play(self, item):
|
||||
self.stopped = True
|
||||
@@ -142,4 +164,5 @@ class audioPlayer(object):
|
||||
|
||||
def __del__(self):
|
||||
self.event_manager.event_detach(vlc.EventType.MediaPlayerEndReached)
|
||||
self.event_manager.event_detach(vlc.EventType.MediaPlayerEncounteredError, self.playback_error)
|
||||
if hasattr(self, "event_manager"):
|
||||
self.event_manager.event_detach(vlc.EventType.MediaPlayerEncounteredError, self.playback_error)
|
Reference in New Issue
Block a user