Create MP3 Player with Raspberry Pi (With Python Code in Comments)

preview_player
Показать описание
In this project, I made a nice MP3 player by using raspberry pi. Actually, raspberry pi plays all the audio files with ".mp3" extension stored in an external usb flash drive. A python code is written to read files from usb and plays them by "omxplayer". You also have control on playing the music by four buttons, "Stop", "Pause", "Next audio stream" and "Previous audio stream". MP3 player will start working as the Pi boots up.

Рекомендации по теме
Комментарии
Автор

Thanks man! thanks a lot... used your code for project and modified it a little according to projects need.. this is exactly what I was looking for and will share my codes too soon.. thanks again

vivekkabirrr
Автор

hello sir
i tested this code, but doesnt work.
in the console:
player.stdin.write ("q")
TypeError: an object of type bytes is required, not 'str'.
please help me and thank you

believeinyourself
Автор

nice one. i need the connection of the switches and the resistors you used..  send me those details soon... we are in our project completion

kalaiselvan
Автор

Thank you for making this video it was helpful

zacharyhuntsman
Автор

Here is the python code of my project. Hope you enjoy it.

import os
import glob
import subprocess
from time import sleep
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN)   # pin 15
GPIO.setup(23, GPIO.IN)   # pin 16
GPIO.setup(24, GPIO.IN)   # pin 18
GPIO.setup(25, GPIO.IN)   # pin 22

sleep(20)
os.chdir('/media/HANIEH')
f = glob.glob('*.mp3')
#print f
h = len(f)
flag=1
pt=0
st=0

while True:
    if flag==1:
        player = subprocess.Popen(["omxplayer", f[pt]], stdin=subprocess.PIPE) #, stdout=subprocess.PIPE, stderr=subprocess.PIPE
        fi = player.poll()
        flag=0
        st=0

    if (GPIO.input(22)==False):
        sleep(0.5)
        fi = player.poll()
        if fi!=0:
            player.stdin.write("p")      # pin 15 pause
            
        

    if (GPIO.input(23)==False):
        sleep(0.5)
        fi = player.poll()
        if fi!=0:
            player.stdin.write("q")      # pin 16 stop
            st=1
       
    if (GPIO.input(24)==False):
        if st==0:
            player.stdin.write("q")      # pin 18 Next Audio
        flag=1
        pt = pt+1
        if pt>h-1:
            pt=0
        sleep(0.5)    

    elif (GPIO.input(25)==False):
        if st==0:
            player.stdin.write("q")      # pin 22 Next Audio
        flag=1
        pt = pt-1
        if pt<0:
            pt=h-1
        sleep(0.5)

    else:
        fi = player.poll()
        if (fi==0 and st==0):
            flag=1
            pt=pt+1
            if pt>h-1:
                pt=0
    sleep(0.1)

    
#player.stdin.write("+")

#player.stdin.write("-")

gholamrezakhademi
Автор

Very good idea!!! But where's the python source? I don't find it anywhere! Thanks

bodale
Автор

this is an excellent project and you should make another video going into more detail on how to make it. one question i have, would it be possible to make it so the music comes from a file within the usb, rather than from the root of the usb itself?

nbarrager
Автор

Is it possible to get a code for this program?

LK-yueq
Автор

Is this possible to do with a raspberry pi zero w?

Hunter-qslr
Автор

Do you have the Python code available for others to look at? Like at Github.com?

linuxgnuru
Автор

so I've been getting an error saying 'media/HANIEH' is not a directory and I don't know how to fix this if anyone can help that would be great

estopesto
Автор

Thank you Hanieh. That's correct.

gholamrezakhademi
Автор

.poll() is from the subprocess module and used to check if child process has terminated.

haniehmohammadi
Автор

mr. saman i have problem in GPIO input, "error in GPIO 22"

mudzakirsalam
Автор

its very nice .. i need the switch connections for this... please send me very soon because i am in my final year academic

kalaiselvan
Автор

                                               SW
R=10k
                                    |
                                    |
                                 GPIO

gholamrezakhademi
welcome to shbcf.ru