Hey everyone! I have this following code. I’m building a media player with crossfading functionality. For that I’m using two vlc instances that play one song each. Everything is working so far, except the fade in of the next song. During fadein, the song will play a few samples at full volume, regardless of the audio_set_volume setting. I guess this has something to do with the buffering of the first samples, which will ignore the volume setting.
Here is some example code of how I did it, you can hear the fadein works, but only after playing a few ms on full volume:
Anyone have an idea how to solve this or is it a limitation of the vlc library?
Thanks!
import vlc import time # Simple VLC Player with fade-in class SimpleAudioPlayer: def __init__(self, audio_file): # Initialize VLC instance and media player self.instance = vlc.Instance() self.player = self.instance.media_player_new() self.audio_file = audio_file def play_fadein(self): # Load media media = self.instance.media_new(self.audio_file) self.player.set_media(media) # Set volume to 0 and mute before playback starts self.player.audio_set_volume(0) self.player.audio_set_mute(True) # Start playback print("Starting playback (muted)...") self.player.play() # Simulate fade-in by gradually increasing the volume print("Fade-in...") self.player.audio_set_mute(False) for volume in range(100): # Gradually increase volume self.player.audio_set_volume(volume) time.sleep(0.01) # Wait 10 ms between steps print("Playback running at full volume.") time.sleep(10) self.stop() def stop(self): # Stop playback self.player.stop() print("Playback stopped.") # Test the player if __name__ == "__main__": audio_file = "song.wav" player = SimpleAudioPlayer(audio_file) player.play_fadein()
submitted by /u/Healthy_Frosting_318
[link] [comments]
r/learnpython Hey everyone! I have this following code. I’m building a media player with crossfading functionality. For that I’m using two vlc instances that play one song each. Everything is working so far, except the fade in of the next song. During fadein, the song will play a few samples at full volume, regardless of the audio_set_volume setting. I guess this has something to do with the buffering of the first samples, which will ignore the volume setting. Here is some example code of how I did it, you can hear the fadein works, but only after playing a few ms on full volume: Anyone have an idea how to solve this or is it a limitation of the vlc library? Thanks! import vlc import time # Simple VLC Player with fade-in class SimpleAudioPlayer: def __init__(self, audio_file): # Initialize VLC instance and media player self.instance = vlc.Instance() self.player = self.instance.media_player_new() self.audio_file = audio_file def play_fadein(self): # Load media media = self.instance.media_new(self.audio_file) self.player.set_media(media) # Set volume to 0 and mute before playback starts self.player.audio_set_volume(0) self.player.audio_set_mute(True) # Start playback print(“Starting playback (muted)…”) self.player.play() # Simulate fade-in by gradually increasing the volume print(“Fade-in…”) self.player.audio_set_mute(False) for volume in range(100): # Gradually increase volume self.player.audio_set_volume(volume) time.sleep(0.01) # Wait 10 ms between steps print(“Playback running at full volume.”) time.sleep(10) self.stop() def stop(self): # Stop playback self.player.stop() print(“Playback stopped.”) # Test the player if __name__ == “__main__”: audio_file = “song.wav” player = SimpleAudioPlayer(audio_file) player.play_fadein() submitted by /u/Healthy_Frosting_318 [link] [comments]
Hey everyone! I have this following code. I’m building a media player with crossfading functionality. For that I’m using two vlc instances that play one song each. Everything is working so far, except the fade in of the next song. During fadein, the song will play a few samples at full volume, regardless of the audio_set_volume setting. I guess this has something to do with the buffering of the first samples, which will ignore the volume setting.
Here is some example code of how I did it, you can hear the fadein works, but only after playing a few ms on full volume:
Anyone have an idea how to solve this or is it a limitation of the vlc library?
Thanks!
import vlc import time # Simple VLC Player with fade-in class SimpleAudioPlayer: def __init__(self, audio_file): # Initialize VLC instance and media player self.instance = vlc.Instance() self.player = self.instance.media_player_new() self.audio_file = audio_file def play_fadein(self): # Load media media = self.instance.media_new(self.audio_file) self.player.set_media(media) # Set volume to 0 and mute before playback starts self.player.audio_set_volume(0) self.player.audio_set_mute(True) # Start playback print("Starting playback (muted)...") self.player.play() # Simulate fade-in by gradually increasing the volume print("Fade-in...") self.player.audio_set_mute(False) for volume in range(100): # Gradually increase volume self.player.audio_set_volume(volume) time.sleep(0.01) # Wait 10 ms between steps print("Playback running at full volume.") time.sleep(10) self.stop() def stop(self): # Stop playback self.player.stop() print("Playback stopped.") # Test the player if __name__ == "__main__": audio_file = "song.wav" player = SimpleAudioPlayer(audio_file) player.play_fadein()
submitted by /u/Healthy_Frosting_318
[link] [comments]