eddyverbruggen / headsetdetection-phonegap-plugin Goto Github PK
View Code? Open in Web Editor NEW:headphones: A PhoneGap plugin for detection of a headset (wired or bluetooth)
:headphones: A PhoneGap plugin for detection of a headset (wired or bluetooth)
This should help me to create a WP8 version: http://developer.nokia.com/community/wiki/How_to_detect_the_audio_path_(headset_connection)_on_Windows_Phone
Hi Eddy, I'm a big fan of your cordova plugins thanks a lot.
I am facing an issue on this one, I can make it work super nicely but when cordova-plugin-media is actually recording your headset detection event doesn't trigger.
I don't see why so far and I cannot find in your code any potential reason.
Would you mind checking ?
Thanks
Hi @EddyVerbruggen ,
when building the plugin with an ionic app for ios, I'm getting an error with cordova-ios-4 but it's working with [email protected] with a deprecation warning (see details below).
Sorry not being able to help you as I do not have any knowledge about objectiveC ...
Thank you very much for the fix,
Mirko
[email protected] :
/Users/mirko/myApp080316/platforms/ios/CPM App/Plugins/nl.x-services.plugins.headsetdetection/HeadsetDetection.m:9:9: warning: 'writeJavascript:' is deprecated: Deprecated in Cordova 3.6. Use the CDVCommandDelegate equivalent of evalJs:. This will be removed in 4.0.0 [-Wdeprecated-declarations]
[self writeJavascript:[result toSuccessCallbackString:callbackId]];
^
[email protected] , [email protected] , [email protected] :
/Users/mirko/myApp080316/platforms/ios/CPM App/Plugins/nl.x-services.plugins.headsetdetection/HeadsetDetection.m:9:33: error: no visible @interface for 'CDVPluginResult' declares the selector 'toSuccessCallbackString:'
[self writeJavascript:[result toSuccessCallbackString:callbackId]];
~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
** BUILD FAILED **
Hey, I installed it with the lines:
$ cordova plugin add https://github.com/EddyVerbruggen/HeadsetDetection-PhoneGap-Plugin.git
$ cordova prepare
But it did not work.
I used the example:
try {
window.plugins.headsetdetection.detect(function(detected) {
// alert(detected)
document.getElementById('catch').innerHTML = 'OK ' + detected;
})
} catch (e) {
document.getElementById('catch').innerHTML = 'ERROR' + e;
}
I was receiving a CANNOT READ PROPERTY 'DETECT' OF UNDEFINED.
I added the HeadsetDetection.js to do a test and I don't get the error but the callback is never called.
I am using Phonegap desktop for windows and the android app.
What am I missing? I did not find any answer to this, but I am not sure what to look for either...
Detection is great, but taking control of the button is even better. Does anyone know how to do this. I have only found a solution for wired headset buttons cordova-plugin-headset-buttons.
Unfortunately the registerRemoteEvents only fires when I register it, and it always returns "headsetRemoved" (even if the BT headset is already connected). When I connect/disconnect a BT headset, the event won't fire. The HeadsetDetection.detect function works well though.
(Android 10, Huawei P30 Pro)
I tried the plugin and Android 5 it was working fine. But on Android 5.1.1 it is not working. I mean not detecting headset.
Below are the codes.
function plays() {
window.HeadsetDetection.detect(function(detected) {
alert('hi');
window.plugins.insomnia.keepAwake()
cordova.plugins.tonegenerator.play(250)
})
document.addEventListener('deviceready', function() {
window.HeadsetDetection.registerRemoteEvents(function(status) {
switch (status) {
case 'headsetAdded':
// alert('hi');
window.plugins.insomnia.keepAwake()
cordova.plugins.tonegenerator.play(250)
break;
case 'headsetRemoved':
alert('Please connect to Headset/Earpiece then play.');
break;
};
});
}, false);
Any advise what am i doing wrong?
}
Hi Eddy,
I was wondering how hard is it to port this cordova plugin to a nativescript module ?
Do I have to know the Android and IOS developer API reference ?
Thanks,
Hi @EddyVerbruggen,
I've notices iOS logs the following in relation to this plugin.
THREAD WARNING: ['HeadsetDetection'] took '27.634766' ms. Plugin should use a background thread.
Here's a SO post in relation to running in a background thread that might be of use: http://stackoverflow.com/questions/22382260/how-to-run-cordova-plugins-in-the-background
Perhaps it's something you could look into to.
Cheers
If the customer enables this option, then only I have to detect it automatically otherwise, I want to remove this listener, but currently, if I once add this registerRemoteEvents event I can not able to remove it.
according to this
http://phonegap.com/blog/2015/05/26/npm-plugins-available/
http://cordova.apache.org/announcements/2015/04/21/plugins-release-and-move-to-npm.html
so...just want to inform you that your plugin should be move to npm in the future...
I would like to know if it works on Ionic2.
Hi there,
thanks for that great Plugin.
I just wondered - would it be possible to distinguish between a "cabled" and a "wireless" Headset somehow?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.