0% found this document useful (0 votes)
190 views

G9Adv-Building An MP3 Player in Python (Word Version)

Uploaded by

Maryam
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
190 views

G9Adv-Building An MP3 Player in Python (Word Version)

Uploaded by

Maryam
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Section 4 : Creative development – Building an

MP3 player in Python

Aim

This section will introduce you to the concept of programming events, prototypes and feedback. You will
learn these concepts through designing a GUI of an MP3 player using Python.

Learning outcomes

• Create prototypes that use algorithms to solve a range of computational problems by applying
prior student knowledge.
• Develop computational artefacts using an iterative process for practical intent and personal
expression using events to initiate instructions.
• Explain methods that can be implemented to gather feedback on a program from a broad
audience.

Prior knowledge

• Algorithms
• Python programming

ADVANCED WORKBOOK
My STREAM focus

Copyright © Ministry of Education – United Arab


Emirates
43

Copyright © Ministry of Education – United Arab


Emirates
Key vocabulary

WORD MEANING PICTURE

sample model of a product built to test a concept


prototype
or process

event action that occurs as a result of the user or


another source

information about reactions to a product, a person's


feedback performance of a task, etc. which is used as a basis
for improvement
ADVANCED WORKBOOK
Section
4
Chapter 1

44

Copyright © Ministry of Education – United Arab


Emirates
Activity 1.4.1

Research various examples for the GUI of an MP3 player. Use your research to gather
some information about the various layout available using images or text. Paste your findings
in the space below.

ADVANCED WORKBOOK

Copyright © Ministry of Education – United Arab


Emirates
4
Section
Chapter 1
45

Copyright © Ministry of Education – United Arab


Emirates
Activity 1.4.2

Use the research results completed in Activity 1.4.1 to sketch the layout of the GUI for
your MP3 player.
Remember that you will be designing a very basic GUI with the following elements on the
window:

(a)welcome message / your name


(b) Play button
ADVANCED WORKBOOK

Copyright © Ministry of Education – United Arab


Emirates
Section
4
Chapter 1

46

Copyright © Ministry of Education – United Arab


Emirates
Activity 1.4.3

The algorithm for your MP3 player is shown in the table below but in the wrong order.

Initialise the libraries.


Add the title to the player window.
Import the libraries.
Close button will automatically clear the song list and will stop playing the song.
Specify the geometry size of the player window.
Add button to play the song
Add the label to display a welcome message or your name
Create a function to play a song
Add the method that executes the MP3 player application

Organise the steps in the correct order in the table below. The first and last steps are done for
you.

Import the libraries.

Initialise the libraries.

Add the label to display a welcome message or your name

ADVANCED WORKBOOK
Add the title to the player window.

Specify the geometry size of the player window.

Create a function to play a song


4
Section

Add button to play the song


Chapter 1

Close button will automatically clear the song list and will stop playing the song.

47

Copyright © Ministry of Education – United Arab


Emirates
Activity 1.4.4

Copy and paste the following code to build your MP3 player.

# importing required libraries


from tkinter import *
import pygame

root = Tk()
root.title('MP3 player')

root.geometry("500x400")

pygame.mixer.init() # initialise the pygame

def play():
pygame.mixer.music.load("write the name of the audio file here")
pygame.mixer.music.play(loops=0)

title=Label(root,text="MyMusicPlayer",bd=9,relief=GROOVE,
font=("times new roman",50,"bold"),bg="white",fg="green")
title.pack(side=TOP,fill=X)

play_button = Button(root, text="Play Song", font=("Helvetica", 32),


command=play)
play_button.pack(pady=20)
root.mainloop()

Run the code and observe the


ADVANCED WORKBOOK

output.

• Remember to store the song / audio in the same folder where


Note: you have stored the code for your MP3 player.
• For a start, you can download the UAE national anthem and try
to play it on your laptop using the above code.
• You can play as many songs as you want, but you have to download the
MP3 files and store in the same folder where your stored. Then
code is change the name of the file in the code.
Section
4
Chapter 1

48

Copyright © Ministry of Education – United Arab


Emirates
Activity 1.4.5

For the MP3 player which you have developed using Python, answer the following questions:

a. Which type of evaluation will you choose -qualitative and quantitative?


b. Justify your choice in (a).
c. How would you like to develop your MP3 player in the future? (You can answer this in
text or using an image)

ADVANCED WORKBOOK
4
Section
Chapter 1

49

Copyright © Ministry of Education – United Arab


Emirates
Student reflection

List three things you have learned and two things you have enjoyed.
Three things I have learned:
1-
2-
3-

Two things I have enjoyed:


1-
2-

Key skills
I don’t I’m an
Learning outcomes (Please tick the box to show your I understand.
understand. expert.
understanding of the skills below.)

I can develop algorithms for


computational problems by applying
Create prototypes that use prior student knowledge.
algorithms to solve a range
of computational problems
by applying prior student I can create prototypes that use
knowledge. algorithms to solve a range of
computational problems by applying
prior student knowledge.

I can identify real-world


examples of programming
Develop computational events and the controls
artefacts using an iterative structures required for
ADVANCED WORKBOOK

process for practical intent implementation.


and personal expression using I can develop computational
events to initiate instructions. artefacts using an iterative
process for practical intent and
personal expression using events
to initiate instructions.

I can identify methods that can


be implemented to gather feedback
Explain methods that can on a program from a broad
be implemented to gather audience.
feedback on a program from
a broad audience. I can explain methods that can
Section

be implemented to gather feedback


on a program from a broad
audience.
4

Teacher's comment:
Chapter 1

50
Copyright © Ministry of Education – United Arab
Emirates

You might also like