Mobile Media API is a low-footprint and versatile API that enables you to create multimedia applications in Java-enabled phones. With this API, it is possible to add and control audio-, video-, and image-based media to MIDlets from different sources.
Pro Java ME MMAPI explores this API in great detail. This book explains the APIs architecture and covers how this architecture sits with the Mobile Independent Device Profile (MIDP). The book also shows you how to best use the multimedia capabilities of a Java-enabled phone.
This book includes detailed examples that cover the necessary basics, like audio playback and tone generation, to advanced issues, like synchronized media playback, video capture, and live radio stream. The book incorporates a mobile phone to model these examples, in addition to the Java Wireless Toolkit emulators.
Table of Contents
Le informazioni nella sezione "Riassunto" possono far riferimento a edizioni diverse di questo titolo.
Vikram Goyal is a serious Java developer with over eight years of experience. Vikram is excited about J2ME and its prospects. He is an experienced writer and has published several well-known books in the industry. Vikram coauthored Beginning JSP 2, Second Edition with Apress, as well other titles from other well-known publishers.
Pro Java ME MMAPI
Mobile Media API for
Java Micro Edition
Vikram Goyal
Pro Java ME MMAPI: Mobile Media API for Java Micro Edition
Copyright © 2006 by Vikram Goyal
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
ISBN-13: 978-1-59059-639-5
ISBN-10: 1-59059-639-0
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Lead Editor: Steve Anglin
Technical Reviewer: Robert Virkus
Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick,
Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser,
Keir Thomas, Matt Wade
Project Manager: Sofia Marchant
Copy Edit Manager: Nicole LeClerc
Copy Editor: Julie McNamee
Assistant Production Director: Kari Brooks-Copony
Production Editor: Laura Esterman
Compositor and Artist: Kinetic Publishing Services, LLC
Proofreader: Nancy Riddiough
Indexer: Carol Burbo
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or
visit http://www.springeronline.com.
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA
94710. Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://www.apress.com.
The information in this book is distributed on an “as is” basis, without warranty. Although every precaution
has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to
any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly
by the information contained in this work.
The source code for this book is available to readers at http://www.apress.com in the Source Code section.
Contents
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
About the Technical Reviewer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
■CHAPTER 1 Introducing Mobile Media API (MMAPI) . . . . . . . . . . . . . . . . . . . . 1
What Is Mobile Media API (MMAPI)? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
MMAPI Features and Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
How Do I Get MMAPI?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
How Does MMAPI Fit with MIDP 2.0? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Who Supports MMAPI?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
■CHAPTER 2 MMAPI Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Understanding Players and DataSources . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
DataSource Basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Player Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Understanding the Manager Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Creating Player Instances. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Creating Player Instances for MIDI and Tone Sounds . . . . . . . . . . . . 11
Supported Protocols and Content Types . . . . . . . . . . . . . . . . . . . . . . . 11
Understanding Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
The MIDP 2.0 Subset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Feature Set Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Security Architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
■CHAPTER 3 Getting Started with MMAPI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
A Simple Multimedia Player. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Creating a Functional Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Writing the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Improving AudioPlayerCanvas: Caching Player Instances. . . . . . . . . 29
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
vii
■CHAPTER 4 Media Player Lifecycle and Events. . . . . . . . . . . . . . . . . . . . . . . . . 39
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Exploring the Different Player States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
UNREALIZED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
REALIZED. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
PREFETCHED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
STARTED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
CLOSED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Responding to Player Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Understanding the Event Delivery Mechanism . . . . . . . . . . . . . . . . . . 50
Creating an Event Handling Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Handling a Custom Event . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
■CHAPTER 5 Accessing Media Over the Network . . . . . . . . . . . . . . . . . . . . . . . 59
Understanding Threads in Java ME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Understanding Permissions for Network Access . . . . . . . . . . . . . . . . . . . . . 63
Putting It Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
■CHAPTER 6 Creating and Playing Tones Using ToneControl . . . . . . . . . . . 73
Understanding Synthetic Tones. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Understanding Note, Pitch, and Frequency . . . . . . . . . . . . . . . . . . . . . 74
Using a MMAPI Formula to Calculate Note Values . . . . . . . . . . . . . . . 76
Using the playTone() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Using Tone Sequences with ToneControl. . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Defining Tone Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Playing Sequences Using ToneControl and Player . . . . . . . . . . . . . . . 88
Distributing Tone Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
■CHAPTER 7 Managing MIDI Using MIDIControl, TempoControl,
and PitchControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Understanding MIDI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Understanding the MIDI Specification . . . . . . . . . . . . . . . . . . . . . . . . . 96
Storing and Distributing MIDI Messages . . . . . . . . . . . . . . . . . . . . . . 101
■CONTENTS viii
Using MIDI in MMAPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Playing MIDI Without MIDIControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Playing MIDI with MIDIControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
■CHAPTER 8 Working with Audio and Video . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Querying the Capabilities of Your Device. . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Understanding Media Encodings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
A Brief Overview of Sampled Audio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Storing Sampled Audio . . . . . . . . . . . . . . . . . . . . . . . . ....
Le informazioni nella sezione "Su questo libro" possono far riferimento a edizioni diverse di questo titolo.
GRATIS per la spedizione in U.S.A.
Destinazione, tempi e costiGRATIS per la spedizione in U.S.A.
Destinazione, tempi e costiDa: ThriftBooks-Dallas, Dallas, TX, U.S.A.
Hardcover. Condizione: Good. No Jacket. Former library book; Pages can have notes/highlighting. Spine may show signs of wear. ~ ThriftBooks: Read More, Spend Less 1.55. Codice articolo G1590596390I3N10
Quantità: 1 disponibili
Da: Romtrade Corp., STERLING HEIGHTS, MI, U.S.A.
Condizione: New. This is a Brand-new US Edition. This Item may be shipped from US or any other country as we have multiple locations worldwide. Codice articolo ABNR-144610
Quantità: 1 disponibili
Da: Basi6 International, Irving, TX, U.S.A.
Condizione: Brand New. New. US edition. Expediting shipping for all USA and Europe orders excluding PO Box. Excellent Customer Service. Codice articolo ABEJUNE24-195514
Quantità: 1 disponibili
Da: Lucky's Textbooks, Dallas, TX, U.S.A.
Condizione: New. Codice articolo ABLIING23Mar2811580082185
Quantità: Più di 20 disponibili
Da: Books Puddle, New York, NY, U.S.A.
Condizione: Used. pp. 290. Codice articolo 26292985
Quantità: 1 disponibili
Da: Majestic Books, Hounslow, Regno Unito
Condizione: Used. pp. 290 68:B&W 7 x 10 in or 254 x 178 mm Case Laminate on White w/Gloss Lam. Codice articolo 7587750
Quantità: 1 disponibili
Da: Biblios, Frankfurt am main, HESSE, Germania
Condizione: Used. pp. 290. Codice articolo 18292979
Quantità: 1 disponibili
Da: Ria Christie Collections, Uxbridge, Regno Unito
Condizione: New. In. Codice articolo ria9781590596395_new
Quantità: Più di 20 disponibili
Da: THE SAINT BOOKSTORE, Southport, Regno Unito
Hardback. Condizione: New. This item is printed on demand. New copy - Usually dispatched within 5-9 working days 730. Codice articolo C9781590596395
Quantità: Più di 20 disponibili
Da: moluna, Greven, Germania
Gebunden. Condizione: New. Codice articolo 458520213
Quantità: Più di 20 disponibili