Hello Monkey followers!
Before I get into the lesson’s I’ve done since the last post I wanted to just talk about this blog a little. First up is my update schedule. I plan to post something every Tuesday and Thursday. Hopefully with each post I’ll cover 2 or three tutorials for as long as I work on them, and when I’m done then I’ll post about what I’m learning as I develop apps. You might also see the occasional weekend post if I get wrapped up in something development related and want to share, but mostly my weekend computer time will be spent gaming. I’d also like to talk about what this blog will focus on and what it’s become. I never intended it to be a step by step tutorial, and it won’t become that. But at this point I feel it is a good supplement for anyone working through mybringback’s tutorials. It is my hope that even those not working through them will find them informative, or at least a little amusing. Let me know what you’d like to see!
I started working nights this week so my days are a little messed up and thinking is more difficult, but I think I’m still learning. Lesson nine from mybringback was all about audio. It went pretty smoothly. Adding a media player was remarkably simple.
MediaPlayer logoMusic;
That’s it. Well, that’s it for adding the media player. To start it wasn’t too much harder. I’ll put the code snippet that got it running below.
This code starts the Music running
I did have a few problems with this that I’ll go over quickly in case it helps anyone else. 1) Where it says MainActivity up there, that is the class you are working in. Travis’ had main there in the tutorial so I just wrote what he did and it didn’t work because I don’t have a main class. I used Android Studio’s tool tip on the error to sort things out. 2) Next my music file (The Mermaid) was throwing an issue. The tool tip said it was an invalid name. So I removed the space in it and changed the first capital (theMermaid). AS still didn’t like that so I changed it again to themermaid and it worked no problem.
Before we ran the program we added an onPause method to our activity, and told our MediaPlayer to release the music when the activity paused. This caused the music to stop when the 5 second sleep timer ran out and the app moved on to our menu screen.
mybringback’s Lesson Ten makes our buttons work! Yay! OK, let’s get into this. Our buttons were made earlier, so all had to do with them was make sure that they had id’s. “@+id/tutorial1” That was easy. We also had to create a new xml layout file. Travis left his completely blank and to start with I did as well, but when I ran into trouble I added to it by putting in my ugly background an a TextView. I’ll get to the trouble I had later, as well as my eventual solution to it. We set up the button in our menu class.
The Code from our Button
We learn the basics of the OnClickListener from this. We set up the button first by naming it and telling it what id it is. Then we tell it to listen for clicks. Finally when it clicked (onClick) we start a new activity with the intent that follows. This was a new way of doing intents and I feel it cleans things up as opposed to having a line of code above it. I’ll try to use this way in the future when possible. If we tried to run our app at this point, it would not work. We haven’t declared the activity in the AndroidManifest.xml file. To do this we copied the last activity we made and pasted it between the <application> tags there, then we edited the android:name to and intent-filter android:name to match the new activity we set up. We left the category as DEFAULT so that the application would know not to use it as the launcher activity. That was pretty much it. Except my app crashed every time I tried to run it.
Uh-Oh
I’m not proud of how long it took me to find the problem. Travis had name various things in this lesson “TUTORIALONE”, “TutorialOne”, “tutorialone”, and “tutorial1”. This confused me to no end. I’ll need to get better at watching what labels are put on what. I spent over 2 hours looking for the issue. I looked at comments from the tutorial page and others that had a similar issue solved it by added a background to the layout file, so I did that. No dice! I finally sorted it out by re watching the video while following along in my code to find what should match up to what. I had made a mistake in the AndroidManifest file with naming the intent filter properly. After that it ran properly.
Lesson 11 got me excited. In the introduction on the mybringback web site he said that with the knowledge from this lesson we would be able to make a soundboard app and publish it, maybe start making money. That sounded great to me! First, let’s look at the lesson.
In this lesson we added sound to our buttons. He suggested grabbing sounds from soundjay.com so that’s what I did. I went with button 1… This lesson was mostly a review with really only one new thing going on that we didn’t use in our splash screen sound example. What we did was set up our second button to work the exact same as our first (sort of boring going to the same activity again) and then added a sound to them. We still used the media player instead of the media pool.
Adding Sound to a Button
As you can see on line 22 we set up the MediaPlayer. We didn’t initially make it final, but then line 32 threw an error. I’m not sure exactly why, but Travis said to add final to the MediaPlayer that made it work. That is pretty much all there was to it. Not too difficult at all and a nice review.
So after reading the introduction to the lesson I was excited. I thought I could make a Star Wars soundboard app and sell it in the Play Store. Get my fee (I think it’s $25) out of the way and maybe start gaining money to offset it before any of my other apps our ready to be made. Seemed like a fun idea! Then I thought about it longer. Isn’t the audio I would want to work with under Copyright? Doesn’t that make sound boards using them (or any other copyrighted audio) illegal? I answered yes to those two questions. So it begs a third question: Why do I see so many sound board apps on the market? Surely they didn’t all receive permission from the copyright holders to use them! Is there something I’m missing here? Can I go ahead and publish a sound board app without being sued into oblivion by Disney/LucasFilm?