16 abr. 2014

A guide to AutoPlay problem solution

Hello,

So you downloaded AutoPlay and it is not working? Do not worry. Let me will guide you through some steps and verifications to know why AutoPlay is not working properly, what can you do to make it work or understand why it can not work in your case.

4 abr. 2014

AutoPlay: why & how

 I have to admit that the App description on Google Play may be too short to anyone who wants some more detailed and know if the App can do this or that.

So to help you here I explain more details of the App and why it is the way it is and how it was done.

Why

AutoPlay is an Android App that allows you to start listening your music by simply plug in your earphones.

The Android operating system does already something similar, but on the opposite side: if you are listening music with earphones and you unplug them the music stops automatically with no action required.

Then the question was: why not start to play the music again when I plug the earphones back?

I know that my mobile phone needs some level of security to preserve the, al least for me, valuable information I store in it. So if someone stoles my phone the first thing it would need is to enter a password. Of course this does not prevent the thief to get access to the information or put the phone again to factory default, but gives me valuable time to activate the remote delete that the Google Account allows.
What does this has to be with the music player and the earphones? Well, my phone requires a password to access to any App, so every time I want to start to play the music I had to enter the password. Stop the music was easy: simply unplug the earphones. But play it again was not so easy as I would expect.

No answer I found on Google Play. And I decided to make an App to do it.





How

The program definition was very clear: just start the music if earphones were plugged.
After some search I read about the messages that Android sends to all Apps to inform about some events that may occur along the phone day.
Some messages are related to music controls and fortunately one was about earphones state.

My App just needed to start listening the appropriate messages, listening for earphones plugged and also sending messages to music players to start play music, emulating the controls integrated on some earphones to control the music. So the music player must hear these commands and attend the order.

I named the App AutoPlay and put it on Google Play just in case any other person finds it as useful as me. A free App.

Then one problem arised: the Samsung Galaxy S2 I use had one music player that most of the time received nicely the "play" command and properly started the music on background, but sometimes not at all.
I found that the "play" commands my App was sending were simply ignored if the music player was never started since the phone was turned on. So the music player should be starting some kind of service to listen to play commands.

I changed the App to start the music player before sending the "play" command. This solution worked fine, but the sacrifice was that know the music player jumps to front, disrupting whatever you could be doing.

Later on some users complained that they had installed a music player able to listen to play commands, but when they plugged the earphones another music player was started but the first one attended the "play" command.

So I changed the App to let the user select which music player should start, if any, when the earphones are plugged.

As you can see the App development was not as simple as it could seem.