how to embed a vlc instance in a tkinter frame

无人久伴 提交于 2019-12-08 04:20:01

问题


i wanna embed a vlc instance in a tkinter frame. already there is a similar code here that show a terminal in a tkinter window but i wanna show a vlc instead. here is my vlc code:

import vlc
Instance = vlc.Instance()
player = Instance.media_player_new()
Media = Instance.media_new('http://192.168.1.3:8080')
Media.add_option('network-caching=0')
player.set_media(Media)
player.play()

and here is simple tkinter code

try:
    # Python2
     from Tkinter import *
except ImportError:
    # Python3
    from tkinter import *
root = Tk()
root.geometry("380x480")
root.resizable(width=False, height=False)

frame1 = LabelFrame(root, width=459, height=300, bd=5)
frame1.grid(row=1, column=0, padx=10)

i want to show that vlc stream in this tkinter frame


回答1:


The VLC repo has a complete example for Tkinter.




回答2:


With python-vlc, and vlc player installed (I had to intall the 32 bits version)

    self.Instance = vlc.Instance()
    self.player = self.Instance.media_player_new()
    self.player.set_hwnd(self.label.winfo_id())#tkinter label or frame

    media = self.Instance.media_new(f)
    self.player.set_media(media)
    self.player.play()
    sleep(1.5)

    duration = self.player.get_length() / 1000
    sleep(duration-1.5)
    self.player.stop()


来源:https://stackoverflow.com/questions/47990695/how-to-embed-a-vlc-instance-in-a-tkinter-frame

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!