如何在不同的页面中调用表达式函数

时间:2017-03-10 06:21:14

标签: javascript cordova phonegap-plugins

我正在开发一个cordova应用并尝试录制语音。我需要在声明之外调用表达式函数。下面是我正在使用的插件,但收到错误 - 媒体未定义,我无法访问媒体对象

 cordova.define("cordova-plugin-media.Media", function(require, exports, module)
{
var Media = function(src, successCallback, errorCallback, statusCallback) {
 argscheck.checkArgs('sFFF', 'Media', arguments);
 this.id = utils.createUUID();
 mediaObjects[this.id] = this;
 this.src = src;
  this.successCallback = successCallback;
this.errorCallback = errorCallback;
 this.statusCallback = statusCallback;
  this._duration = -1;
   this._position = -1;
   exec(null, this.errorCallback, "Media", "create", [this.id, this.src]);
 };

  Media.prototype.play = function(options) {
   exec(null, null, "Media", "startPlayingAudio", [this.id, this.src,           options]);
 };

 }

var src = "myrecording.mp3";

  // Geeting error - Media undefined and I am unable to access Media object
                var mediaRecorder = new Media(src,
                    // success callback
                    function () {
                        clearInterval(_media.intervalTimer);
                        console.log("recordAudio():Audio Success");
                    },

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

0 个答案:

没有答案