nativescript-audio plugin does not function on ios - audio

I have succesfully implemented the nativescript-audio plugin on android. I am using plain JS in my project. When i run it on ios i get the following error.
NSURLErrorDomain Code= -1002 "unsupported url".
I get this error with most of the examples that i found on the web (including the following , which works perfectly on android).
var ns_audio = require("nativescript-audio");
var player = new ns_audio.TNSPlayer();
var playerOptions = {
audioFile: "http://www.noiseaddicts.com/samples_1w72b820/2514.mp3",
loop: false,
completeCallback: function () {
console.log('completePlayer')
},
errorCallback: function (errorObject) {
console.log(JSON.stringify(errorObject));
},
infoCallback: function (args) {
console.log(JSON.stringify(args));
}
};
player.playFromUrl(playerOptions)
.then(function (res) {
console.log(res);
})
.catch(function () {
console.log("didn't work...");
})
It looks like recording works (no errors, and the correct responses, although i cannot test if the file has been correctly created...) But playback gives this error. Any idea ?

I have created a plain JS playground for you. I have tested the mp3 URL that you have provided in the the post and that works fine on ios.
Have a play with that and see if you are missing something. Here is
function pageLoaded(args) {
var page = args.object;
const player = new audio.TNSPlayer();
const playerOptions = {
audioFile: 'http://www.noiseaddicts.com/samples_1w72b820/2514.mp3',
loop: false,
completeCallback: function () {
console.log('finished playing');
},
errorCallback: function (errorObject) {
console.log(JSON.stringify(errorObject));
},
infoCallback: function (args) {
console.log(JSON.stringify(args));
}
};
player
.playFromUrl(playerOptions)
.then(function (res) {
console.log(res);
})
.catch(function (err) {
console.log('something went wrong...', err);
});
page.bindingContext = homeViewModel;
}

Recording and Playback with the nativescript-audio plugin (for iOS) are both working now!. My first problem was that i needed to record to .caf (not .mp3) so i used
if(isAndroid)
{
extention = ".mp3";
}
else
{
extention = ".caf";
}
before i record the audio file....
Also i ran in a stupid oversight which is easy to miss....
i created my code from the above mentioned example, but because i play the sound that is recorded to a .caf file. i needed to use playFromFile and not playFromUrl as the example uses.
( thats what caused the error : NSURLErrorDomain Code= -1002 "unsupported url".)
player
.playFromFile(playerOptions)
.then(function (res) {
hopefully this point of attention can save someone a headache !

Related

How to create a share link in Buildfire

I'm attempting to create a share link that users within a plugin can send to friends via email or sms. If their friend has the app, the goal would be to open the app to the plugin with a query string similar to navigation.navigateTo does so that it would open to specific content within the plugin. If they don't, the goal would be to send them to the app's webpage where they could download the app from the appropriate store (android or apple). Is this possible or at least a portion of it?
I've generated a share link using buildfire.deeplink.generateUrl but can't find the appropriate steps from there in the API documentation.
Yes, The steps as following:
generate the deeplink URL
buildfire.deeplink.generateUrl(options, callback)
make sure of passing data property to options where its representing the
deep link data that developers need to provide to the plugin once the user
opened the share link. For more information on how to reed this data from
plugin, see buildfrire.deeplink.getData.
buildfire.deeplink.generateUrl(
{
data: { videoId: "9Q-4sZF0_CE" },
},
(err, result) => {
if (err) {
console.error(err);
} else {
console.log(result.url);
}
}
);
after generate the deep link use the following function to open share device options
buildfire.device.share({ link: deepLinkUrl }, callback);
Finally you have to handle deeplink data in you plugin to be able to open desired content based deeplink data that you pass during generate the deeplink URL, check this buildfrire.deeplink.getData.
For more details check the doc.
Example
// share function
const share = () => {
let deeplinOptions= {};
deeplinOptions.title = 'Hello world';
deeplinOptions.type = "website";
deeplinOptions.description = 'First program';
deeplinOptions.imageUrl = '<IMAGE URL>';
deeplinOptions.data = {
"link": vidId
};
buildfire.deeplink.generateUrl(deeplinOptions, function (err, result) {
if (err) {
console.error(err);
} else {
let options = {
link: result.url
};
let callback = function (err, result) {
if (err) {
console.warn(err);
};
};
buildfire.device.share(options, callback);
};
});
};
// Handle Deeplink data in your plugin
const handleDeepLinkData = () => {
buildfire.deeplink.getData(function (data) {
if (data && data.link) {
let vidId= data.link;
// Do what you want
}
// Do what you want
});
}
Yeah, Just share the result URL

Routing 404 not found issue

I am running a Express application with Node in the backend. I have 2 functions in a component in NodeJS which I am trying to access from my service. The link for both are the same in the service. It is able to connect one of the functions from the service.
However, it is showing 404 not found for accessing the second function in the same component.
Has anyone faced any such issue and if so how can it be rectified?
EDITED :
Some code for reference :
component1.component.ts
getallprojectcat()
{
this.authenticationService.getprojectcat()
.pipe(first())
.subscribe(
data => {
this.data = data;
},
error => {
this.loading = false;
});
}
}
component2.component.ts
showprojects(moid)
{
this.authenticationService.getprojectslist(moid)
.pipe(first())
.subscribe(
data => {
this.silver = data;
},
error => {
console.log('some error');
this.alertService.error(error);
this.loading = false;
});
}
the .service file
getprojectcat()
{
return this.http.get<any>(this.studenturl+'/getprojectcata/')
.pipe(map(allprojectcat => {
console.log(JSON.stringify(allprojectcat));
return allprojectcat;
}));
}
getprojectslist(moid)
{
return this.http.get(this.studenturl+'/getprojects/'+moid)
.pipe(map(projectslist => {
console.log("Projects List:"+JSON.stringify(projectslist));
return projectslist;
})).catch(this.handleError);
}
Backend .js file
exports.getprojectcata = function(req, res){
console.log("First Function");
};
exports.getprojects = function(req, res){
console.log("Second Function");
};
The function getprojectcata is working in the first component. However, it shows an 404 not found on the getprojects function in the second component. I have checked the following things -
Routing does not seem to be the problem as it is moving to the next component without any issues.
We have also tried calling the getprojectscata through the same service in component and it worked.

Reading json file in windows 10 html5 app?

I was developing a Windows 10 app with HTML5 and Javascript.
In one part of the code I need to get data from a json file which is located in the project folder. I tried below , but it doesnt seems to be working.
try
{
$.getJSON('../js/towards_beach.json', function (data)
{
document.getElementById("Result").innerText = "We are working on it";
});
}
catch(err)
{
document.getElementById("Result").innerText = err;
}
Does any one have a clue how I can do it?
Do I need to register this function in winjs?
If you use jquery to do the request the right way is :
var jqxhr = $.getJSON( "example.json", function() {
console.log( "success" );
}).done(function() {
console.log( "success" );
}).fail(function() {
console.log( "error" );
}).always(function() {
console.log( "complete" );
});
doc is here http://api.jquery.com/jquery.getjson/
If you use WinJS.xhr
WinJS.xhr({url:"example.json"}).done(
function completed(request) {
console.log( "success" );
},
function error(request) {
console.log( "error" );
},
function progress(request) {
console.log( "progress" );
});
doc is here https://msdn.microsoft.com/en-us/library/windows/apps/br229787.aspx
the following code will help you to read JSON file
var url = new Windows.Foundation.Uri("ms-appx:///data/data.json");
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(url).then(function (file){
Windows.Storage.FileIO.readTextAsync(file).then(function (text) {
var parsedObject = JSON.parse(text);
// do something with object
});
});
Put this code in a function wherever you want :) happy coding

Why does node webkit crash when downloading a big file?

Im using node webkit 0.7.5 (which is the only version so far which allows me to display video in a correct way).
I'm trying to download a big video file (200+ mb) and sometimes, not always, node webkit crashes when the file is done downloading. Writestream.end() is called, and that is when the crash happens.
My code:
var fs = require('fs');
var request = require("request");
var req = request(self.requestOptions(), function (err) {
if (err) {
//handle error
}
});
req.on("response", function (response) {
writeFile(response);
});
function writeFile(response) {
var file = fs.createWriteStream(filename);
var self = this;
response.on('data', function (data) {
file.write(data);
});
response.on('end', function () {
log.debug("response end");
file.end();//crash happens after calling this
});
response.on('error', function (err) {
//handle error, not called in this situation
});
file.on('finish', function () {
log.debug("file finish");
});
}
In general this method works excellent, but with some files and situations node webkit just decides to call it quits.
Am I doing something obviously wrong? I've searched the net for possible clues or solutions, but I haven't found anything.

Using external modules within AppJs and nodejs

I've built a basic demo application using AppJS/NodeJS and edge.
Heres the relevant part of the the app.js config file - Basically it just references the external modules.
.......
window.on('ready', function(){
console.log("Window Ready");
window.process = process;
window.module = module;
window.dns = require('native-dns');
window.edge = require('edge');
window.fs = require('fs');
window.frame.openDevTools();
..........
And heres the relevant javascript part of the main index.html page:
.......
function myFunction1()
{
var question = dns.Question({
name: 'www.google.com',
type: 'A'
});
var req = dns.Request({
question: question,
server: { address: '8.8.8.8', port: 53, type: 'udp' },
timeout: 1000
});
req.on('timeout', function () {
console.log('Timeout in making request');
});
req.on('message', function (err, answer) {
answer.answer.forEach(function (a) {
console.log(a.address);
});
});
req.on('end', function () {
console.log('Finished processing request');
});
req.send();
}
function myFunction2()
{
var helloWorld = edge.func('async (input) => { return ".NET Welcomes " + input.ToString(); }');
helloWorld('JavaScript', function (error, result) {
if (error) throw error;
console.log(result);
});
}
..........
If I call myFunction1() which uses another nodejs module (DNS lookup) it works perfectly. However if I call myFunction2() which uses edge I get the following error!
Uncaught TypeError: Property 'func' of object [object Object] is not a function
I've spent hours on this and for cannot work out why this happening!
Have you tried running the same myFunction2 code inside app.js i.e. in nodejs? Maybe the func function does not exist on the edge object. Check the docs maybe you need to do something like
window.edge = require('edge').Edge;
or something similar to get hold of the object that you think you have at the moment. You can also do console.log(window.edge) and see what it outputs (both in node and in browser running dev tools (F12)).
/Simon

Resources