Channels ▼

Mike Riley

Dr. Dobb's Bloggers

The Parrot Asteroid Development Experience

May 31, 2012

To make up for the loss of the SoundPool functionality, I stored the shots and booms sound effects into separate arrays and randomly selected one from each for playback when the button OnClick event is fired. Here's a look at the main VirtualRoadRage class:


public class VirtualRoadRageActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final int shotArr[] = new int[11];
        shotArr[0] = R.raw.shot1;
        shotArr[1] = R.raw.shot1;
        shotArr[2] = R.raw.shot2;
        shotArr[3] = R.raw.shot3;
        shotArr[4] = R.raw.shot4;
        shotArr[5] = R.raw.shot5;
        shotArr[6] = R.raw.shot6;
        shotArr[7] = R.raw.shot7;
        shotArr[8] = R.raw.shot8;
        shotArr[9] = R.raw.shot9;
        shotArr[10] = R.raw.shot10;

        final int boomArr[] = new int[22];
        boomArr[0] = R.raw.boom1;
        boomArr[1] = R.raw.boom1;
        boomArr[2] = R.raw.boom2;
        boomArr[3] = R.raw.boom3;
        boomArr[4] = R.raw.boom4;
        boomArr[5] = R.raw.boom5;
        boomArr[6] = R.raw.boom6;
        boomArr[7] = R.raw.boom7;
        boomArr[8] = R.raw.boom8;
        boomArr[9] = R.raw.boom9;
        boomArr[10] = R.raw.boom10;
        boomArr[11] = R.raw.boom11;
        boomArr[12] = R.raw.boom12;
        boomArr[13] = R.raw.boom13;
        boomArr[14] = R.raw.boom14;
        boomArr[15] = R.raw.boom15;
        boomArr[16] = R.raw.boom16;
        boomArr[17] = R.raw.boom17;
        boomArr[18] = R.raw.boom18;
        boomArr[19] = R.raw.boom19;
        boomArr[20] = R.raw.boom20;
        boomArr[21] = R.raw.boom21;    
        
        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
        	MediaPlayer shotPlayer;
        	MediaPlayer boomPlayer;
        	
            public void onClick(View v) {
                Random rnd = new Random();
                int shotInt = rnd.nextInt(10) + 1;
                int boomInt = rnd.nextInt(21) + 1;
                
                try {
                    shotPlayer = MediaPlayer.create(getBaseContext(), shotArr[shotInt]); 
                    shotPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() 
                    {           
                        public void onCompletion(MediaPlayer shotPlayer) 
                        {
                            shotPlayer.release();
                        }           
                    });  
                    shotPlayer.start();
                
                    boomPlayer = MediaPlayer.create(getBaseContext(), boomArr[boomInt]); 
                    boomPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() 
                    {           
                        public void onCompletion(MediaPlayer boomPlayer) 
                        {
                            boomPlayer.release();
                        }           
                    });  
                    boomPlayer.start();
                
                } catch (Exception e) {
                    Log.e("Virtual Road Rage", "Audio playback error - ", e);  // log the error
                }            	
            }
        });
    }

Fortunately, running two MediaPlayer audio playback instances isn't too taxing on the Asteroid, even when another audio stream coming from Asteroid's built-in music app is running. The random combinations give the merged sound effects enough variety to minimize audio fatigue. Pressing the Parrot dial button multiple times queues up the OnClick events, allowing for a continuous stream of explosive sounds. Thus, the more times the button is pressed, the more sounds are reproduced and the more rage is expressed.

Testing and Debugging

Because the Asteroid I used lacked an on-board WiFi radio, the build and debug cycle on the device itself was cumbersome. I was able to successfully connect the Asteroid to my home network via a direct Ethernet connection and a Trendnet Ethernet to USB adapter plugged into the Asteroid's USB port. Parrot's SysInfo.apk, included in the SDK, identified the IP address it picked up from my DHCP server and I was able to use the "export ADBHOST=the_asteroids_ip_address" command with the Android Debug Bridge (ADB) to load and launch apps on the Asteroid as if it were just a plain old Android 1.5 mobile device. Naturally, I built a majority of the app using the emulator ahead of time since I didn't want to drain my car battery with a time-consuming debug cycle. So let this be a lesson to developers who want to build a complex app. Either develop the app on the Asteroid before having it installed in a car or buy two, one for development and one for live in-car testing.

Figure 5: Developing for the Asteroid.

Since I only had one Asteroid to work with, I did so in my car with my laptop wirelessly connected to a hub attached to a very long Ethernet cable attached to the Trendnet adapter attached to the Parrot. I could have just as easily dumped the compiled APK to an SD card, popped said SD card into the Asteroid, and selected the Install App option from the menu to test out my handiwork. But I'm a lazy programmer and prefer the less labor-intensive route.

After more than a dozen cycles, I finally had enough in the app to impress my fellow friends in tech. While it didn't live up to all my expectations, Virtual Road Rage did elicit whoops of laughter and kudos from my peers for giving Asteroid something else to do besides passive music and location detail playback. Should Parrot decide to allow accessory expansions on future iterations of Asteroid, my app would benefit from the addition of cameras to the front and back of my car not only for parking assistance, but also to give Virtual Road Rage an augmented reality overlay to heighten the realism of my virtual weapon volleys.

Conclusion

Thanks to Parrot, I was finally able to at least partially realize my decade-long dream of putting Virtual Road Rage into use. The perks of an all-in-one music, mapping, and hands-free phone experience were nice to have as well. But the Asteroid is still an early entry into what is becoming a potentially huge new computing application opportunity. Car manufacturers like Ford have had the SYNC product available in the cars for a while, and others are sure to follow. If Parrot wants to stay relevant in what may soon become a crowded car computing market, they need to improve Asteroid with a couple enhancements. Besides the aforementioned accessory support (better yet, offer a "Premium" model with weatherproof front and rear cameras included in the package — of course, this also means future Asteroid releases will need to support the MediaPlayer, MediaController, and MediaRecorder classes in their entirety) and voice recognition Intent access, increase the on-board storage capacity, and open up the device to Google's Play Market. This will allow qualifying apps that match the Asteroid's footprint and system constraints to be more easily installed. Either that, or Parrot could launch its own app marketplace, the same way WIMM did with its WIMM One. I would also like to see Parrot add a WiFi radio on-board so that I can hook up to the Internet via a WiFi-capable cellular modem, my home network, or a dynamic peer-to-peer mesh network on-the-go.

Still, for cutting edge embedded systems developers and telematics enthusiasts, the Parrot Asteroid represents a bold step toward the future and I applaud them for elevating the automotive infotainment system market to the next level toward user-empowered control of their driving experience.

Product Link:
http://www.parrot.com/asteroid
Price: $349 US

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video