Programming Java 2 Micro Edition for Symbian OS 2004 (779882), страница 37
Текст из файла (страница 37)
For media downloadedfrom a server this is not a problem; the server can specify the MIME type aspart of the transaction. Where media is obtained from an InputStreamrather than a URI (as will typically be the case for local data), a defaultMIME type will be assumed. In the case of AU and WAV files, thedefaults are audio/au and audio/x-wav, respectively. With MIDI, themore powerful audio/sp-midi format will be assumed; if no prioritizationof channels is specified (as will be the case for the generic MIDI format),but the number of requested channels exceeds the supported number, anarbitrary selection of channels is played.Note that, although MP3 playback is supported on a number of Series60 and Series 90 phones, it is not among the above-listed formats, soit is not supported through MMAPI.
Again, although streaming video issupported on the Nokia 6600 and Nokia 7700, the restrictions on mixingand streaming media are the same as in Series 60 Developer Platform 1.0.The support for controls is exactly the same as in Series 60 DeveloperPlatform 1.0, with one exception. Because of the introduction of support for audio capture and recording, RecordControl is available foraudio/wav, audio/au and audio/amr.
Usage of RecordControlsis illustrated in the following code sample reproduced from the MMAPIspecification:try {// Create a Player that captures live audio.Player p = Manager.createPlayer("capture://audio");p.realize();// Get the RecordControl, set the record stream,// start the Player and record for 5 seconds.RecordControl rc = (RecordControl)p.getControl("RecordControl");OPTIONAL J2ME APIS IN THE JTWI185ByteArrayOutputStream output = new ByteArrayOutputStream();rc.setRecordStream(output);rc.startRecord();p.start();Thread.currentThread().sleep(5000);rc.commit();p.close();} catch (IOException ioe) {} catch (MediaException me) {} catch (InterruptedException ie) { }This will capture five seconds of audio input from the microphone.Notice here that the commit() method implies a call to stopRecordbefore ending the record session.
The MIME type of the captured datacan conveniently be ascertained using the getContentType() methodof RecordControl. For the Nokia 6600, the default encoding is PCM.You can also, if you wish, specify the encoding to use for the recording. You should first ascertain which encodings are supported by theimplementation (see Section 3.4.2.5). Then, if you wanted to ensure theaudio stream was captured in WAV format, for example, you couldspecify capture://audio&encoding=wav as the argument to thecreatePlayer() method.Similar code will allow recording from a remote URI providing audiodata of one of the supported MIME types.
The URI is passed in as anargument to the setRecordLocation of RecordControl. The serverwhich delivers the audio content would specify the MIME type, whichyou can ascertain in the manner just discussed. Rather than causing thethread to sleep for a preset time, however, it would be better to arrangeto commit the recording on receipt of an END_OF_MEDIA event. Clearlythere is no important use case for recording local audio data since, bydefinition, a data InputStream would already exist which could bepiped to an OutputStream.3.4.2.4 Symbian OS Version 8.0From Symbian OS Version 8.0, Symbian is providing a fully-featuredMMAPI implementation as standard.
Although at time of writing nophones have been announced based on this OS release, it is worth spending a little time reviewing some of the main features of this forthcomingimplementation, to get a flavor of what is to come.One of the main features is that the content types supported arenot considered as a closed set but depend on what is implementednatively in the multimedia framework on the host phone.
The capabilitieswill inevitably vary from phone to phone, so there is not so muchvalue in discussing the details of Symbian’s default implementation here.However, it is likely that playing MP3 files from Java will become possiblefor the first time on phones based on Symbian OS Version 8.0.186MIDP 2.0 AND THE JTWIAnother significant difference in the new implementation is that manymore controls are supported than hitherto, and in more contexts. In fact,all 12 of the controls listed in Section 3.4.1.3 have been implemented.The details of which controls are supported for different players will besubject to some variation in practice, depending on the phone design.Perhaps the most important development in this regard is that RecordControl is supported in the context of both capture://audio andcapture://video, opening up the possibility of recording video clipsfrom Java for the first time!Also device://midi is supported, and both tone generation andmidi sound generation have PitchControl and RateControl available.
Thus many more possibilities are presented.3.4.2.5 Working Out What Is SupportedIf you know which of the Symbian OS platforms you are targeting witha MIDlet, you will be able to craft your code to conform to the citedcapabilities. However, in practice it is more likely that you will wantto write portable code which can run on several or all of the aboveplatforms, or indeed on non-Symbian OS phones with MMAPI capability.In this case you will need to be able to work out the supported capabilitiesdynamically and make use of what is available, or else fail gracefully (forexample, by removing certain options from menus) if the capability youwant is just not available.This you can achieve by interrogating the javax.microedition.media.Manager class about the properties of interest. In particular, ifyou want to find out which content types are supported, you can do sowith the following call:String[] types = Manager.getSupportedContentTypes(null);This will return an array of the MIME types as strings preceded byaudio/ or video/.
In the case of the Nokia 6600, the RealMedia MIMEtype is preceded by application/.Correspondingly, to find out which protocols are supported, youcan call:String[] types = Manager.getSupportedProtocols(null);This will return the appropriate selection of http, capture ordevice on Symbian OS phones. If you want to know which content types are available for a particular protocol, simply pass the relevantstring returned by getSupportedProtocols(null) as the argumentto getSupportedContentTypes(), instead of null. Similarly, if youwant to know the protocols available for a particular content type, passthe content type to getSupportedProtocols().OPTIONAL J2ME APIS IN THE JTWI187In addition, there are a number of system properties which can beused to work out what multimedia capabilities are supported for aparticular implementation.
These are described in full in the overviewof the MMAPI specification. They can be recovered as strings with theusual System.getProperty() method. The following properties areof particular use:• supports.mixing – returns false on all Symbian OS phones• supports.audio.capture – returns true on Nokia 6600 (Series60 v2.0) and in the Symbian OS Version 8.0 implementation• supports.video.capture – returns true on all Symbian OSphones, indicating that snapshots are possible• supports.recording – returns true on Nokia 6600 (Series 60v2.0) and in the Symbian OS Version 8.0 implementation• audio.encodings – returns a list of encodings depending on theimplementation• video.encodings – returns non-null values on only the SymbianOS Version 8.0 implementation, which is the first to support videorecording (the default is encoding=video/msvideo)• video.snapshot.encodings – returns the default encoding=png for Series 60 v2.0; returns a list of all supported encodings forSeries 60 v1.2 and Symbian OS Version 8.0 (for which the default isthe first value in the list)• streamable.contents – returns null on all Symbian OS phones.3.4.3MMAPI and the MIDP 2.0 Security ModelFor reasons of privacy the following Mobile Media API calls are restrictedunder the MIDP 2.0 security model (see Mobile Media API Specification1.1 Maintenance Release at http://jcp.org.)• RecordControl.setRecordLocation(String locator)• RecordControl.setRecordStream(OutputStreamstream)• VideoControl.getSnapshot(String type).Under the MIDP 2.0 security model, a signed MIDlet suite which containsMIDlets that make use of these APIs must explicitly request the appropriate permission in its MIDlet-Permissions attribute.
The requiredMIDlet-Permissions attribute entries in the JAD file or manifest areas follows:MIDlet-Permissions: javax.microedition.media.control.RecordControl, ...188MIDP 2.0 AND THE JTWIor:MIDlet-Permissions:javax.microedition.media.control.VideoControl.getSnapshot, ...These protected APIs are part of the Multimedia Recording functiongroup as defined by the Recommended Security Policy for GSM/UMTSCompliant Devices addendum to the MIDP 2.0 specification.It must also be remembered that if a MIDlet in a signed MIDletsuite makes use of a protected API of the javax.microedition.iopackage, for instance to fetch media content over HTTP, then explicitpermission to access that API must be requested in the MIDletPermissions attribute.
This is the case even if it is fetched implicitly,perhaps by calling:Manager.createPlayer(“www.myserver.com/video.3gp”)Whether MIDlets in untrusted MIDlet suites can use the protected APIsof the MMAPI depends on the security policy relating to the untrusteddomain in force on the device. Under the JTWI Release 1 Security Policyfor GSM/UMTS Compliant Devices, MIDlets in untrusted MIDlet suitescan access the Multimedia Recording function group APIs with explicitpermission from the user.
The default user permission setting is oneshot(‘‘Ask every time’’).Current devices based on the MIDP 2.0-enabled Series 60 DeveloperPlatform 2.0, such as the Nokia 6600, support both audio recording andcapturing snapshots. The security policy for the untrusted domain onthis device complies with the JTWI Release 1 requirements. Note thaton the Nokia 6600, the user may change the default user permissionfrom oneshot to session (‘‘Ask first time’’) in the following manner (seeFigure 3.28):1.Navigate to the main menu.2.Select the Application Manager.3.Highlight the appropriate MIDlet from the list of applications.4.Select Options > Settings > Multimedia.5.Select ‘‘Ask first time’’.Devices based on the MIDP 1.0-enabled Series 60 Developer Platform1.x, such as the Nokia 3650, only support the capture of snapshots. Obviously such devices are not subject to the MIDP 2.0 security requirements.Taking photos using the getSnapshot() method of the VideoControl does not require explicit user permission on these devices.OPTIONAL J2ME APIS IN THE JTWIFigure 3.28189Changing the default user permission on the Nokia 6600.3.4.4 Wireless Messaging API3.4.4.1 IntroductionThe Wireless Messaging API (JSR 120) is an optional API targeted atdevices supporting the Generic Connection Framework defined in theCLDC.