I am new to python and trying to create GUI that take in user inout of video's name and play it in the frame of said GUI, when pasuse button click it show the error below.
[0000019acb774fe0] avcodec decoder error: hardware acceleration picture allocation failed
[h264 @ 0000019acb7c2580] get_buffer() failed
[h264 @ 0000019acb7c2580] thread_get_buffer() failed
[h264 @ 0000019acb7c2580] decode_slice_header error
[h264 @ 0000019acb7c2580] no frame!
After clicked pause and click play again the video is resuming but it was stuttered before resuming. This is my whole code.
import tkinter as tk
from tkinter import *
import pafy
import vlc
import re, requests, subprocess, urllib.parse, urllib.request
from bs4 import BeautifulSoup
class my_player():
def __init__(self, window):
self.window = window
window.title('My player GUI')
# Create frames
self.nameFrame = tk.Frame(window)
self.nameFrame.grid(row = 0, column = 0, sticky = N+W+S+E)
self.vidFrame = tk.Frame(window, width= 350, height= 400, bg= 'black')
self.vidFrame.grid(row = 0, column = 1, sticky = N+W+S+E)
self.buttonFrame = tk.Frame(window)
self.buttonFrame.grid(row = 1, column = 0, sticky = N+W+S+E)
self.volFrame = tk.Frame(window)
self.volFrame.grid(row = 0, column = 2, sticky = N+W+S+E)
# Create elements in each frames
# first song name Label
self.songLa = tk.Label(self.nameFrame, text = 'Song Name')
self.songLa.grid(row = 0, column = 0, sticky = W+E)
# then song name entry
self.songEn = tk.Entry(self.nameFrame, width = 30, border= 5)
self.songEn.grid(row = 1, column = 0, sticky = W+E)
self.enBu = tk.Button(self.nameFrame, text = 'SEARCH', relief= 'groove', width = 20, command = self.getName)
self.enBu.grid(row = 2, column = 0, sticky = N+W+S+E)
# second button elements
self.playBu = tk.Button(self.buttonFrame, text = 'PLAY', relief= 'groove', width= 20, command = self.play)
self.playBu.grid(row = 0, column = 0, sticky = N+W+S+E)
self.stopBu = tk.Button(self.buttonFrame, text = 'STOP', relief= 'groove', width= 20, command = self.stop)
self.stopBu.grid(row = 0, column = 1, sticky = N+W+S+E)
self.pauseBU = tk.Button(self.buttonFrame, text = 'PAUSE', relief= 'groove', width= 20, command= self.pause)
self.pauseBU.grid(row = 0, column = 2, sticky = N+W+S+E)
# third volume element
self.volSlide = tk.Scale(self.volFrame, from_ = 0, to = 100, orient = VERTICAL, border = 5)
self.volSlide.grid(row = 0, column = 0, sticky = N+W+S+E)
self.video = None
self.media = None
self.Instance = vlc.Instance()
self.media =self.Instance.media_player_new()
self.set_volume(50)
self.media.set_hwnd(self.vidFrame.winfo_id())
self.paused = False
self.playback_time = 0
def getName(self):
music_name = self.songEn.get()
query_string = urllib.parse.urlencode({"search_query": music_name})
formatUrl = urllib.request.urlopen("https://www.youtube.com/results?" + query_string)
search_results = re.findall(r"watch\?v=(\S{11})", formatUrl.read().decode())
self.clip = requests.get("https://www.youtube.com/watch?v=" + "{}".format(search_results[0]))
clip2 = "https://www.youtube.com/watch?v=" + "{}".format(search_results[0])
return clip2
def play(self):
play_song = self.getName()
# creating pafy object of the video
self.video = pafy.new(play_song)
# getting stream at index 0
best = self.video.streams[0]
# creating vlc media player object
#self.media = vlc.MediaPlayer()
self.setMedia = self.Instance.media_new(best.url)
self.media.set_media(self.setMedia)
# embedded video screen in GUI
self.set_volume(50)
self.media.play()
if self.paused:
self.media.set_time(self.playback_time)
self.paused = False
else:
# embedded video screen in GUI
self.media.play()
def pause(self):
self.playback_time = self.media.get_time()
self.media.pause()
self.paused = True
def stop(self):
pass
def set_volume(self, volume):
# set the volume of the media player
self.media.audio_set_volume(volume)
if __name__ == '__main__':
window = tk.Tk()
player = my_player(window)
window.mainloop()
And this is my pause button code.
def pause(self):
self.media.pause()
Thank you in advance for the answer. I tried searching from google and still not get it, I'm sorry in advance as this is my first time asking question hear.
As I'm new, I tried using google and try update my graphic card but still the same. What I am expecting is when click pause the video stop where it is and resume smoothly when click play again.