skip to Main Content

I need a function to play a video inside a window of tkinter, given only the url of the video. Moreover the video can be of any streaming platform. The only solution that i found is to use an external web pace to load the page with the video, but this isn’t my target

Read above. Thanks in advance for the answer.

2

Answers


  1. Your stated goal is infeasible.

    the video can be of any streaming platform.

    Tkinter doesn’t evaluate javascript.
    Many of those streaming platforms rely on JS
    for proper selection and playback of video,
    and to manipulate the DOM.
    You will want something like a browser
    if you intend to interact with such platforms.
    There are point solutions for a handful of
    bigger platforms, such as YouTube,
    that may work well in a tkinter widget.
    It is feasible for tkinter to send commands
    to Selenium, which in turn can control a browser.


    Consider focusing just on "playback of *.mp4 streams"
    within a tkinter app.
    The MPEG content could come from a local downloaded file
    or from TCP connection to an internet webserver.

    Login or Signup to reply.
  2. Description:

    You can easily play a video using an online url using the Python tkVideoPlayer library. Keep in mind that the url you are using should contain the address to the file itself with its format.

    Usage:

    If you are using Tkinter:

    import tkinter as tk
    from tkVideoPlayer import TkinterVideo
    
    root = tk.Tk()
    
    videoplayer = TkinterVideo(master=root, scaled=True)
    videoplayer.load(r"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")
    videoplayer.pack(expand=True, fill="both")
    
    videoplayer.play() # play the video
    
    root.mainloop()
    

    If you are using customtkiner:

    import customtkinter
    from tkVideoPlayer import TkinterVideo
    app = customtkinter.CTk()  # create CTk window like you do with the Tk window
    app.geometry("400x240")
    
    def button_function():
        video_player.play()
    
    video_player = TkinterVideo(master=app, scaled=True)
    video_player.pack(expand=True, fill='both')
    video_player.load("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")
    
    button = customtkinter.CTkButton(master=app, text="Play", command=button_function)
    button.pack()
    
    app.mainloop()
    

    Note:

    The package tkVideoPlayer isn’t installing properly and hence giving an error I would suggest you to import it locally and then use it.

    Proof:

    Video running on Tkinter:
    Video playback on TKinter

    Video running on customtkinter:
    Video Playback on customtkinter

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search