Cordova Windows Phone 8 Play Local File Sound - file

How can I play a local mp3 file in the www folder?
Example: I need to play the following file : 'www/audio/button.mp3'. So:
1) I install the Cordova media and the media capture plugin.
2) I add the following code in the DeviceReady event handler :
var media=null;
function onDeviceReady()
{
alert("ready");
addSoundEffects();
}
function addSoundEffects(){
var soundUrl=getMediaUrl("/audio/button.mp3");
media=new Media(soundUrl,mediaLoaded,mediaError);
alert('after');
}
function getMediaUrl(s){
if(device.platform.toLowerCase() === "android") return "/android_asset/www" + s;
return 'www'+s;
}
function mediaLoaded(){
alert('Media loaded correctly');
}
function mediaError(e) {
alert('Media Error');
alert(JSON.stringify(e));
}
3) I run the application on my windows phone device, but it just stopped on the media=new Media(soundUrl,mediaLoaded,mediaError); row. I can see the "after" alert, but the function above doesn't call mediaLoaded neither mediaError, i don't know what to do.
NOTE: I think that the path is not the problem, otherwise it should just call the mediaError callback. I notice that the 'Media' variable is undefined, i don't know if can help.
Thanks for answer, i have been working on this from 3 hours and i can't find anything on google!

try to add '/' before www. It works in my apps

Related

Send data to .php with Cocoonjs Canvas+

I have a game finished and I´m saving the scores in a database perfectly, only if I use webview+, if I change to canvas+ the save proccess is not working (and no errors).
I´m trying to save this data sending it to a php file connected to de database (as I said, is working using webview or webview+)
How would you do this using canvas+?
var http = new XMLHttpRequest();
var url = path+"getScores.php";
var params = "game=1&order=ASC";
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
Please, try passing the parameters in the request URL using a GET (just in case). Also, try compiling a custom launcher in the cloud using the latest version (2.1.1). Actually, the JQuery errors should disappear by doing this.
And as Iker said, you can fix this with a custom launcher. I didn´t know about this thing but well, it´s working perfectly now, so if you have this problem, just try that and good luck.

Cordova + Sencha Touch: Delete file after it has been used

So I'm using Cordova + Sencha Touch for an app and Antair's SQLitePlugin (https://github.com/Antair/Cordova-SQLitePlugin) to import and use an SQLite database in it.
I managed to import my (kinda big) prepopulated database using Antair's importPrepopulatedDatabase ( window.sqlitePlugin.importPrepopulatedDatabase({file:"mydb.db",importIfExists:false}) ) method and it works just fine. The thing is I noticed the app is using twice the size it really needs as it keeps the file after importing it.
I checked and the app works just fine if I delete the file from /cordova/www/db and build again, it keeps the actual db in the app's filesystem I guess, but I can't find a way to programmatically delete that file after it has been imported.
I looked around and found cordova file plugin (https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md), but from what I saw from the docs it only grants read permissions on the www folder, so that won't do it.
Does anyone have any workaround for this? I could really use that extra space.
By using cordova file plugin api you can do this,
please refer this :
deleteFile: function(fileName) {
var that = this;
if (!fileName) {
console.error("No fileName specified. File could not be deleted.");
return false;
}
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function(fileSystem){ // this returns the tmp folder
// File found
fileSystem.root.getFile(fileName, {create: false}, function(fileEntry){
fileEntry.remove(function(success){
console.log(success);
}, function(error){
console.error("deletion failed: " + error);
});
}, that.get('fail'));
}, this.get('fail'));
}

Get the current browser name in Protractor test

I'm creating users in some test. Since it is connected to the backend and create real users I need fixtures. I was thinking of using the browser name to create unique user. However, It has proven to be quite difficult to get to it...
Anyone can point me in the right direction?
Another case of rubber ducking :)
The answer was actually quite simple.
in my onPrepare function I added the following function and it works flawlessly.
browser.getCapabilities().then(function (cap) {
browser.browserName = cap.caps_.browserName;
});
I can get access the name in my test using browser.browserName.
This has changed in version of protractor starting from 3.2 (selenium webdriver 2.52)
Now one should call:
browser.driver.getCapabilities().then(function(caps){
browser.browserName = caps.get('browserName');
}
If you want to avoid the a browser, you may want to do this:
it('User should see a message that he has already been added to the campaing when entering the same email twice', function () {
browser.getCapabilities().then(function (capabilities) {
browserName = capabilities.caps_.browserName;
platform = capabilities.caps_.platform;
}).then(function () {
console.log('Browser:', browserName, 'on platform', platform);
if (browserName === 'internet explorer') {
console.log('IE Was avoided for this test.');
} else {
basePage.email.sendKeys('bruno#test.com');
console.log('Mande el mail');
basePage.subscribe.click().then(function () {
basePage.confirmMessage('Contact already added to target campaign');
});
}
});
});

angular $resource works with IIS express but not IIS ? I think something is wrong with the PUT?

I have isolated the problem down to a few lines. With IIS express it calls the PUT on the web API. When I switch to using IIS with the same code the call to the PUT method never happens.. The GET call works with both just fine.. any idea?
$scope.save = function (msa) {
$scope.msa = msa;
var id = this.msa.PlaceId;
Msa.update({ id: id }, $scope.msa, function () {
alert('finished update'); //only gets here with iis express
$scope.updatedItems.push(id);
$location.path('/');
});
}
MsaApp.factory('Msa', function ($resource) {
return $resource('/api/Place/:id', { id: '#id' }, { update: { method: 'PUT' } });
});
EDIT 1:
I thought it was working but now it only works when 'localhost' and not the computer name.. it is not calling the server method.. any ideas what things to look out for that make the site act differently from localhost to ? .. and even stranger.. the angular site wont load in IE.. but it loads in chrome
EDIT 2:
I think I have the answer.. The dewfault webapi PUT/UPDATE creates invalid code.. It sort of randomly would breaking at db.Entry(place).State = EntityState.Modified... I found code here that seems to fix it so far.. not exactly sure what it does though
An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key
Remove WebDAV module from IIS, it should work
IIS does block some of the actions by default, I believe PUT is one (DELETE is another).
See: https://stackoverflow.com/a/12443578/1873485
Go to Handler Mappings in your IIS Manager. Find ExtensionlessUrlHandler-Integrated-4.0, double click it. Click Request Restrictions... button and on Verbs tab, add both DELETE and PUT.

On Cordova 2.0 app - readAsText breaks on iOS6 ...

I'm working on a Phonegap/Cordova app, use Cordova 2.0, and after iOS 6 is available - we suddenly begun to experience a problem. It's in the readAsText method of the file object.
Here is the part of the code. We use the facebook SDK to release Facebook Single Sign-On, and so we have a file, written down in a folder. Then we attempt to read it and take the token from it.
And so - on iOS 4 and iOS5 it's working - i.e. you'll see the two alerts - 111 and 222. But on iOS6 the second alert doesn't happen. Or in other words - the onloadend callback never triggers, although I see that the file is there.
// start the file interaction:
window.requestFileSystem(
LocalFileSystem.PERSISTENT,
0,
function(fileSystem) {
fileSystem.root.getFile(
"FacebookData/facebookData",
null,
function(fileEntry) {
fileEntry.file(
function(file) {
alert('111');
var reader = new FileReader();
reader.onloadend = function(evt) {
alert('222');
// do something with the file ..
}; // end of onloadend
reader.readAsText(file);
},
fail
); // end fileEntry.file
},
fail
); // end getfile
},
fail
); // end window.requestFileSystem
The function "fail" doesn't trigger at all, and also - all of this is inside a try-catch - but it doesn't throw an exception too.
And also - on iOS 4/5 it happens only once, but on iOS 6 it happens several times, as if you've clicked several times on a button and then the code executes.
Has anyone met a bug like this?
Known issue, apparently there is a fix there :
https://issues.apache.org/jira/browse/CB-1219
https://github.com/apache/incubator-cordova-js/pull/22
But I didn't test it yet.

Resources