Play the sound already

I spent all day figuring out how to play a mp3 file in my Android app.  Before you start to question my programming skills (which is fine) let me add a few requirements:

1. The sound file is contained in a subdirectory within my assets

2. The code should work for external assets outside of the bundle as well as assets within the bundle.  For this reason I didn’t want to use resource ids.

3. The file should be streamed and not loaded entirely into memory.

The MediaPlayer seems like the best option to use and I immediately tried coding to that.  I spent most of the time trying to get the Uri implementation to work (ex: “file:///android_asset/sounds/music.mp3”) but that just refused to work for me.

I was able to use the AssetManager to get a AssetFileDescriptor which can give you a FileDescriptor that can be used as a data source for the MediaPlayer.

Here is the code:

// get the asset file descriptor from our context
AssetFileDescriptor afd = mContext.getAssets().openFd(filename);

// media player created in idle state (always call setDataSource next)
MediaPlayer mp = new MediaPlayer();

// setting data source puts media player into the initialized state
mp.setDataSource(afd.getFileDescriptor(), 
                 afd.getStartOffset(), 
                 afd.getLength());

// setting of looping should be done in the initialized or 
// prepared state (not idle state)
mp.setLooping(false);

// prepare required before calling start or stop methods
mp.prepare();

// listeners require running on the ui thread
mp.setOnCompletionListener(new OnCompletionListener()
{
    public void onCompletion(MediaPlayer mp)
    {
        mp.release();
    }
});

// finally play it
mp.start();

// cleanup afd
afd.close();

What’s in your water? Part 2

Distilled Tap WaterI have found out what’s in my tap water–Brown nasty chemical-smelling crap.   And it’s not just in my water but yours too.  I used a water distiller on 2 gallons of my tap water and the leftover is shown in this photo.  Go ahead and click on it for the full image.  I dare you.  It’s darker than a lager beer and smells of deadly toxins.  Would you drink this?  No, I don’t think so.  But you probably are if you are not using a distiller or high quality filter.

Megahome Countertop Water Distiller
Megahome Countertop Water Distiller

I purchased the Megahome Water Distiller so that I can remove fluoride from tap water.  This is something a regular water filter cannot do.  I could go on and on about why fluoride is not safe for you.  But instead, I’ll point you to the warning label on the back of your toothpaste:

“WARNING: Keep out of reach of children under 6 years of age. If you accidentally swallow more than used for brushing, get medical help or contact a Poison Control Center right away.”

If it says that on toothpaste then why is it a good idea to put fluoride in our drinking water?  I don’t understand it and I don’t want to get in a debate with any dental hygienists or conspiracy theorists.  I’m just going to remove it from my water.

In summary, if you drink tap water then you might as well be drinking out of the toilet.  Once you see and smell what is in your water, you will stop drinking it, and switch to bottled water or distill it like me.  I’m still using my ZeroWater filter too.  But now I pour the distilled water into that.  It really makes for some great tasting water.

If you decide to buy any of these items please go through my online store so I get some Amazon credit.  That way I can get more filters.  Or maybe just cash.  That’s nice too.

What’s in your water?

zerowater

I never thought about how good water filters were until I ordered a ZeroWater filter and it included a water testing tool.  They claim their filter results in water with 0 PPM (parts per million).  The higher the number means more particles and contaminants that not only make water taste bad but can also be bad for your health. It’s time for an experiment.

 

I tested my tap water, a bottle of spring water, and the ZeroWater filter:

Tap Water - 159 PPM
Tap Water – 159 PPM
Acadia Bottle Water -  24 PPM
Bottle Water – 24 PPM
ZeroWater - 0 PPM
ZeroWater – 0 PPM

 

 

 

 

 

My tap water clocked in at 159 PPM.  Is that a good number?  Apparently the World Health Organization says that water with a TDS (total dissolved solids) of 1,000 PPM is “acceptable” and under 600 PPM is “good.”  Yeah, maybe if you’re living in a tent in Africa it’s good but for us fussy Americans we want crystal clear drinking water without any off-flavors.  The higher the PPM number means the worse it will taste.  The bottle of Acadia Natural Spring Water was much better at 24 PPM.  And my new ZeroWater filter, as promised, clocked in at 0 PPM.  Guess it’s not marketing fluff after all.

I have two other water filters in my house–My refrigerator’s water filter (uses a PUR filter) and a Dr. Mercola filter that was pretty expensive.  In full disclosure, the refrigerator filter was replaced 2 months ago and the Dr. Mercola filter has about 5 months of use on it.  The refrigerator filter definitely gets more use than the Dr. Mercola filter.  The results really shocked me:

Refrigerator Water
My Refrigerator
Fridge Water - 171 PPM
Fridge Water – 171 PPM

My refrigerator PUR water filter is worse than my tap water at 171 PPM! How can that be?

Shouldn’t it be removing something?

 

 

Dr. Mercola Water Filter
Dr. Mercola Water Filter
Dr. Mircola's Pure & Clear - 178 PPM
Dr. Mircola’s Pure & Clear – 178 PPM

The worse rating goes to the expensive Dr. Mercola Pure & Clear drinking water filter which clocked in 178 PPM. It’s probably only fair to test the filters when they are brand new but I would still think that even if they are a few months old it shouldn’t be adding anything to the water.

I really like companies that back up their product claims, and the fact that the ZeroWater filter included a TDS water testing tool speaks volumes.   The instructions say to replace the ZeroWater filter once it gets to 6 PPM.  Maybe they should tell that to the entire water bottle industry.

Engineers are Worthless

Dear Engineer Friends,

You are the most worthless class of people I have ever known. I would never hire you. Engineers just sit around and think how great they are that they passed some tough classes in College. I need problem solvers out here in the real world. I need people that can use logic and creativity at the same time. Engineers solve problems recklessly and without concern for the future. If I was going to be plugged into a life support system, I’d make sure the logic behind the machine was created by a computer scientist. That way I’d have a much better chance of survival.

With the invention of the general purpose computer, engineers have been struggling to find their place in life. The sad thing is most of them end up taking our blue collar shit jobs that us computer scientists wouldn’t want–like writing websites, or maintaining someone else’s code– These jobs are perfect for engineers because they can operate like robots doing tedious tasks and not having to think.

The demand for solving math equations, building specific pieces of hardware, or researching better ways to transmit signals is just not there anymore. And if you say that’s not what engineers do, then I apologize because no Engineer has ever been able to tell me what exactly they do. In fact, the only answer you’ll get from an Engineer is that whatever they are working on isn’t what they do. Engineers are a bunch of chickens running around with their heads cut off.

If you Engineers think you’ll be designing the next processor for Intel, think again, you got the same chance to be selected on NASA’s next moon mission. And speaking of the moon, who do you think made it possible to land the LEM3 on it? It wasn’t those puppets Neil Armstrong and Buzz Aldrin, it was a team of computer scientists that deserve the credit for designing software that was ahead of its time.

The main thing I can’t stand about engineers is they smell.

Continue reading Engineers are Worthless

The most beautiful pieces of crap I’ve ever purchased

My latest purchase from Apple is the 27″ Thunderbolt Display and it has inspired me to write this article. It’s the most beautiful piece of crap I’ve ever purchased. And by that I mean, the display is beautiful but the audio is total crap. In this video, I’m playing a simple tone of a constant frequency so you can hear all the lovely artifacts:

If I wanted snap, crackle, and pop then I’d spend a buck on some rice krispies but this is completely unacceptable for a $1,000 computer monitor. How could Apple who is known for revolutionizing the way we purchase music, release a product that can’t even play audio without distortion? I’ve determined that it happens if you plug anything into the USB ports on the monitor. I’ve joined this rather large thread of unhappy customers. Thankfully I’m still within 14 days of receiving this purchase so it’s getting returned to my local retail store. I’m hoping the next Thunderbolt display either fixes the problem or they just remove the speakers altogether and make the price cheaper.

I also picked up a couple Mac Minis this year. I needed a new workstation as my iMac was getting slow when trying to compile apps using the latest Xcode. I came really close to dropping $3,000 on the 15″ Retina MacBook Pro but I kept reading about lagging and ghosting issues. No thanks I’ll wait for v2. So instead, I bought a high-end Mac Mini with fusion drive and 16 GB of RAM. This seems to be a better option than buying a Mac Pro desktop. Apple just doesn’t seem to care about the Mac Pro. It hasn’t had a real update in a long time and it still doesn’t support Thunderbolt. Maybe next year the Mac Pro will get a real update but for now the only desktops Apple cares about is iMac and Mac Mini. I’m sure there are plenty of Xcode and Final Cut Pro folks like myself that still appreciate the power of desktop computers.

The other Mac Mini I purchased was to replace my OTA DVR which runs Windows 7 Media Center. The small footprint and quietness of the Mac Mini makes it a great HTPC DVR but I’ve noticed it has been skipping with HD video playback. I can’t confirm it’s the Intel HD 4000 chipset but that would seem the likely suspect given my last HTPC never skipped video and had a slower processor. I hope the future Mac Mini’s include a higher-end graphics card.

The iPhone 5 was another purchase and overall it’s really fast compared to my previous iPhone 4. Apple’s A6 processor combined with Verizon LTE makes it the fastest phone I’ve ever owned. But if I was going to get picky, and I am, I really wish they would have made the screen even bigger. I know the design is made so you can easily touch any part of the device with one hand. But not all hands are the same size so why not give guys like me an XL model? Apple needs to start competing with the bigger Android devices that are making me want to switch from iOS–This includes the Samsung Galaxy S III w/ 720P display and Verizon DNA with 1080P display. But my biggest complaint is that the iPhone has never been able to go a full day on a single charge. Instead of making it thinner, can we please just add a bigger battery? Maybe this will be the big feature of iPhone 6.

I also picked up an iPad 4 to replace my iPad 2. The Retina display looks amazing. But there is something I like better when holding the iPad 2. It’s thinner and lighter. Maybe the iPad 5 will get it right.

So there you have it–Major issues with Thunderbolt and Mac Book Pro with Retina display combined with annoyances of the Mac Mini, iPad 4, and iPhone 5. I’m hoping next years revisions get it right.

Cross-Platform Gaming Library

Cocos2dXMy favorite programming language is C++.  My favorite game library is Cocos2d.  It’s too bad that Cocos2d is written in Objective-C and only supports iOS and Mac.  And by that I mean it’s too bad I didn’t discover the C++ port of Cocos2d called Cocos2d-X earlier.  It’s absolutely amazing.  Why?

  • First, it’s C++.  My favorite.  The standard template library with it’s generic containers such as std::map is the best.
  • Second, it uses all the same class names and constructs as my favorite Cocos2d gaming library.  This made it extremely easy to switch over to.
  • Third, it’s cross-platform and runs almost everywhere–iOS, Android, Mac, and Windows.  It even has a HTML5 port and the Windows port uses DirectX instead of OpenGL.

With this kind of distribution and support why would you code up your own solution or limit yourself to a single platform?  I’m all in and you should be too.  That is of course if you write games.  Check out my first Cocos2d-x game called Tic Tac Toe Glow which I’m releasing to iOS and Android at the same time.  Windows 8 and Mac will be coming too and why not?  This library makes it easy to do.

Building your First iPhone App

I’m writing a couple tutorials on how to build your first app, starting with the typical Hello World example.  I’ll then show how to take that code and build something a little more useful including a system clock and a stopwatch timer. It will be a total of three articles.

Update:  Article #2 on Create your own Apple iPhone Clock app was just published. (8/2/2012)

I’ve been pretty busy writing my next game which will initially launch on iOS and Android platforms.  I hope to have it out by August.  Stay tuned!

 

Congressional Committee on Mobile App Privacy

I had the opportunity to give my advice on mobile apps and privacy as a panelist for the 2012 State of the Mobile Net Advisory Committee. If you watch the video you will notice not everyone is in agreement with who should be responsible for your privacy–The App Developer, The Platform (iOS, Android, etc), or The End-User?  I certainly have my opinions as both a developer and a consumer of hundred of apps.  Click the image to watch the video:

Although ultimately it is up to the developer to protect your privacy and do no evil, I argued that the platforms are in the best position to protect your information.  Apple iOS guards your location and prompts you when an application tries to access it.  This works well and you have the ability to deny the app access.  This kind of protection could be provided to other areas such as your address book and calendar events which are currently wide open for apps to abuse.  Imagine downloading a flashlight app, only to have your entire address book uploaded to Spammers-R-Us.

The Android platform gives you a list of permissions an application requires prior to installation.  I like this but as I discuss in the video it has caused issues in my own apps.   I’m hoping a mix of both real time and installation time permissions find it’s way into both platforms going forward.  I feel when a technical solution exists to a problem, and I’m claiming it does, then that is the best approach–Not government regulation and certainly not 100 page privacy policies that nobody reads.

We discussed issues with apps like Path which uploaded your address book without first getting your permission (It does now).  The Girls Around Me App was also a major focus and although we all think it’s creepy, I’m the only one who made the point of what’s wrong with displaying publicly available information?  In this case, girls were not aware their location was being put out into the public by Foursquare.  That’s a problem with the social network and not with an application that just displays what is already online.  Education is key here.

Privacy has become a huge issue with mobile apps and will continue to be.  I’m looking forward to future versions of iOS and Android which will hopefully provide even better controls.  If we just leave it up to application developers to implement privacy controls then we won’t have a consistent standardized method to safeguard our privacy.  I want this across all of my applications.  What do you think?