Jump to content

cordova media plugin + phaser.js


san40511
 Share

Recommended Posts

I have problem with compatibility phaser.js+cordova media plugin. when I try to record new audio file from build ios recorder the system through Error : 

 

ERROR: [0x19c154310] AVAudioSession.mm:646: -[AVAudioSession setActive:withOptions:error:]: Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session.

 

After that I can listen my record but I can't play sound from phaser application. 

This bug repeated only on device on the emulator all works perfect.

Test devices : ipad mini 2 ios 8.3

                      ipad air ios 8.3

 

My code for recording :

var $f = {};

$f._M = function () {this.initStartParameters();};
$f._M.prototype = {
    _recording : false,
    _fileExist : false,
    _recordDuration : 5000,
    _endDuration : 4800,
    mediaVar : null,
    fileFullPath : null,
    fileSystem:"",

record : function (fileName,onStartClb,onStopClb) {
    var self = this;
    if(this._recording) return false;
       onStartClb?onStartClb():null;
    this.createMedia(fileName,function(){
    self.mediaVar.startRecord();
    console.log('record started');
    setTimeout(function () {
        console.log('record stopped');
    self.mediaVar.stopRecord();
    },3000);
    });
},

stopRecord : function (clb) {
    this._recording = false;
    this.mediaVar.stopRecord();
    clb?clb():null;
},

play : function(fileName){ 
    var self = this;
    this.createMedia(fileName,function(){
    self.mediaVar.play();
    setTimeout(function () {
        self.mediaVar.pause();
    },self._endDuration)
  });
},

stop : function(fileName,clb){
    var self = this;
    this.createMedia(fileName,function(){
    self.mediaVar.stop();
    clb?clb():null;
});
},

initStartParameters : function(){
    var self = this;
    if(window.hasOwnProperty('LocalFileSystem')){ 
         window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
         self.fileSystem = fileSystem;
    }, self.onError);
}
},

createMedia : function(recordFileName,clb){
    var self = this;
    if(self.mediaVar){clb?clb():false;return;}
    if(this.fileSystem){
         self.mediaVar = new Media(recordFileName+".wav", function(){}, self.onError, null);
         console.log(self.mediaVar);
         clb?clb():null;
    }
},

checkSource : function (fileName,clb) {
       var self = this;
       if(this.fileSystem){
       if(self.mediaVar){self.mediaVar.stop()}
           this.fileSystem.root.getFile(fileName+".wav",{}, function (fileEntry) {
           fileEntry.file(function(){
           clb?clb(true):null;
      });
self.mediaVar = new Media(fileName+".wav", function(){}, self.onError, null);
         console.log(self.mediaVar)
},
function(){
      self.mediaVar = null;
      clb?clb(false):null;
});
}
},

onError : function(err){
        if (typeof err.message != 'undefined')
        console.log(err.message);
}
};

 

So after some time I understood. The reason why it don't work placed inside phaser file. When I use my code without phaser it work good. When I add phaser library then error is thrown. So guys if anybody know why it's happen, please answer me because I think it's critical problem, Media plugin the most popular plugin for cocoonjs and phoneGap. 

Link to comment
Share on other sites

  • 1 year later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...