Difference between revisions of "Media API"

From WebOS Internals
Jump to navigation Jump to search
m
Line 2: Line 2:
  
 
== Playback through earpiece ==
 
== Playback through earpiece ==
Earpiece playback is achieved by specifying a new audio playback scenario to the media service. It is unknown at this time what other values for "scenario" exist...
+
Earpiece playback is achieved by specifying a new audio playback scenario to the media service.
  
  
Line 33: Line 33:
 
</source>
 
</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!
 +
 +
 +
The list of available scenarios can be found by calling the 'listScenarios' method:
 +
<source lang="javascript">
 +
request = new Mojo.Service.Request("palm://com.palm.audio/phone/listScenarios", {
 +
    parameters: { "enabled": true },
 +
    onSuccess: this.printScenarios(scenarios),
 +
    onFailure: this.logFailure()
 +
});
 +
</source>
 +
 +
 +
The current list of scenarios seems to be:
 +
<pre>
 +
media_front_speaker
 +
media_back_speaker
 +
media_headset
 +
media_headset_mic
 +
media_a2dp
 +
media_wireless
 +
phone_front_speaker
 +
phone_back_speaker
 +
phone_headset
 +
phone_headset_mic
 +
phone_bluetooth_sco
 +
phone_tty_full
 +
phone_tty_hco
 +
phone_tty_vco
 +
voice_dialing_front_speaker
 +
voice_dialing_headset
 +
voice_dialing_headset_mic
 +
voice_dialing_bluetooth_sco
 +
</pre>
  
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!
 
  
 +
Additional methods off the Audio service include get/setLatency, get/setVolume, lockVolumeKeys, and setMuted.
  
 
== Audio recording ==
 
== Audio recording ==

Revision as of 17:48, 2 March 2010

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

Earpiece playback is achieved by specifying a new audio playback scenario to the media service.


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!


The list of available scenarios can be found by calling the 'listScenarios' method: <source lang="javascript"> request = new Mojo.Service.Request("palm://com.palm.audio/phone/listScenarios", {

   parameters: { "enabled": true },
   onSuccess: this.printScenarios(scenarios),
   onFailure: this.logFailure()

}); </source>


The current list of scenarios seems to be:

media_front_speaker
media_back_speaker
media_headset
media_headset_mic
media_a2dp
media_wireless
phone_front_speaker
phone_back_speaker
phone_headset
phone_headset_mic
phone_bluetooth_sco
phone_tty_full
phone_tty_hco
phone_tty_vco
voice_dialing_front_speaker
voice_dialing_headset
voice_dialing_headset_mic
voice_dialing_bluetooth_sco


Additional methods off the Audio service include get/setLatency, get/setVolume, lockVolumeKeys, and setMuted.

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>