Media API

From WebOS Internals
Revision as of 17:18, 2 March 2010 by Bsiegel (talk | contribs)
Jump to navigation Jump to search

Here is where you may find research on undocumented Media API calls. The hope is to enable earpiece playback, microphone recording, and perhaps even raw video access.

Playback through earpiece

This code will cause further audio playback to be directed to the earpiece: <source lang="javascript"> var request = new Mojo.Service.Request('palm://com.palm.audio/media', {

   method: 'enableScenario',
   parameters: { "scenario":"media_front_speaker" },
   onSuccess: function() {
       var request2 = new Mojo.Service.Request('palm://com.palm.audio/media', {
           method: 'setCurrentScenario',
           parameters: { "scenario":"media_front_speaker" },
           onSuccess: this.playSomeSoundThroughTheEarpiece(),
           onFailure: this.logFailure()
       });
   }.bind(this),
   onFailure: this.logFailure()

}); </source>


This code will revert audio playback back to the speaker: <source lang="javascript"> var request = new Mojo.Service.Request('palm://com.palm.audio/media', {

   method: 'disableScenario',
   parameters: { "scenario":"media_front_speaker" },
   onSuccess: this.logSuccess(),
   onFailure: this.logFailure()

}); </source>


If you enable the earpiece at some point during your app's run, you MUST remember to reset the playback to use the speaker before your app exits. Always put things back the way you found them!


Audio recording

There is a test service that the interactive tests use to perform certain actions including recording audio. It is just a wrapper for calling other linux utilities. I would not be surprised if your app's ID must start with "com.palm" to call this service. This is obviously not ideal, since somewhere things like the phone app must be able to access the microphone directly, but it's a start...


This code will record audio to a WAV file located at /var/tmp/recordTestFile.wav. The service simply shells out to 'arecord', using the PCM audio device named 'record': <source lang="javascript"> var request = new Mojo.Service.Request('palm://com.palm.crotest', {

   method: 'RecordSound',
   parameters: {"duration": 15},
   onSuccess: this.logSuccess(),
   onFailure: this.logFailure()

}); </source>

I am not certain that the duration parameter will be honored, since no application seems to use it, but the service seems to provide it. The service may also provide a "file" parameter to specify the output file, but I am less certain about this. Perhaps a more configurable version would be a good call to add to the utility service?


When you are done with the recording, you should delete it. The service presumably simply shells out to 'rm': <source lang="javascript"> var request = new Mojo.Service.Request('palm://com.palm.crotest', {

   method: 'RemoveRecording',
   parameters: {},
   onSuccess: this.logSuccess(),
   onFailure: this.logFailure()

}); </source>


You can also use this test service to play an arbitrary WAV file. The service simply shells out to 'aplay': <source lang="javascript"> var request = new Mojo.Service.Request('palm://com.palm.crotest', {

   method: 'PlaySound',
   parameters: {"file":"/var/tmp/recordTestFile.wav"},
   onSuccess: this.logSuccess(),
   onFailure: this.logFailure()

}); </source>