0

Going to keep this short and sweet. I am trying to play a song using pygame's mixer. When I choose the song to play I get this error. `

File "d:\Study\Python\musicplayer.py", line 32, in PlayMusic
    mixer.music.load(Playlist.get(ACTIVE))
pygame.error: Failed loading libmpg123-0.dll: The specified module could not be found.

Here is my code if that helps as well.

import os
from tkinter import *
from tkinter import filedialog
from pygame import mixer
import pygame
# from PIL import Image, ImageTk
# to create a GUI window
root = Tk()
root.title('Melody Soul')
root.geometry('920x600+290+85')
root.configure(background='#212121')
root.resizable(False, False)
pygame.init()
mixer.init()
# root.mainloop()

# To create a function to opne a file

def AddMusic():
    path = filedialog.askdirectory()
    if path:
        os.chdir(path)
        songs = os.listdir(path)

        for song in songs:
            if song.endswith(".mp3"):
                Playlist.insert(END, song)
                
def PlayMusic():
    Music_Name = Playlist.get(ACTIVE)
    print(Music_Name[0:-4])
    mixer.music.load(Playlist.get(ACTIVE))
    mixer.music.play()

#icon
image_icon = PhotoImage(file='C:\\Users\\meetg\\OneDrive\\Pictures\\Saved Pictures\\Pins\\music.png')
root.iconphoto(False,image_icon)

Top = PhotoImage(file='C:\\Users\\meetg\\OneDrive\\Pictures\\Saved Pictures\\Pins\\312F6F46-F8F6-428F-BD78-A6E8644AAA42.png')
Label(root,image=Top,bg='#0f1a2b').pack()

#logo
logo = PhotoImage(file='C:\\Users\\meetg\\OneDrive\\Pictures\\Saved Pictures\\Pins\\photo-1505238680356-667803448bb6.png')
Label(root,image=logo,bg='#0f1a2b',bd=0).place(x=70,y=115)

# Buttons 
ButtonPlay = PhotoImage(file="C:\\Users\\meetg\\OneDrive\\Pictures\\Saved Pictures\\play-button.png")
Button(root, image=ButtonPlay, bg="#0f1a2b", bd=0,
       command=PlayMusic).place(x=40, y=40)

# ButtonResume = PhotoImage(file="C:\\Users\\meetg\\OneDrive\\Pictures\\Saved Pictures\\end.png")
# Button(root, image=ButtonResume, bg="#0f1a2b", bd=0,
#        command=mixer.music.unpause).place(x=40, y=40)

# ButtonPause = PhotoImage(file="C:\\Users\\meetg\\OneDrive\\Pictures\\Saved Pictures\\pause button.png")
# Button(root, image=ButtonPause, bg="#0f1a2b", bd=0,
# command=mixer.music.pause).place(x=40, y=40)

# Label 
Menu = PhotoImage(file="C:\\Users\\meetg\\OneDrive\\Pictures\\Saved Pictures\\Pins\\IMG_0778.png")
Label(root, image=Menu, bg="#0f1a2b").pack(padx=10, pady=50, side=RIGHT)

Frame_Music = Frame(root, bd=2, relief=RIDGE)
Frame_Music.place(x=330, y=350, width=560, height=200)

Button(root, text="Open Folder", width=15, height=2, font=("times new roman",
       12, "bold"), fg="Black", bg="#21b3de", command=AddMusic).place(x=330, y=300)

Scroll = Scrollbar(Frame_Music)
Playlist = Listbox(Frame_Music, width=100, font=("Times new roman", 10), bg="#333333", fg="grey", selectbackground="lightblue", cursor="hand2", bd=0, yscrollcommand=Scroll.set)
Scroll.config(command=Playlist.yview)
Scroll.pack(side=RIGHT, fill=Y)
Playlist.pack(side=LEFT, fill=BOTH)
root.mainloop()

`

I think there is a issue with the compatibility of the version of python and pygame. So i tried few different versions of pygame and still it's showing the same error..

  • [Failed loading libmpg123.dll: The specified module could not be found](https://stackoverflow.com/questions/65237071/failed-loading-libmpg123-dll-the-specified-module-could-not-be-found), [Issues with pygame and libmpg123-0.dll](https://stackoverflow.com/questions/66828575/issues-with-pygame-and-libmpg123-0-dll) – Rabbid76 Nov 06 '22 at 17:35

1 Answers1

1

I believe you are running python from the Windows store. People who have had this error before have had this setup, rather than the much more common python.org installs.

Try updating to the latest pre release version of pygame. python -m pip install pygame --upgrade --pre. You should see "pygame 2.1.3.dev8" as the installed version after this change. (At the time of writing)

That will include my fix for the issue: https://github.com/pygame/pygame/pull/3196

Starbuck5
  • 1,649
  • 2
  • 7
  • 13