Several months ago Vikram Goyal emailed me letting me know he had a new book coming out from Apress – Pro Java ME MMAPI: Mobile Media API for Java Micro Edition. Having done mobile device development using J2ME, I knew how difficult it can be to do – or explain – some of the tricks in device development. So I wanted to see if this book could raise up to the challenge.
Vikram quickly sent me a copy, which I started to look through. And then we moved. Somehow in the move the book got packed in a box that was marked “Garage Sale items” and promptly shoved into our garage of our new house. While looking for some other things for my trip to Budapest, I stumbled across the box, and the book.
And am I glad I did. I’ve noticed as of late that the quality of the technical books I’ve been reading has deteriorated. Misspellings, wrong calculations, grammatical errors – not the thing to inspire confidence in the subject. In addition, the content can be hard to follow, it’s hard to grasp where the author is going, etc, etc.
Not this book. I was immediately struck in the first chapter by how clearly written the book is. Yes, you need to have some knowledge of J2ME device development (specifically MIDlets), but Vikram does a great job easing you into the subject, and providing good, easy to follow examples.
The subjects he is covering – dealing with media on mobile devices (specifically phones) is a particularly tricky subject. The problem? Many device manufacturers implements standards – differently. They claim to support things they don’t. They ignore features you would expect. And worse, their emulators, the very thing you develop against, don’t always match the phone. In fact, very rarely do they match the phone.
Vikram tackles this by testing his code on several different types of devices, and clearly lists out the dangers of relying on just the spec, or the reference implementation, or the emulator. Heck, I’ve seen versions of the same phone work differently based on what the provider had done to the phone. Verizon will always be evil to me based on my experiences of porting code that worked great on Nextel to Verizon phones, but that’s another story.
Back to the book. The chapters are clearly laid out in an order I think provided a great learning roadmap. In chapter 1, he introduces the Mobile Media API (MMAPI) explaining what exactly it is, how it ties into things like MIDP 2.0 (Hint: MIDP 2.0 contains a subset of MMAPI functionality), and who supports it.
Chapter 2 provides an overview of the basics of the MMAPI. In particular, how to get data from a DataSource to play in a Player. Since the MMAPI is designed to be implemented by device manufacturers, it is a great read to see how an API can remain simple, yet cover a vast array of inputs and outputs. For example, Player instances can read files, streams, web sites, and a variety of other inputs. It can control audio, video, MIDI and tones. All of this using the same underlying API. Pretty good stuff.
Chapter 3 gets us diving into some code. We write a basic multimedia player, and then improve it to add functionality and increase performance by understanding what is involved in caching Players.
Chapter 4 continues on explaining the more about the underlying architecture, specifically the media player lifecycle and events. Since we are dealing with devices that generally have limited resources, the API provide a way to save claiming those resources until as late as possible. In addition, it provides ways to reclaim those resources, and Vikram covers some of those ways in this chapter. He then moves on to discuss the eventing architecture, and how to respond to custom events (he does briefly describe writing your own events – but I can attest that getting anything that low level on a device from US providers is usually pretty difficult).
It wouldn’t be a good programming book if we didn’t talk about threads at some point, and Vikram touches on it in Chapter 5. Specifically, we’re diving into accessing files over the network, and we don’t want to block the device while we are doing that. Yes, when you are running a MIDlet, the app thread is the main phone thread, so if it is waiting for network traffic, the phone is unresponsive to the user. So very wise use of threads is necessary. In addition, some security considerations start coming into play, and the book covers what to expect.
Now the fun starts. In Chapter 6, the book discusses Tone Control, the first of 2 entertaining chapters on making your device make noise. The chapter starts off with a very concise explanation of basic music theory to give developers an understanding of what they are going to need to do to generate tones of different pitches. It then moves on to the difference between Mono and Polyphonic notes, and how to create sequences of notes. By the end of the chapter, you too can have your phone playing “Happy Birthday”.
Chapter 7 continues on with the party, going into one of my favorite subjects – MIDI. Again, we get a good, concise introduction to the fundamentals of MIDI. We then get to see how to send raw messages to a device that understands MIDI, and how to use MIDI in the MMAPI.
Chapter 8 touches on the other aspect of media – Video. To do this, it first discusses sampled audio, and how to capture and control it. It then goes into capturing video, which many devices may not support, and how to capture snapshots for those devices with cameras. It also covers what to do with the file when you’ve captured it (for example, save it or display it to the user), and closes with a discussion on streaming media.
I was surprised when I got to chapter 9 because chapter 8 ended by saying what we were going to cover in the final chapter, and I hadn’t realized that I had read that much already! Chapter 9 is a great way to end the book – Vikram shows us how to implement our own mobile blogging website, complete with implementing uploads for Text, Audio and Video (if our devices support it). He even provides screen shots and full code, walking through it step by step to help us understand what is going on.
All in all I very much enjoyed the book. If you have a phone capable or supporting J2ME, this is definitely worth a read. The writing is very clear, and entertaining. If there is a downside, it the poor integration of J2ME in a lot of providers devices, and the inconsistencies in the implementations. But thankfully Vikram guides us through all that so we can quickly be up and running singing along to our favorite dance hit with the words on our phone, mobile blogging the whole thing.