0

I am trying to make a media explorer using the vlc-python library and tkinter. But I keep getting multiple errors. There errors occur in seemingly random order and only after pressing Left or Right. Pressing these buttons multiple times quickly sometimes causes the program to crash. Folder contains only images and videos. I am just including the unique errors :-

[000001e7a8e0b2a0] cache_read stream error: cannot pre fill buffer
[000001e7ae098ee0] mjpeg demux error: cannot peek
[000001e7ae286d30] direct3d11 vout display error: SetThumbNailClip failed: 0x800706f4
[000001e7b6be89f0] avcodec decoder: Using D3D11VA (Intel(R) HD Graphics 5500, vendor 8086(Intel), device 1616, revision 9) for hardware decoding
[h264 @ 000001e7a90b1040] get_buffer() failed
[h264 @ 000001e7a90b1040] thread_get_buffer() failed
[h264 @ 000001e7a90b1040] decode_slice_header error
[000001e7ae0fcbc0] direct3d11 vout display error: SetThumbNailClip failed: 0x800706f4
[000001dceaa2c890] mmdevice audio output error: cannot initialize COM (error 0x80010106)

Sometimes when I play videos, the playback continually lags and the following error is logged every time it lags,

[h264 @ 000001e7a90b1040] get_buffer() failed
[h264 @ 000001e7a90b1040] thread_get_buffer() failed
[h264 @ 000001e7a90b1040] decode_slice_header error

The code:

from time import sleep
import vlc
import tkinter as Tk
from tkinter import ttk
from tkinter.filedialog import askdirectory
import os


class Player(Tk.Frame):
    def __init__(self, parent, title=None):
        Tk.Frame.__init__(self, parent)

        self.base = ""
        self.files = ""
        self.currFile = -1
        self.parent = parent

        if title == None:
            title = "Project"
        self.parent.title(title)

        self.videopanel = ttk.Frame(self.parent)
        self.canvas = Tk.Canvas(self.videopanel).pack(fill=Tk.BOTH, expand=1)
        self.videopanel.pack(fill=Tk.BOTH, expand=1)

        self.sortOptions = ttk.Frame(self.parent)
        ttk.Button(self.sortOptions, text="Open...",
                   command=self.OnOpen).pack(side=Tk.LEFT)
        self.sortOptions.pack(side=Tk.BOTTOM)

        self.player = None

    def OnOpen(self):
        self.OnStop()
        currfolder = next(os.walk(askdirectory()))
        self.base = currfolder[0]
        self.files = []
        for file in currfolder[2]:
            if(file.endswith(('.png', '.jpg', '.jpeg', '.gif', '.mp4', '.mkv', '.mp3'))):
                self.files.append(file)
        
        for child in self.sortOptions.winfo_children():
            child.destroy()

        self.player = vlc.Instance().media_player_new()
        self.player.set_hwnd(self.videopanel.winfo_id())

        self.parent.bind("<Right>", lambda e: self.nextFile(e))
        self.parent.bind("<Left>", lambda e: self.nextFile(e, False))
        
        self.nextFile()

    def nextFile(self, event=None, next=True):
        self.OnStop()

        if(next):
            self.currFile += 1
            if(self.currFile == len(self.files)):
                self.currFile = 0
        else:
            self.currFile -= 1
            if(self.currFile == -1):
                self.currFile = len(self.files)-1

        filePath = os.path.join(self.base, self.files[self.currFile])

        self.player.set_media(vlc.Media(filePath))

        self.OnPlay()
        return

    def errorDialog(self, errormessage):
        Tk.tkMessageBox.showerror(self, 'Error', errormessage)

    def OnPlay(self):
        if not self.player.get_media():
            self.OnOpen()
        else:
            if self.player.play() == -1:
                self.errorDialog("Unable to play.")

    def OnStop(self):
        if(self.player):
            pass
            self.player.pause()


def Tk_get_root():
    if not hasattr(Tk_get_root, "root"):
        Tk_get_root.root = Tk.Tk()
    return Tk_get_root.root


def _quit():
    print("_quit: bye")
    root = Tk_get_root()
    root.quit()
    root.destroy()
    os._exit(1)


if __name__ == "__main__":
    root = Tk_get_root()
    root.protocol("WM_DELETE_WINDOW", _quit)

    player = Player(root, title="Project")
    root.mainloop()

FieryRMS
  • 91
  • 3
  • 11
  • Have you checked what is in `self.files`? I see nothing obvious in the code to suggest that you are limiting the file types to audio/video. – Rolf of Saxony Feb 08 '22 at 19:49
  • @RolfofSaxony I made some edits to my code with the advice you gave, but it still didn't make any changes. – FieryRMS Feb 10 '22 at 03:14

0 Answers0