0

I am trying to finish my music app using tkinter and python. It streams a provided youtube link and plays it using the python-vlc library. But what i want is to control the time and duration of a playing song using the slider widget(Scale) and move it to jump to a specific time in the song.

I have no idea how to do that.

If anybody needs the code just let me know in the comments.

If possible can somebody help in adding volume controls using the slider to increase and decrease volume.

hoping somebody would help... this is the screenshot of the app working

Thanks, Sreeram.

Srm
  • 1
  • 1
  • See first answer here: https://stackoverflow.com/questions/47990695/how-to-embed-a-vlc-instance-in-a-tkinter-frame or go direct: https://git.videolan.org/?p=vlc/bindings/python.git;a=blob;f=examples/tkvlc.py;h=55314cab09948fc2b7c84f14a76c6d1a7cbba127;hb=HEAD – Rolf of Saxony Jan 08 '22 at 08:26
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jan 17 '22 at 02:20

1 Answers1

0

Good day,

Basically what you need to have is:

  1. A scale. timescale = Scale( (...)
  2. Setting the scale range every time a new song starts, something like this: timescale.config(to=item['duration'])
  3. A loop, for which you can use win.after(1000, timeloop). In the loop, you get the time of your player (time = player.get_time(), and then pass that time to the scale, like this: timescale.set(time)
  4. A function that sets the player time when you move the scale: player.set_time(timescale_var), with a check that the scale has actually been moved by the user, and not by the loop updating the time (therefor I put a minimum of 4000ms on the moving of the scale, otherwise it just doesn't update the player time)
  5. for the volume scale, it's more basic, youll see in the code below

I show you a little excerpt from my code, that does what you need. It is from a project of mine: https://github.com/floris-vos/gui-youtube-player

In that app, you'll find an implemented volume scale and time scale. Its a work in progress, currently I'm refactoring the code, and implementing some more things.

Relevant excerpts of code:

timescale = Scale(
    root, from_=0, to=1000,
    orient=HORIZONTAL, length=267,
    showvalue=0, command=timescale_move)
#above is your timescale - embedded in root for the example
timescale.pack()
#pcak it
volumescale = Scale(
    root, from_=200, to=0, orient=VERTICAL,
    showvalue=0,command=change_volume)
#here the volume scale, with a maximum volume of 200%
volumescale.set(100)
#it is set by default to 100% volume
volumescale.pack()
#pack it. 

def timeloop():
    time = player.get_time()
    #getting time from your player
    timescale.set(time)
    #setting the scale
    win.after(1000, timeloop)
    #looping

def change_volume(volume_var: int):
    player.audio_set_volume(int(volume_var))
    #setting volume. changing the volumescale automatically sends
    #a variable with the new value

def new_song():
    timescale.config(to=item['duration'])

def timescale_move(timescale_var):
    if abs(int(timescale_var) - player.get_time()) > 4000:
        player.set_time(int(timescale_var))
    #the if check is just to be sure that the scale was moved
    #a significant amount