Adding the volume change function

We have already defined the volume method in the Player class. Now, all that you need to do is simply get the value of the Volume Scale widget and set the volume in the Player class.

Also, ensure that in case the volume becomes zero, we change the volume button icon to the mute image (see code 5.04view.py):

def on_volume_scale_changed(self, value):
self.player.volume = self.volume_scale.get()
if self.volume_scale.get() == 0.0:
self.mute_unmute_button.config(image=self.mute_icon)
else:
self.mute_unmute_button.config(image=self.unmute_icon)

This concludes the iteration. The player is now functional enough to be called an audio player. Go ahead and add some music files to the player. Press the play button and enjoy the music! Try out other player controls that we defined in this iteration and they should work as expected.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.9.148