3

I am trying to set volume while playing an audio file but it doesn't seem to work at all. Please what am I doing wrong?

# create a vlc playable object from source
self.playable = vlc.libvlc_media_new_path(self.instance, sourceURL)


# create a new vlc player
self.player = vlc.libvlc_media_player_new_from_media(self.playable)

# play
vlc.libvlc_media_player_play(self.player)

while not self.stop:
 sleep(10)                              # sleep for a while to allow playback
 self.player.audio_set_volume(50)       # suppose to reduce volume. Doesn't work
 sleep(10)                              # sleep for a while to allow playback
 self.stop = True
Kennedy
  • 2,146
  • 6
  • 31
  • 44

1 Answers1

2

UPDATE try the following:

self.instance = vlc.Instance()
self.mediaplayer = self.instance.media_player_new()
self.media = self.instance.media_new(unicode(sourceURL))
self.mediaplayer.set_media(self.media)
self.media.parse()

while True :
    sleep(10)
    self.mediaplayer.audio_set_volume(50)

Example usage

Keep in mind that volume_level is an integer between 0 and 100, 100 will be equal to 0db.

Made a big edit because I think I originally misunderstood a bit. Does the video output work for you?

beiller
  • 3,105
  • 1
  • 11
  • 19
  • Thanks for your answer but it still doesn't solve the problem. I even set the volume_level to 0 and could still hear the audio play – Kennedy Sep 03 '13 at 20:32
  • the function libvlc_audio_set_volume returns a value. -1 on error, 0 on success. Can you test that value? a la code=libvlc_audio_set_volume(...) – beiller Sep 03 '13 at 21:35
  • 0 (success) was returned – Kennedy Sep 03 '13 at 22:45
  • what if you try adjusting the volume before starting playback? – beiller Sep 04 '13 at 05:12
  • yes, it works that way. What I want is to be able to change volume while the audio is already playing. I tried pausing the audio, changing volume and then play again but nothing changed. – Kennedy Sep 04 '13 at 10:52
  • Can you update your question to contain more context, IE what is self? I'm guessing this is a class function? It seems you have a bit of a context mixup. IE you should be calling self.player.media_player_play() (I actually don't know the correct function name here). – beiller Sep 05 '13 at 17:51
  • Still doesn't work even though calls to self.player.audio_get_volume() returns the new volume. self (like this) is a reference to the current class. I also tried self.player.play() but no difference. Thank you for your attempts to help – Kennedy Sep 06 '13 at 20:47