a-m-h-t
a-m-h-t

Reputation: 1

Get the output device name in vlc

I want to get the names of the output devices in vlc. I use the audio_output_device_enum function but it does not give me the name of the main output device My code:

import vlc
p=vlc.MediaPlayer("music.mp3")
mods = p.audio_output_device_enum()
if mods:
    devices=[]
    mod = mods
    while mod:
        mod = mod.contents
        devices.append(mod.device)
        mod = mod.next
print(devices[1])

b'{0.0.0.00000000}.{152df11f-ed40-403e-8bf6-7916e2b74849}'

While I want to show me the original name, Speakers (High Definition Audio). How do I find the original output device name? thanks.

Upvotes: 0

Views: 632

Answers (1)

Rolf of Saxony
Rolf of Saxony

Reputation: 22443

audio_output_device_enum contains description in addition to device
There are caveats to audio_output_device_enum:

   @note: Not all audio outputs support enumerating devices.
   The audio output may be functional even if the list is empty (None).
   @note: The list may not be exhaustive.
   @warning: Some audio output devices in the list might not actually work in
   some circumstances.
import vlc
import time

p=vlc.MediaPlayer("vp.mp3")
mods = p.audio_output_device_enum()
if mods:
    devices=[]
    mod = mods
    while mod:
        mod = mod.contents
        devices.append([mod.device,mod.description])
        mod = mod.next
for d in devices:
    print(d)
p.play()
time.sleep(1)
while p.is_playing():
    time.sleep(1)

Output:

[b'alsa_output.pci-0000_00_1b.0.analog-stereo', b'Built-in Audio Analogue Stereo']

Upvotes: 1

Related Questions