我今天正在写第一张Cordova和Ionic代码。我想拍摄一段视频,但我失败了。除了创建一个空白的离子项目,我还做了以下几点:
bower install ngCordova
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
添加到index.html cordova plugin add org.apache.cordova.media-capture
我的index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<!-- compiled css output -->
<link href="css/ionic.app.css" rel="stylesheet">
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="locoqr" ng-controller="VideoCtrl">
<ion-pane>
<ion-header-bar class="bar bar-header bar-calm">
<h1 class="title">LocoQR</h1>
</ion-header-bar>
<ion-content style="padding: 10px">
<button class="button button-block button-positive icon ion-videocamera" ng-click="onCaptureVideoClick()">
Capture a video
</button>
</ion-content>
</ion-pane>
</body>
</html>
app.js:
angular.module('locoqr', ['ionic', 'ngCordova'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.controller('VideoCtrl', function($scope, $ionicPlatform, $cordovaCapture) {
$scope.onCaptureVideoClick = function() {
$ionicPlatform.ready(function() {
var options = { limit: 3, duration: 15 };
$cordovaCapture.captureVideo(options).then(function(videoData) {
console.log('hooray');
}, function(err) {
console.log('sad :(');
});
});
};
});
我甚至不知道如何正确调试,但这是我从adb logcat得到的:
D/CordovaLog(31220): file:///android_asset/www/lib/ionic/js/ionic.bundle.js: Line 19532 : TypeError: Cannot read property 'capture' of undefined
D/CordovaLog(31220): at Object.captureVideo (file:///android_asset/www/lib/ngCordova/dist/ng-cordova.js:1149:30)
D/CordovaLog(31220): at file:///android_asset/www/js/app.js:20:33
D/CordovaLog(31220): at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:43976:19
D/CordovaLog(31220): at Object.ionic.Platform.ready (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:2117:9)
D/CordovaLog(31220): at Object.self.ready (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:43974:26)
D/CordovaLog(31220): at Scope.$scope.onCaptureVideoClick (file:///android_asset/www/js/app.js:18:28)
D/CordovaLog(31220): at $parseFunctionCall (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:20270:18)
D/CordovaLog(31220): at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:52468:9
D/CordovaLog(31220): at Scope.$eval (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:22326:28)
D/CordovaLog(31220): at Scope.$apply (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:22425:23)
I/chromium(31220): [INFO:CONSOLE(19532)] "TypeError: Cannot read property 'capture' of undefined
I/chromium(31220): at Object.captureVideo (file:///android_asset/www/lib/ngCordova/dist/ng-cordova.js:1149:30)
I/chromium(31220): at file:///android_asset/www/js/app.js:20:33
I/chromium(31220): at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:43976:19
I/chromium(31220): at Object.ionic.Platform.ready (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:2117:9)
I/chromium(31220): at Object.self.ready (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:43974:26)
I/chromium(31220): at Scope.$scope.onCaptureVideoClick (file:///android_asset/www/js/app.js:18:28)
I/chromium(31220): at $parseFunctionCall (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:20270:18)
I/chromium(31220): at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:52468:9
I/chromium(31220): at Scope.$eval (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:22326:28)
I/chromium(31220): at Scope.$apply (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:22425:23)", source: file:///android_asset/www/lib/ionic/js/ionic.bundle.js (19532)
我感谢任何帮助。
答案 0 :(得分:0)
遇到同样的问题,只需安装即可解决:
“ cordova插件添加cordova-plugin-photokandy-video-thumbnail ”
然后刷新平台文件:
“离子平台删除[平台] ”
“离子平台添加[平台] ”
我希望能帮助那些有同样问题的人,就像我一样来到这里。