I'm trying to build a music player using Python Tkinter, but I really facing issues while I set the song path it seems some errors.
Here is my code:
song = song_box.get(ACTIVE)
song = f'C:/Users/parve/PycharmProjects/gf/songs/{song}.ogg'
pygame.mixer.music.load(song)
pygame.mixer.music.play(loops=0)
Here is the error I face:
File "C:/Users/parve/PycharmProjects/gf/music.py", line 25, in play
pygame.mixer.music.load(song)
pygame.error: Failed loading libvorbisfile-3.dll: The specified module could not be found.
Related
Recently I have created a python script to play youtube videos using pafy and python-vlc.
The below code is the script:
# importing vlc module
import vlc
# importing pafy module
import pafy
# url of the video
url = "https://www.youtube.com/watchv=il_t1WVLNxk&list=PLqM7alHXFySGqCvcwfqqMrteqWukz9ZoE"
# creating pafy object of the video
video = pafy.new(url)
# getting stream at index 0
best = video.streams[0]
# creating vlc media player object
media = vlc.MediaPlayer(best.url)
# start playing video
media.play()
And after running it I get this error:
Traceback (most recent call last):
File "C:\Users\harsh\Desktop\don't.py", line 11, in <module>
video = pafy.new(url)
File "C:\Users\harsh\AppData\Local\Programs\Python\Python310\lib\site-
packages\pafy\pafy.py", line 124, in new
return Pafy(url, basic, gdata, size, callback, ydl_opts=ydl_opts)
File "C:\Users\harsh\AppData\Local\Programs\Python\Python310\lib\site-
packages\pafy\backend_youtube_dl.py", line 31, in __init__
super(YtdlPafy, self).__init__(*args, **kwargs)
File "C:\Users\harsh\AppData\Local\Programs\Python\Python310\lib\site-
packages\pafy\backend_shared.py", line 97, in __init__
self._fetch_basic()
File "C:\Users\harsh\AppData\Local\Programs\Python\Python310\lib\site-
packages\pafy\backend_youtube_dl.py", line 54, in _fetch_basic
self._dislikes = self._ydl_info['dislike_count']
KeyError: 'dislike_count'
Please help me with this error. If you have any questions please ask.
The dislike button on youtube has been made private, so some modification on backend_youtube_dl.py is required to run pafy.
Navigate to C:\Users\harsh\AppData\Local\Programs\Python\Python310\lib\site-
packages\pafy
Open backend_youtube_dl.py file
Comment or remove this code: self._dislikes = self._ydl_info['dislike_count']
Besides the dislike function, everything else works fine.
It worked for me and hope the same goes for everyone.
Pafy its very usefull tool if you want to extract information about youtube video like, retrieve metadata such as viewcount, duration, rating, author, thumbnail, keywords or Download video or audio at requested resolution.
But it doesnt work(at least untill now) to play a video.
If you want to play a Yt video inside your code use it:
import webbrowser
url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
webbrowser.open(url)
I am working on a python project to control vlc player - volume up/down, play/pause, rewind/forward and I have installed python2.7, vlc 3.0.8 32bit on windows 7. this is the code below which is to play the local mp4 file
import vlc
instance = vlc.Instance()
player = instance.media_player_new()
Media = instance.media_new('d:\1280.mp4')
Media.get_mrl()
player.set_media(Media)
player.play()
problem is the keywords - Instance and other functions are not getting highlighted except import and am getting the following error
Traceback (most recent call last):
File "C:\Python27\vlc3.py", line 4, in <module>
Media = instance.media_new('d:\1280.mp4')
File "C:\Python27\vlc.py", line 1916, in media_new
m._instance = self
AttributeError: 'NoneType' object has no attribute '_instance'
I am not able to understand please help me out
Use forward slashes instead of backward slashes.
Use:
Media = instance.media_new('d:/1280.mp4')
Instead of:
Media = instance.media_new('d:\1280.mp4')
I tried to set up a highscore tracker for an app by using a JSON file and the json storage language in Kivy.
I imported JSONstore and in my main game class I did
class Game(FloatLayout):
highscorejson = JsonStore('highscore.json')
highscore = NumericProperty(highscorejson.get('highscore')['best'])
and after I init the class, I have an end game function that ends the game and checks to see if the new score beats the old highscore.
def end_game(self):
if self.score > self.highscore:
self.highscorejson.put('highscore', best = self.score)
self.highscore = self.highscorejson.get('highscore')['best']
This runs perfectly when I run it through Kivy, but when I run it through XCode using my iphone as a test device, it crashes when you score above the highscore and the game ends. The error message is as below.
File "/usr/local/lib/python2.7/site-packages/kivy/storage/__init__.py", line 174, in put
File "/usr/local/lib/python2.7/site-packages/kivy/storage/jsonstore.py", line 39, in store_sync
IOError: [Errno 1] Operation not permitted: 'highscore.json'
2014-06-24 21:59:34.385 cookie[2320:60b] Application quit abnormally!
2014-06-24 21:59:34.457 cookie[2320:60b] Leaving
Full Error:
http://pastebin.com/Zy0DtysW
I was stuck on this problem too. So, finally, I was able to solve this problem. The next code helped me a lot.
from os.path import join
class MyApp(App):
def build(self):
data_dir = getattr(self, 'user_data_dir')
store = JsonStore(join(data_dir, 'storage_file.json'))
As I understand, user_data_dir stores an unique for each app and OS path, where current app's code is stored.
You're probably trying to save the file in an invalid location. Try including a full path to the file you want to write out - you can use kivy_home_dir to help with this.
from kivy import kivy_home_dir
from os.path import join
highscore = JsonStore(join(kivy_home_dir, 'highscore.json'))
I have tried this code able to get only playlist information but I am looking for current Audio file name is running or not
import win32com.client
w=win32com.client.gencache.EnsureDispatch('WMPlayer.OCX',0)
pl=w.playlistCollection.getByName('All Music')[0]
s=pl[1]
print s.name, s.duration
w.currentMedia=s
w.IsPlaying=0
print "w.currentMedia",w.currentMedia
im trying to display a video on a pygame surface using the pyglet library to import, play and then convert the frames into an image. I managed to battle my way through installing avbin but now I'm hitting a type error with my code
def cutscene(window_surface, filename):
player = pyglet.media.Player()
source = pyglet.media.load(filename)
player.queue(source)
player.play()
pygame.display.flip()
while True:
window_surface.fill(0)
player.dispatch_events()
tex = player.get_texture()
raw = tex.get_image_data().get_data('RGBA',tex.width*4)
raw = ctypes.string_at(ctypes.addressof(raw), ctypes.sizeof(raw))
img = pygame.image.frombuffer(raw, (tex.width, tex.height), 'RGBA')
window_surface.blit(img, (0,0))
pygame.display.flip()
when I run, i get the following error
Traceback (most recent call last):
File "dino_game.py", line 348, in <module>
main()
File "dino_game.py", line 45, in main
cutscene(window_surface, "Cutscenes/Cutscene1.mov")
File "dino_game.py", line 68, in cutscene
raw = tex.get_image_data().get_data('RGBA',tex.width*4)
AttributeError: 'NoneType' object has no attribute 'get_image_data'
Nothing that I do seems to solve it
EDIT: So after testing both this file and the sample files provided by pyglet, it seems that I get this error no matter what filetype I use, could this be an installation error with pyglet or AVbin?
Gave up trying to use pyglet and swapped to VLC where I just have to pass the window ID for the game and it does the rest for me
VLC script: https://wiki.videolan.org/Python_bindings/