<file_sep>AwesomeTkinter==2020.9.16
certifi==2020.6.20
chardet==3.0.4
debtcollector==2.2.0
EasyTkinter==1.1.0
fire==0.3.1
future==0.18.2
hdpitkinter==1.0.3
idna==2.10
ModTkinter==0.0.22
mttkinter==0.6.1
mutagen==1.45.1
netaddr==0.8.0
numpy==1.19.2
OmegaMath01==1.0.8
os-android-apk-builder==1.13
os-tools==4.48
oslo.config==8.3.2
oslo.i18n==5.0.1
packaging==20.4
pbr==5.5.0
Pillow==7.2.0
pygame==1.9.6
pyparsing==2.4.7
pyquickhelper==1.9.3418
python-dateutil==2.8.1
pytz==2020.1
PyYAML==5.3.1
requests==2.24.0
rfc3986==1.4.0
six==1.15.0
stevedore==3.2.2
termcolor==1.1.0
tkinter-fonts-viewer==0.1.1
Tkinter-Managed-Frame==1.0.3
tkinter-nav==0.0.5
tkinter.help==2.0
TkinterClock01==1.0.3
tkinterhtml==0.7
tkinterquickhelper==1.5.72
tkintertable==1.3.2
tkintertoy==1.3.0
tkinterx==0.0.9
urllib3==1.25.10
wrapt==1.12.1
<file_sep># Music Player

This project is about creating a music player using python language.

### Setup

- create virtual environment, we are using `venv` here

    ```python
    python -m venv venv
    ```

- activate virtual environment

    **windows**

    ```python
    venv/Scripts/activate.bat
    ```

    **bash/linux** 

    ```python
    . venv/bin/activate
    ```

- install requirements

    ```python
    pip install -r requirements.txt
    ```

- finally to run the music player

    ```python
    python Canvas.py
    ```

### Contrubution

To contribute to this project, find an issue to work on or create an issue for something new you want to add or fix. And make a pull request.

### Hacktoberfest Contribution

If you are new and want to learn, you can start by improving documentation of the project, fix typos or improving readme
<file_sep># system imports
import os
from mutagen.id3 import ID3
import random

# pygame imports
import pygame
from pygame import mixer

# tkinter imports
from tkinter import *
from tkinter.ttk import 
from tkinter.filedialog import askdirectory

# initialization
root = Tk()
root.geometry('400x400+200+50')
root.title("Music Player")
root.iconbitmap("player.ico")
root.resizable(False,False)


listofsongs = []


index=0

v = StringVar()
songlabel = Label(root, textvariable=v, width=50)




def playsong(event):
    """
    plays song
    @param:
        event : pygame event object
    """
    pygame.mixer.music.play()
    pygame.mixer.unpause()

    updatelabel()


def nextsong(event):
    """
    plays next song
    @param:
        event : pygame event object
    """
    global index
    index += 1
    pygame.mixer.music.load(listofsongs[index])
    pygame.mixer.music.play()
    updatelabel()

def prevsong(event):
    """
    plays prev song
    @param:
        event : pygame event object
    """
    global index
    index -= 1
    pygame.mixer.music.load(listofsongs[index])
    pygame.mixer.music.play()
    updatelabel()

def randomsong(event):
    """
    plays random song
    @param:
        event : pygame event object
    """

    x = random.randint(0, len(listofsongs))
    pygame.mixer.music.load(listofsongs[x])
    pygame.mixer.music.play()
    updatelabel(x)



def stopsong(event):
    """
    stops song
    @param:
        event : pygame event object
    """
    pygame.mixer.music.stop()
    v.set("")

def updatelabel(loc=None):
    """
    update's label to present songs name
    @param:
        loc : int, index location of the present song playing
    """
    global index
    
    # if loc is passed then play song at that index
    # otherwise
    if loc is not None:
        v.set(listofsongs[loc])
    else:
        v.set(listofsongs[index])


def directorychooser():
    """
    function to choose the directory containing the songs
    """
    directory = askdirectory()
    os.chdir(directory)

    for files in os.listdir(directory):
        if files.endswith(".mp3"):

            listofsongs.append(files)
            print(files)


    pygame.mixer.init()
    pygame.mixer.music.load(listofsongs[0])


directorychooser()

label = Label(root, text=f"Music List-{len(listofsongs)}Songs")
label.pack()


listbox = Listbox(root)
listbox.pack()

listofsongs.reverse()


for items in listofsongs:
    listbox.insert(0,items)

listofsongs.reverse()


playbutton = Button(root, text="Play")
playbutton.pack()

nextbutton = Button(root,text="Next Song")
nextbutton.pack()

randombutton = Button(root,text="Random Song")
randombutton.pack()

previousbutton = Button(root,text="Previous Song")
previousbutton.pack()

stopbutton = Button(root,text="Stop")
stopbutton.pack()

playbutton.bind("<Button-1>", playsong)
nextbutton.bind("<Button-1>", nextsong)
randombutton.bind("<Button-1>", randomsong)
previousbutton.bind("<Button-1>", prevsong)
stopbutton.bind("<Button-1>", stopsong)

songlabel.pack()

root.mainloop()
