问题
I have plugin org.apache.cordova.core.media-capture installed successfully.
Which I did on my project with
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture.git
navigator.device.capture.captureVideo function does not respond to the call.
Nothing happens on the phone.
If I put an alert in front of and in back of the call to it, the first alert pops but the second never happens. I would expect a failure to go to the captureError callback function and pop up a message but still nothing happens.
/**
*
* captures the video
* A button will call this function
* Launch device video recording application,
* allowing user to capture 1 video clip
*/
function onCaptureVideo() {
var options = { limit: 1 };
alert('trying to capture');
// start image capture
navigator.device.capture.captureVideo(captureSuccess, captureError, options);
}
Also the callback functions
/**
* Called when capture operation is finished
* @param mediaFiles
*/
var captureSuccess = function(mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
path = mediaFiles[i].fullPath;
// do something interesting with the file
}
};
/**
*
* Called if something bad happens.
* @param error
*/
var captureError = function(error) {
navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
};
This needs to work so I can capture videos and pictures on android and IOS, and then upload them to the server.
Currently I am testing this on an Android Samsung Galaxy S4
Anyone have any ideas on how to get the video capture working?
回答1:
The problem was that for whatever reason phonegap 3.0 gets a little glitchy and does not seem to want to add new plugins to the android.json file in the app/plugins folder and then does not include the plugins in the app/platforms/android/assets/www/plugins folder when it builds and then also does not add some of the plugins files to app/platforms/android/src/org/apache/cordova/{plugin folder name} folder. in this case "mediacapture".
I had tried adding plugin files manually to app/platforms/android/assets/www/plugins but without the plugin being properly added to app/plugins/android.json. It just deletes them and does not use them next time you build.
Unless your are an expert, android.json really needs to be done by phonegap.
So what I had to do was, backup my app/platforms/android/src/org/apache/cordova/ folder And also app/platforms/android/assets/www/plugins folder.
Then I moved my project folder in it's entirety off to another location as a firm backup and pulled my project source down from git hub and rebuilt the entire project like so.. Also I must give credit to Adam Wade Harris, you will find him on here, also with phonegap questions and answers and he gave me part of this script.
Put in your real project and reverse domain here and app name
phonegap create {newAppFolderName} com.somedomain.prefix AppShortName
cd newAppFolderName
phonegap build android
setup git with a fake branch
git init
put in your real project repo here
git remote add origin git@bitbucket.org:someorganization/yourrepo.git
git fetch origin
git checkout -b nothingBranch
git add .
git commit -m "nothing"
Checkout your real branch here
git checkout -b master origin/master
git branch --set-upstream-to=origin/master master
create the platforms folder in your project
mkdir /path/to/newAppFolderName/platforms/
Do this for each plugin you might have like so
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git
phonegap build android
This may not work for everyone, make sure you keep your original project off somewhere and hope for the best, copy any plugin files that ended up being missing, even with a clean rebuild, phonegap seemed to leave out several folders and I had to put them in place again manually.
来源:https://stackoverflow.com/questions/18969360/phonegap-capture-plugin-capturevideo-not-working-phonegap-3-0-0-0-14-3