MP3 Player Demo | Development | Online Course With Appy Pie Academy

MP3 Player Demo

Lesson Details:
July 10, 2020


I: Introduction

A: A computer is a machine that can be programmed to do repetitive tasks. Computer programming is the act of writing the instructions that tell the computer what to do.

B: The main programming languages are C, C++, Pascal, Java, Python, Perl, and C#. There are hundreds of other programming languages in use, but these are the most common.

II: Body

A: Mp3 Player Demo

B: To demonstrate how programming languages work, I am going to create an mp3 player in C++. This will allow me to show you how to program in C++.

C: To begin with, I need to give a pointer to the data structure that will hold the music file on the hard drive. This can be done by declaring a variable called “Music” of type FILE. Here is the code:

FILE* Music;

D: Next, I need to open a file with the name “Music” that has been created for this purpose. In order to do this, you need to use a function called fopen(). This function takes two parameters, a string containing the name of the file you want to open and a mode of operation. The first thing we need to do is declare a string called “FileName” and a switch variable called “Mode”. We then use the symbol “#include” to include a header file called fstream which contains all of the functions we need to open a file. Once this is done, we call the fopen() function as follows:

#include

FileName = "Music";

Mode = fopen(FileName,"r");

E: The first parameter is the name of the file we want to open. The second parameter is the mode of operation and must be set to "r". This means we want to open an existing file for reading only. If we were opening a new file we would use an "w" instead. This code takes us one step closer to our mp3 player by creating a pointer called "Music" that points to a FILE structure associated with a file called "Music".

F: Finally, we need to read the file into memory. To do this we need yet another function called fgets(). This function reads characters from an input source into memory up until it reaches a specified character or string terminator. We then display the contents of the file on screen and create a new line (using the new line character). When we hit this new line we need to close the file and free up any memory used by the fgets() function by calling the fclose() function. This function takes two parameters; one is a FILE pointer and the other is a boolean value which must be set as true as we want to close the file as soon as we have finished reading it. Here is what our code now looks like:

fgets(FileString, 256, Music); //Reads 256 bytes from Music using fgets() and stores them in FileString



































































































loader
Course content