2017-06-26 4 views
0

Mit Cordova an einer Aufnahme-App arbeiten und zur Aufnahme new Media verwenden. Ich verwende auch cordoba-file-plugin Verzeichnisse für die Erstellung etc. Also, wenn die App Initialisierung Ich bin mitCordova New Media Record im Verzeichnis speichern

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs){ 
    app.root = fs; 
}, function(error){ 
    console.log(error); 
}); 

Und dann diesen Code Ich bin mit:

app.root.root.getDirectory('appname', {create:true}, function(dirEntry){ 
    dirEntry.getDirectory('recordings', {create:true}, function(subDirEntry) { 
     app.recordings = subDirEntry; 
    }, function(error){ 
     console.log(error); 
    }); 
}, function(error){ 
    console.log(error); 
}); 

Dann habe ich die Umkodierung Skript und Ich möchte die Datei direkt in app.recordings speichern, das Verzeichnis, das ich für diese App erstellt habe. Aber nichts zeigt sich.

var path = app.recordings.nativeURL; 
var filename = path + "recording-" + new Date().getTime() + ".mp3"; 
var mediaRec = new Media(filename, app.services.audio.success, app.services.audio.error); 
mediaRec.startRecord(); 
mediaRec.stopRecord(); 

Ich halte eine tmprecording-12351834581925.3gp in root zu bekommen.

Antwort

0

Auf Gerät

if(device.platform == "iOS"){ 
    app.path = cordova.file.tempDirectory; 
    app.extension = ".wav"; 
    app.mimeType = "audio/wav"; 
} else if(device.platform == "Android"){ 
    app.path = cordova.file.externalRootDirectory; 
    app.extension = ".amr"; 
    app.mimeType = "audio/amr"; 
} 

window.resolveLocalFileSystemURL(app.path, function(fileSystem){ 
    fileSystem.getDirectory("AppName", {create:true},function(dirEntry){ 
     dirEntry.getDirectory("Recording", {create:true} , function(subEntry){ 
      app.recording = subEntry.nativeURL; 
     }, function(error){ 
      console.log(error); 
     }); 
    }, function(error){ 
     console.log(error); 
    }); 
},function(error){ 
    console.log(error); 
}); 

Dann bereit, auf die Aufnahme

var filename = app.recording + new Date().getTime() + app.extension; 
var mediaRec = new Media(filename, success, error); 

Die Dateien werden nun in einer bevorzugten Position gespeichert, wo ich jetzt die Kontrolle und den Zugriff auf die Dateien haben.

Lesen von Dateien in Recordings

window.resolveLocalFileSystemURL(app.recording ,function (fileSystem) { 
    var reader = fileSystem.createReader(); 
    reader.readEntries(function (entries) { 
     console.log(entries); 
     //loop all entries 
    }, function(error){ 
     console.log(error); 
    }); 
} 
Verwandte Themen