0

I'm trying to adjust the volume of an instance of vlc.MediaPlayer before playback. Running the below snippet (python3 test.py) plays five seconds of the audio file path/to/file.m4a. It appears that audio_set_volume does actually set the volume of the player, given that the subsequent print statement returns 10; but there's no practical change in volume (whether I set it lower or higher).

# test.py
import vlc 
from time import sleep
  
media_player = vlc.MediaPlayer("path/to/file.m4a") 
# Set the volume to 10%
media_player.audio_set_volume(10)
# Returns 10
print("Set volume: " + str(media_player.audio_get_volume()))
media_player.play() 
sleep(5) 

This similar question doesn't appear to have been resolved.

Versions:

Python==3.10.6
python-vlc==3.0.16120
heds1
  • 3,203
  • 2
  • 17
  • 32

1 Answers1

0

You didn't create a vlc.Instance() which probably won't help matters.

Try:

import vlc 
from time import sleep

instance = vlc.Instance()  
media_player = instance.media_player_new() 
media = instance.media_new('./vp1.mp3')
media_player.set_media(media)
media.parse()
media_player.audio_set_volume(30)
media_player.play()
print("Starting Volume "+ str(media_player.audio_get_volume()))
low = True
while True:
    sleep(5)
    if low:
        media_player.audio_set_volume(150)
        low = False
        print("vol 150")
    else:
        media_player.audio_set_volume(50)
        low = True
        print("vol 50")

See if you get any mileage from that?

Rolf of Saxony
  • 21,661
  • 5
  • 39
  • 60