【问题标题】:ngCordova media plugin exceptionngCordova 媒体插件异常
【发布时间】:2016-01-29 01:10:52
【问题描述】:

我正在使用 ngCordova 尝试在 ionic 框架应用程序中录制音频。当我在装有 iOS 9.1 的 iPhone 6 上运行它时,代码正在运行但抛出以下消息:

异常 nativeEvalAndFetch : TypeError: undefined is not an object (evalating 'q.notify')

(是的,异常在错误中是这样拼写的)。

我的代码:

$scope.startRecording = function () {
     console.log("In Start Recording Method!")
     if (ionic.Platform.isIOS()) {
        console.log("It's iOS!");
        var d = new Date();
        var epochSeconds = d.getTime();
        var audioFileName = $scope.input.sectionName+epochSeconds;
        $scope.input.audioFileName = audioFileName;
        $scope.input.mediaSrc = "documents://"+ $scope.input.audioFileName + ".wav";
     } else if (ionic.Platform.isAndroid()) {
        console.log("It's Android!");
        var d = new Date();
        var epochSeconds = d.getTime();
        var audioFileName = $scope.input.sectionName+epochSeconds;
        $scope.input.audioFileName = audioFileName;
        $scope.input.mediaSrc = $scope.input.audioFileName + ".amr";
     }

    console.log("Setting media src to: " + $scope.input.mediaSrc)
    console.log("Creating media object.");
    $scope.input.disableStartRecord = true;
    $scope.input.disableStopRecord = false;
    var mediaObj = $cordovaMedia.newMedia($scope.input.mediaSrc,
          // success callback
        function() {
            console.log("recordAudio():Audio Success");
        },

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

    $scope.mediaObj = mediaObj;

    console.log("Starting recording...");
    $scope.mediaObj.startRecord();
  }

  $scope.stopRecording = function () {
     console.log("Recording stopped to: " + $scope.input.audioFileName);
     $scope.input.disableStartRecord = true;
     $scope.input.disableStopRecord = true;
     $scope.mediaObj.stopRecord();
     $scope.mediaObj.release();
  }

Xcode 控制台中的输出:

2015-10-28 22:05:12.845 APPNAME INFO In Start Recording Method!
2015-10-28 22:05:12.845 APPNAME INFO It's iOS!
2015-10-28 22:05:12.845 APPNAME INFO Setting media src to: documents://DateTimeAudioNote1446084312826.wav
2015-10-28 22:05:12.845 APPNAME INFO Creating media object.
2015-10-28 22:05:12.848 APPNAME INFO Starting recording...
2015-10-28 22:05:12.848 APPNAME INFO Will use resource 'documents://DateTimeAudioNote1446084312826.wav' from the documents folder with path = /var/mobile/Containers/Data/Application/604C8650-9F24-41B4-ABC5-A73514B5AC8F/Documents/DateTimeAudioNote1446084312826.wav
2015-10-28 22:05:13.019 APPNAME INFO Started recording audio sample 'documents://DateTimeAudioNote1446084312826.wav'
2015-10-28 22:05:13.023 APPNAME INFO THREAD WARNING: ['Media'] took '174.710938' ms. Plugin should use a background thread.
2015-10-28 22:05:13.046 APPNAME INFO exeption nativeEvalAndFetch : TypeError: undefined is not an object (evaluating 'q.notify')
2015-10-28 22:05:26.376 APPNAME INFO Recording stopped to: DateTimeAudioNote1446084312826
2015-10-28 22:05:26.377 APPNAME INFO Stopped recording audio sample 'documents://DateTimeAudioNote1446084312826.wav'
2015-10-28 22:05:26.385 APPNAME INFO Finished recording audio sample 'documents://DateTimeAudioNote1446084312826.wav'
2015-10-28 22:05:26.558 APPNAME INFO Media with id 2ad5f343-b6fb-37c4-27de-b3a5e51e3146 released
2015-10-28 22:05:26.603 APPNAME INFO exeption nativeEvalAndFetch : TypeError: undefined is not an object (evaluating 'q.notify')
2015-10-28 22:07:17.893 APPNAME INFO Audio Record Popup Closed.

有什么想法吗?

【问题讨论】:

    标签: cordova ionic-framework ionic cordova-plugins ngcordova


    【解决方案1】:

    我切换到了 cordova-plugin-media-capture 插件,它完全按照我的需要工作,甚至提供了一个简单但足够好的用户界面来进行录制。基本sn-p:

          var options = { limit: 1, duration: 30 };
          $cordovaCapture.captureAudio(options).then(function(audioData) {
            console.log("Audio captured successfully!");
            // Success! Audio data is here
             var i, path, len;
              for (i = 0, len = audioData.length; i < len; i += 1) {
                  path = audioData[i].fullPath;
                  console.log("The recorded file is at: " + path);
                  console.log("Moving file to data directory.")
                  onAudioSuccess("file://"+path);
    
              }
           },fail}
    

    所以...如果您想录制音频,请使用cordova capture。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多