Hello!
My app downloaded and saves mp3 files from my server. For Android it works like a charme. But for iOS I was coding, testing and researching yesterday for the whole day. I wasn't able to bring it to work. It "seems" that downloading and saving is working fine. But I don't know what the correct path is to play back that saved mp3 files. It "seems" that the download and save process worked because the success callback was called but I don't know how to find out if it was really saved. For coding I use Phonegap Build.
In the config.xml
<gap:plugin name="org.apache.cordova.device" />
<gap:plugin name="org.apache.cordova.file" />
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
<preference name="iosPersistentFileLocation" value="Library" />
<preference name="AndroidPersistentFileLocation" value="Internal" />
<preference name="BackupWebStorage" value="none" />
<gap:plugin name="org.apache.cordova.file-transfer" />
<gap:plugin name="org.apache.cordova.media" />
<gap:plugin name="org.apache.cordova.geolocation" />
---------------------------------------------------
function downloadFile(file){
var fileURL = "cdvfile://localhost/persistent/s"+file+".mp3";
var fileTransfer = new FileTransfer();
var uri = encodeURI("
http://www.domain.com/mp3/s"+file+".mp3");
fileTransfer.download(
uri,
fileURL,
function(entry) {
alert("download complete");
},
function(error) {
alert("download error source " + error.source);
alert("download error target " + error.target);
alert("upload error code" + error.code);
},
false,
{
headers: {
"Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
}
}
);
}
<a href="#" onclick="playAudio('cdvfile://localhost/persistent/s1.mp3');">Play Test 1</a><br>
<a href="#" onclick="playAudio('file://var/mobile/Containers/Data/Application/' + device.uuid + '/Library/files/s1.mp3');">Play Test 2</a><br>
<a href="#" onclick="playAudio('localhost/Libary/s1.mp3');">Play Test 3</a><br>
<a href="#" onclick="playAudio('cdvfile://localhost/Libary/s1.mp3');">Play Test 4</a><br>
<a href="#" onclick="playAudio('file://localhost/Libary/s1.mp3');">Play Test 5</a><br>
---------------------------------------------------
I tried a lot of different path as you can see in the bottom of the code but never found the correct one. The playAudio() function I didn't here here but that one is working. I have no problems to play a mp3 file which is coming with the installation and is saved in the app storage folder.
What did I wrong? Is it only a path problem? And if so, which is the correct path?
Best regards
Marc