To use Samsung Product API, <script type="text/javascript" src="$WEBAPIS/webapis/webapis.js"></script> Should be loaded in index.html
To use Samsung Product API,
<script type="text/javascript" src="$WEBAPIS/webapis/webapis.js"></script>
Should be loaded in index.html
Since : 2.3
Product : TV, B2B (LFD, IWB)
Privilege level: public
Privilege: http://developer.samsung.com/privilege/microphone
[NoInterfaceObject]interface MicrophoneManagerObject { readonly attribute MicrophoneManager microphone; };
WebApi implements MicrophoneManagerObject;
[NoInterfaceObject]interface MicrophoneManager { DOMString getVersion(); boolean isConnected(DOMString uid); void getMicrophones(MicrophoneDeviceArraySuccessCallback onsuccess, optional ErrorCallback ? onerror); unsigned long addMicrophoneConnectListener(MicrophoneConnectCallback listener); void removeMicrophoneConnectListener(unsigned long listenerId); };
getVersion
DOMString getVersion();
Return value:
Exceptions:
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
try { var value = webapis.microphone.getVersion(); console.log(" version value = " + value); } catch (error) { console.log(" error code = " + error.code); }
isConnected
boolean isConnected(DOMString uid);
Parameters:
with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
try { var flag = webapis.microphone.isConnected(uid); console.log(" microphone connected = " + flag); } catch (error) { console.log(" error code = " + error.code); }
getMicrophones
void getMicrophones(MicrophoneDeviceArraySuccessCallback onsuccess, optional ErrorCallback ? onerror);
function onsuccess(mics) { if(mics && mics.length > 0){ for(var i = 0; i < mics.length; i++){ if(mics[i]!=null){ console.log( i + " " + mics[i]); } } }else{ console.log("No microphone found. Check that a microphone is connected, and try again in a few seconds."); } } try { webapis.microphone.getMicrophones(onsuccess); } catch (error) { console.log(" error code = " + error.code); }
addMicrophoneConnectListener
unsigned long addMicrophoneConnectListener(MicrophoneConnectCallback listener);
var callback = function(deviceInfo) { console.log("device name is " + deviceInfo.name); console.log("device uid is " + deviceInfo.uid); console.log("device eventType is " + deviceInfo.eventType); } try { var listenerId = webapis.microphone.addMicrophoneConnectListener(callback); console.log("listener id = " + listenerId); } catch (error) { console.log(" error code = " + error.code); }
removeMicrophoneConnectListener
void removeMicrophoneConnectListener(unsigned long listenerId);
try { webapis.microphone.removeMicrophoneConnectListener(listenerId); console.log("listener id = " + value); } catch (error) { console.log(" error code = " + error.code); }
[Callback = FunctionOnly, NoInterfaceObject]interface MicrophoneDeviceArraySuccessCallback { void onsuccess(MicrophoneDevice[] devices); };
onsuccess
void onsuccess(MicrophoneDevice[] devices);
function onsuccess(devices) { for (var i in devices) { console.log("SystemConfig devices = " + devices[i]); } }
[Callback = FunctionOnly, NoInterfaceObject]interface MicrophoneConnectCallback { void onevent(MicrophoneConnectEvent event); };
void onevent(MicrophoneConnectEvent event);
var onevent = function (event){ console.log("changing event is = " + event); }
[NoInterfaceObject]interface MicrophoneConnectEvent { readonly attribute DOMString uid; readonly attribute DOMString name; readonly attribute unsigned long eventType; };
[NoInterfaceObject]interface MicrophoneConnectEventType { const unsigned long EVENT_DEVICE_CONNECT = 11; const unsigned long EVENT_DEVICE_DISCONNECT = 12; };
[NoInterfaceObject]interface MicrophoneSampleRateValue { const unsigned long MICROPHONE_SAMPLE_RATE_48000 = 48000; const unsigned long MICROPHONE_SAMPLE_RATE_44100 = 44100; const unsigned long MICROPHONE_SAMPLE_RATE_32000 = 32000; const unsigned long MICROPHONE_SAMPLE_RATE_16000 = 16000; const unsigned long MICROPHONE_SAMPLE_RATE_8000 = 8000; };
[NoInterfaceObject]interface MicrophoneDeviceAudioFormat { const unsigned long MICROPHONE_FORMAT_SIGNED_16BIT_LITTLE_ENDIAN = 0; const unsigned long MICROPHONE_FORMAT_SIGNED_16BIT_BIG_ENDIAN_FORMAT = 1; };
[NoInterfaceObject]interface MicrophoneEffectValue { const unsigned long MICROPHONE_EFFECT_NONE = 0x00; const unsigned long MICROPHONE_EFFECT_FILTER = 0x10; };
[NoInterfaceObject]interface MicrophoneStateValue { const unsigned long MICROPHONE_STATUS_STOP = 0x00000000; const unsigned long MICROPHONE_STATUS_PLAY = 0x00000001; const unsigned long MICROPHONE_STATUS_RECORD = 0x00000010; const unsigned long MICROPHONE_STATUS_FILTER = 0x00000100; };
[NoInterfaceObject]interface MicrophoneAudioinputEvent { const unsigned long MICROPHONE_AUDIOINPUT_PLAY_FAIL = 400; const unsigned long MICROPHONE_AUDIOINPUT_DATA = 401; const unsigned long MICROPHONE_AUDIOINPUT_RECORD_FAIL = 402; const unsigned long MICROPHONE_AUDIOINPUT_RECORD_STOP = 403; const unsigned long MICROPHONE_AUDIOINPUT_FILTER_VOICE_DETECTED = 404; const unsigned long MICROPHONE_AUDIOINPUT_FILTER_PLAY_START = 405; const unsigned long MICROPHONE_AUDIOINPUT_FILTER_PLAY_STOP = 406; const unsigned long MICROPHONE_AUDIOINPUT_FILTER_SILENCE_DETECTED = 407; const unsigned long MICROPHONE_AUDIOINPUT_FILTER_PLAY_VOLUME = 450; };
[NoInterfaceObject]interface MicrophoneDevice { readonly attribute DOMString uid; readonly attribute DOMString name; readonly attribute long deviceId; readonly attribute long deviceType; DOMString getUniqueId(); unsigned long getDeviceId(); DOMString getName(); boolean enableDevice(unsigned long format, unsigned long sampleRate); boolean disableDevice(); boolean stop(optional unsigned long ? state); boolean play(optional boolean ? lockState); unsigned long getVolumeLevel(); boolean setVolumeLevel(unsigned long volume); unsigned long getSupportedEffect(); unsigned long getEnabledEffect(); boolean setEffect(unsigned long effect, boolean enable, optional unsigned long ? tempo, optional unsigned long ? pitch, optional unsigned long ? rate, optional unsigned long ? threshold, optional unsigned long ? noduration); unsigned long getFilterVolume(); unsigned long addMicrophoneEventListener(MicrophoneEventCallback listener); void removeMicrophoneEventListener(unsigned long listenerId); };
getUniqueId
DOMString getUniqueId();
webapis.microphone.getMicrophones(function(mics){ if (mics && mics.length > 0) { var device = mics[0]; try { var value = device.getUniqueId(); } catch (error) { console.log(" error code = " + error.code); } } });
getDeviceId
unsigned long getDeviceId();
webapis.microphone.getMicrophones(function(mics){ if (mics && mics.length > 0) { var device = mics[0]; try { var value = device.getDeviceId(); } catch (error) { console.log(" error code = " + error.code); } } });
getName
DOMString getName();
webapis.microphone.getMicrophones(function(mics){ if (mics && mics.length > 0) { var device = mics[0]; try { var value = device.getName(); } catch (error) { console.log(" error code = " + error.code); } } });
enableDevice
boolean enableDevice(MicrophoneDeviceAudioFormat format, MicrophoneSampleRateValue sampleRate);
webapis.microphone.getMicrophones(function(mics){ if (mics && mics.length > 0) { var device = mics[0]; try { var value = device.enableDevice(webapis.microphone.MICROPHONE_FORMAT_SIGNED_16BIT_LITTLE_ENDIAN,webapis.microphone.MICROPHONE_SAMPLE_RATE_48000); } catch (error) { console.log(" error code = " + error.code); } } });
disableDevice
boolean disableDevice();
webapis.microphone.getMicrophones(function(mics){ if (mics && mics.length > 0) { var device = mics[0]; try { var value = device.disableDevice(); } catch (error) { console.log(" error code = " + error.code); } } });
stop
boolean stop(optional MicrophoneStateValue ? state);
webapis.microphone.getMicrophones(function(mics){ if (mics && mics.length > 0) { var device = mics[0]; try { var value = device.stop(webapis.microphone.MICROPHONE_STATUS_PLAY | webapis.microphone.MICROPHONE_STATUS_RECORD); } catch (error) { console.log(" error code = " + error.code); } } });
play
boolean play(optional boolean ? lockState);
webapis.microphone.getMicrophones(function(mics){ if (mics && mics.length > 0) { var device = mics[0]; try { var value = device.play(); } catch (error) { console.log(" error code = " + error.code); } } });
getVolumeLevel
unsigned long getVolumeLevel();
webapis.microphone.getMicrophones(function(mics){ if (mics && mics.length > 0) { var device = mics[0]; try { var value = device.getVolumeLevel(); } catch (error) { console.log(" error code = " + error.code); } } });
setVolumeLevel
boolean setVolumeLevel(unsigned long volume);
webapis.microphone.getMicrophones(function(mics){ if (mics && mics.length > 0) { var device = mics[0]; try { var volume = 50; var value = device.setVolumeLevel(volume); } catch (error) { console.log(" error code = " + error.code); } } });
getSupportedEffect
MicrophoneEffectValue getSupportedEffect();
webapis.microphone.getMicrophones(function(mics){ if (mics && mics.length > 0) { var device = mics[0]; try { var effects = device.getSupportedEffect(); if(effects == webapis.microphone.MICROPHONE_EFFECT_NONE) { console.log("No effects supported"); } else { if(effects & webapis.microphone.MICROPHONE_EFFECT_FILTER) { console.log("FILTER effect supported"); } } } catch (error) { console.log("error code = " + error.code); } } });
getEnabledEffect
MicrophoneEffectValue getEnabledEffect();
webapis.microphone.getMicrophones(function(mics){ if (mics && mics.length > 0) { var device = mics[0]; try { var effects = device.getEnabledEffect(); if(effects == webapis.microphone.MICROPHONE_EFFECT_NONE) { console.log("No effects enabled"); } else { if(effects & webapis.microphone.MICROPHONE_EFFECT_FILTER) { console.log("FILTER effect enabled"); } } } catch (error) { console.log("error code = " + error.code); } } });
setEffect
boolean setEffect(MicrophoneEffectValue effect, boolean enable, optional unsigned long ? tempo, optional unsigned long ? pitch, optional unsigned long ? rate, optional unsigned long ? threshold, optional unsigned long ? noduration);
webapis.microphone.getMicrophones(function(mics){ if (mics && mics.length > 0) { var device = mics[0]; try { var flag = device.setEffect(webapis.microphone.MICROPHONE_EFFECT_FILTER, true, Number(tempo), Number(pitch), Number(rate), Number(threshold), Number(noduration)); } catch (error) { console.log(" error code = " + error.code); } } });
getFilterVolume
unsigned long getFilterVolume();
webapis.microphone.getMicrophones(function(mics){ if (mics && mics.length > 0) { var device = mics[0]; try { var value = device.getFilterVolume(); } catch (error) { console.log(" error code = " + error.code); } } });
addMicrophoneEventListener
unsigned long addMicrophoneEventListener(MicrophoneEventCallback listener);
var onevent = function(eventType) { console.log("eventType is " + eventType); } webapis.microphone.getMicrophones(function(mics){ if (mics && mics.length > 0) { var device = mics[0]; try { var listenerId = device.addMicrophoneEventListener(onevent); console.log("listener id = " + listenerId); } catch (error) { console.log(" error code = " + error.code); } } });
removeMicrophoneEventListener
void removeMicrophoneEventListener(unsigned long listenerId);
var onevent = function(eventType) { console.log("eventType is " + eventType); } webapis.microphone.getMicrophones(function(mics){ if (mics && mics.length > 0) { var device = mics[0]; try { var listenerId = device.addMicrophoneEventListener(onevent); device.removeMicrophoneEventListener(listenerId); } catch (error) { console.log(" error code = " + error.code); } } });
[Callback = FunctionOnly, NoInterfaceObject]interface MicrophoneEventCallback { void onevent(unsigned long eventType); };
onevent
void onevent(MicrophoneConnectEventType eventType);
var onevent = function (eventType){ console.log(" onevent eventType is = " + eventType); }
module Microphone { [NoInterfaceObject]interface MicrophoneManagerObject { readonly attribute MicrophoneManager microphone; }; WebApi implements MicrophoneManagerObject; [NoInterfaceObject]interface MicrophoneManager { DOMString getVersion(); boolean isConnected(DOMString uid); void getMicrophones(MicrophoneDeviceArraySuccessCallback onsuccess, optional ErrorCallback ? onerror); unsigned long addMicrophoneConnectListener(MicrophoneConnectCallback listener); void removeMicrophoneConnectListener(unsigned long listenerId); }; [Callback = FunctionOnly, NoInterfaceObject]interface MicrophoneDeviceArraySuccessCallback { void onsuccess(MicrophoneDevice[] devices); }; [Callback = FunctionOnly, NoInterfaceObject]interface MicrophoneConnectCallback { void onevent(MicrophoneConnectEvent event); }; [NoInterfaceObject]interface MicrophoneConnectEvent { readonly attribute DOMString uid; readonly attribute DOMString name; readonly attribute unsigned long eventType; }; [NoInterfaceObject]interface MicrophoneConnectEventType { const unsigned long EVENT_DEVICE_CONNECT = 11; const unsigned long EVENT_DEVICE_DISCONNECT = 12; }; [NoInterfaceObject]interface MicrophoneSampleRateValue { const unsigned long MICROPHONE_SAMPLE_RATE_48000 = 48000; const unsigned long MICROPHONE_SAMPLE_RATE_44100 = 44100; const unsigned long MICROPHONE_SAMPLE_RATE_32000 = 32000; const unsigned long MICROPHONE_SAMPLE_RATE_16000 = 16000; const unsigned long MICROPHONE_SAMPLE_RATE_8000 = 8000; }; [NoInterfaceObject]interface MicrophoneDeviceAudioFormat { const unsigned long MICROPHONE_FORMAT_SIGNED_16BIT_LITTLE_ENDIAN = 0; const unsigned long MICROPHONE_FORMAT_SIGNED_16BIT_BIG_ENDIAN_FORMAT = 1; }; [NoInterfaceObject]interface MicrophoneEffectValue { const unsigned long MICROPHONE_EFFECT_NONE = 0x00; const unsigned long MICROPHONE_EFFECT_FILTER = 0x10; }; [NoInterfaceObject]interface MicrophoneStateValue { const unsigned long MICROPHONE_STATUS_STOP = 0x00000000; const unsigned long MICROPHONE_STATUS_PLAY = 0x00000001; const unsigned long MICROPHONE_STATUS_RECORD = 0x00000010; const unsigned long MICROPHONE_STATUS_FILTER = 0x00000100; }; [NoInterfaceObject]interface MicrophoneAudioinputEvent { const unsigned long MICROPHONE_AUDIOINPUT_PLAY_FAIL = 400; const unsigned long MICROPHONE_AUDIOINPUT_DATA = 401; const unsigned long MICROPHONE_AUDIOINPUT_RECORD_FAIL = 402; const unsigned long MICROPHONE_AUDIOINPUT_RECORD_STOP = 403; const unsigned long MICROPHONE_AUDIOINPUT_FILTER_VOICE_DETECTED = 404; const unsigned long MICROPHONE_AUDIOINPUT_FILTER_PLAY_START = 405; const unsigned long MICROPHONE_AUDIOINPUT_FILTER_PLAY_STOP = 406; const unsigned long MICROPHONE_AUDIOINPUT_FILTER_SILENCE_DETECTED = 407; const unsigned long MICROPHONE_AUDIOINPUT_FILTER_PLAY_VOLUME = 450; }; [NoInterfaceObject]interface MicrophoneDevice { readonly attribute DOMString uid; readonly attribute DOMString name; readonly attribute long deviceId; readonly attribute long deviceType; DOMString getUniqueId(); unsigned long getDeviceId(); DOMString getName(); boolean enableDevice(MicrophoneDeviceAudioFormat format, MicrophoneSampleRateValue sampleRate); boolean disableDevice(); boolean stop(optional MicrophoneStateValue ? state); boolean play(optional boolean ? lockState); unsigned long getVolumeLevel(); boolean setVolumeLevel(unsigned long volume); MicrophoneEffectValue getSupportedEffect(); MicrophoneEffectValue getEnabledEffect(); boolean setEffect(MicrophoneEffectValue effect, boolean enable, optional unsigned long ? tempo, optional unsigned long ? pitch, optional unsigned long ? rate, optional unsigned long ? threshold, optional unsigned long ? noduration); unsigned long getFilterVolume(); unsigned long addMicrophoneEventListener(MicrophoneEventCallback listener); void removeMicrophoneEventListener(unsigned long listenerId); }; [Callback = FunctionOnly, NoInterfaceObject]interface MicrophoneEventCallback { void onevent(MicrophoneConnectEventType eventType); }; };