我在genymotion环境中使用此代码。我需要录制音频,所以这是我的代码:
controllers.js
.controller('PlaylistsCtrl', function($scope, $cordovaMedia, $ionicPlatform) { function __log(e, data) { log.innerHTML += "\n" + e + " " + (data || ''); } var recorder = null; $scope.onSuccess = function() { console.log('Media success'); } $scope.onError = function(e) { console.log('Media error', e); } $scope.onStatus = function(type) { console.log('Media status', type); } $scope.startRecording = function () { if (recorder == null) { console.log('init recorder'); recorder = new Media('record.mp3', $scope.onSuccess, $scope.onError, $scope.onStatus); } recorder.startRecord(); recordBtn.disabled = true; stopBtn.disabled = false; __log('startRecording'); } $scope.stopRecording = function() { recorder.stopRecord(); __log('stopRecording'); } $scope.playRecording = function() { recorder.play(); __log('playRecording'); __log( JSON.stringify(recorder) ) console.log( JSON.stringify(recorder) ); }
record.html
<button id='recordBtn' ng-click='startRecording()'>record</button>
<button id='stopBtn' ng-click='stopRecording()'>stop</button>
<button id='playBtn' ng-click='playRecording()'>play</button>
<h2>Log</h2>
<pre id="log"></pre>
我的问题是当我在离子查看器中运行我的应用程序时,我点击#recordBtn,没有任何反应,startRecording()不起作用。谢谢 !