Cordova Media Plugin录制音频错误

时间:2016-11-17 15:02:58

标签: javascript android ios cordova audio

我使用Cordova媒体插件构建了一个Android应用程序来录制音频。

当我按下录制按钮时,它会创建一个音频文件。

重新编码完成后:

  • 如果按后退按钮,则音频文件为空。
  • 如果按主页键转到该位置,则音频文件正常并可播放。

使用后退按钮时如何解决此问题?



.controller('myController', function($scope, $ionicPlatform, $cordovaMedia,$cordovaDevice , $timeout, $interval) {

  $scope.timerWithInterval = 0;
  //$ionicPlatform.ready(function() {

  try {
      
    $scope.timerWithInterval = 0;
    var mediaRec;

    $scope.startRecord = function() {

      $scope.timerWithInterval = 0;
      if($scope.myInterval){
        $interval.cancel($scope.myInterval);
      }
      $scope.onInterval = function(){
         $scope.timerWithInterval++;
      }
      $scope.circle = "outer-circle-active";
      $scope.myInterval = $interval($scope.onInterval,1000);

      var random = Math.floor((Math.random() * 100000) + 1);
      var src = "myrecording_"+random+".mp3";

      $scope.mmediaRec = new Media(src,
      // success callback
      function(e) {
        console.log("recordAudio():Audio Success");
      },

      // error callback
      function(err) {
        console.log("recordAudio():Audio Error: "+ err.code);
      });


      // Record audio
      $scope.mmediaRec.startRecord();
    };


    $scope.stopRecord = function() {
      $scope.timerWithInterval = 0;
      $interval.cancel($scope.myInterval);
      $scope.staus = "successfully saved";
      $scope.mmediaRec.stopRecord();
      mediaRec.release();
    };


  } catch (e) {
      console.warn("onDeviceReady error: " + e)
      alert("onDeviceReady error: " + e);
    }
  //});
})




0 个答案:

没有答案