Ok, this is a simple media player I've been working on. So far, I wont release the whole source, but instead, a little piece to get you going.
I'll write this in a guideish way, if you just want the source, go the the bottom.
Code:
print "Type your song. Remember the file type! (.mp3 or something)"
input " ", songname$
This will display "Type your song. Remember the file type! (.mp3 or something)" on the screen, and it will await the user to type in something.
What the user types in, will be saved as songname$.
Now, we'd want the program to check up for the song, and play it.
Code:
LOAD MUSIC songname$, 1
PLAY MUSIC 1
Now, what happens is that the music gets loaded into the program, and will start to play it. Though, this will be almost nothing, we'll need a stop and resume function, as well as some eye candy!
So, add
goto menu
in the above code.
Now, add a few empty lines, and write
menu:
Below this, write
[code]
cls
sync : center text screen width()/2,screen height()/3,"Now playing:" : sync
sync : center text screen width()/2,screen height()/2,songname$ : sync
[code]
This one is a bit though to explain, though, its a bit easy if you think over it.
Sync, updates the screen or something.. tbh, I aint 100% sure what it does, so I wont try to explain it. The rest of the code will center some text, display "now playing:" and the value of songname below.
Now, for a stop/new/play function, go back to the beginning, and write
start:
That is to add a way back, in case the listener wants to change the song.
So far, the code should look somewhat like this:
Code:
print "Type your song. Remember the file type! (.mp3 or something)"
start:
input " ", songname$
LOAD MUSIC songname$, 1
PLAY MUSIC 1
goto menu
menu:
cls
sync : center text screen width()/2,screen height()/3,"Now playing:" : sync
sync : center text screen width()/2,screen height()/2,songname$ : sync
As you can see, we don't really need the goto menu function, as the program would just go there since there is no code in between, but if you make the application bigger, it gets nice to be able to travel between the functions easier.
Now, we'd want to add a option for the user to type in "new" to choose a new song, or, to direct the program to the beginning, "pause" to pause the music, and "play" to resume it.
The following code goes below the current one.
Code:
input " ", Menu$
rem We'll wait for any key to be pressed. Lets hope they find the any key!
If Menu$ = "new"
rem Giving a notice that they have choosed a new one
print "Select a new song"
rem Lets stop the music, else it will all becomme rather messy!
STOP MUSIC 1
rem As the song is already stored as song number 1, we'll need to clear it.
DELETE MUSIC 1
rem The music is stopped.
rem Going back to the process of getting a new song!
cls
goto start
rem We're closing the new check.
endif
if Menu$ = "pause"
print "Paused."
PAUSE MUSIC 1
wait 1000
goto menu
endif
if Menu$ = "play"
Print "Resumed"
RESUME MUSIC 1
wait 1000
goto menu
endif
print "could not understand command!"
Ok, if you look over it, its going to look at it this way:
If menu$ = "valueish"
If that is correct, it will run that code. If NOT, it will find the endif tag, and continue from there. If you look over it, its rather basic and easy to understand, so I aint going to explain it that much. If you notice, in the end, its a print command, the reason I can place it there is because the code hasn't been picked up, there has been no results, which means that it could not understand the command.
That should be it, I think... If it has any bugs, then I challenge you to find it, because that would be a great way to learn.
Anyways, going to get some sleep, its 03:31, haven't slept for a while, + got the news that my grandpa died not long ago.. :/
goodnight!
(Ps: Adding the full code here tomorrow, + I'll look over it to make sure it works as it should)