I'm currently trying to get the SoundCloud API working under PhoneGap/Cordova and Android. Here's the code that is working fine within the browser:
var track_url = 'http://soundcloud.com/mymusic/mymusic'
;
SC.get('/resolve', {
url : track_url
}, function(track) {
$("#stream").live("click", function() {
SC.stream("/tracks/" + track.id, function(sound) {
sound.play();
$("#stop").live("click", function() {
sound.stop();
});
});
});
});
On my android debug device however there is no sound. LogCat doesn't give any standard or cordova errors. Has anyone encountered this before?
Many Thanks in advance
Your code looks okay and I was able to test it successfully on Android. The only thing I can think of is that the resolve call is returning a 404 or similar. Have you tried checking for an error?
var track_url = 'http://soundcloud.com/your/track';
SC.initialize({
client_id: 'YOUR_CLIENT_ID'
});
SC.get('/resolve', { url: track_url }, function(track, error) {
if (error) {
alert("Error: " + error.message);
return;
}
// ... rest of your code
});
Try that and see if you get anything, if not, leave a comment.
Related
I am currently working on a project on Android using the Expo client for react native. I am trying to open a webpage using WebBrowser, passing my app development URI to the website. The website basically just redirects to the given URI after 5 seconds. However it never seems to open anything. I've used almost the exact same code as here: https://github.com/expo/examples/tree/master/with-webbrowser-redirect. When I load this project into expo and run, it redirects fine. However, when I copy the code for the website and app into my own project, website opens and displays, but redirect does nothing. It just stays there. Here is the code for opening the browser.
_openBrowserAsync = async () => {
try {
this._addLinkingListener();
let result = await WebBrowser.openBrowserAsync(
'https://wexley-auth.firebaseapp.com/?linkingUri=exp://192.168.1.2:19000'
);
this._removeLinkingListener();
this.setState({ result });
} catch (error) {
alert(error);
console.log(error);
}
};
The linking listener never fires the callback which should dismiss the browser. My app URI should be exp://192.168.1.2:19000 as expo developer tools shows me this when I connect over LAN. Ive also tried using Linking.makeUrl() instead of sending URI in string manually. Neither method works for me. Relevant website code:
document.addEventListener("DOMContentLoaded", function(event) {
var links = document.querySelectorAll('a');
var baseUri='';
// Take the uri from the params
var qs = decodeURIComponent(document.location.search);
if (qs) {
baseUri = qs.split('?linkingUri=')[1];
}
var redirectInterval = setInterval(function() {
var countdown = document.querySelector('.countdown');
var t = parseInt(countdown.innerText, 10);
t -= 1;
if (t === 0) {
clearInterval(redirectInterval);
window.location.href = baseUri;
}
}, 1000);
});
Am I missing a step? Do I need to setup a scheme for opening my app or should this work out of the box? Am I using the wrong URI? I noticed that in the example code, the app.json has the following fields that my app.json doesn't have:
"scheme": "expo.examples.with-webbrowser-redirect",
"platforms": [
"android",
"ios"
]
I am working on Cordova app. I wannt to implement a qrcode reader. I tried plugins available in Cordova but they all are buggy and some doesnot provide preview of scanner/video on same screen.
So I decided to use instascan which is a js based library to be used with webcams. I used it and implemented it in a simple cordova app and its working.
Now I see preview of my scan (camera video which is currently being scanned) and it scans perfectly.
But later I merged that code with my actual Cordova app which uses Vue cli. Now I am getting:
Error: Cannot access video stream (NotReadableError)
This error is probably (as I read) due to Chrome's https policy. But the problem is, Cordova uses webview and another cordova app which is basic cordova instance with this plugin only is working perfectly.
My implementation:
mounted: function () {
var _this = this;
this.$ons.ready(function () { // this is ready event fired by Onsen UI when cordova's native APIs are loaded
var scanner = new Instascan.Scanner({
continuous: true,
mirror: false,
video: document.getElementById('scannerPreview'),
});
scanner.addListener('scan', function (content) {
alert('scan' + content);
});
Instascan.Camera.getCameras().then(function (cameras) {
if (cameras.length > 0) {
if (cameras.length === 1) {
scanner.start(cameras[0]);
} else {
scanner.start(cameras[1]);
}
scanner.start(cameras[0]);
} else {
alert('No cameras found.');
}
}).catch(function (e) {
alert(e);
});
});
},
first add the permissions plugin:
cordova plugin add cordova-plugin-permission
And then you must request the permits in the camera:
permissions.requestPermission(permissions.CAMERA, success, error);
function error() {
return false;
}
function success( status ) {
if( !status.hasPermission ) error();
return true;
}
I am trying to add facebook login to my application. I followed the same process as mentioned in this blog of ionic "https://ionicthemes.com/tutorials/about/native-facebook-login-with-ionic-framework"
But somehow its not working.
Its failing at $cordovaFacebook.login. Its not going inside.
$scope.fbLogin = function(){
$cordovaFacebook.login(["public_profile", "email", "user_friends"]) //Failing in this step
.then(function(success) {
$cordovaFacebook.api("me?fields=id,name,picture", [])
.then(function(result){
var userData = {
id: result.id,
name: result.name,
pic: result.picture.data.url
}
//Do what you wish to do with user data. Here we are just displaying it in the view
$scope.fbData = JSON.stringify(userData, null, 4);
}, function(error){
// Error message
console.log(error);
})
}, function (error) {
console.log(error); // error comes as "Class not found"
});
}
What i am missing here. After debugging i found it says
51 F02 FacebookConnectPlugin sClass not found
See attached image. What is wrong here.
Damm...Issue is with cordova 5.4.1. I degraded to version 5.3.3 and it started working.
there is a Sencha 2 bug with the ajax loader.
onActivate : function(result, container) {
Ext.Ajax.request({
url : this.getUrl(),
method : 'GET',
success : function(response, request) {
result.setHtml(response.responseText);
},
failure : function(response, request) {
console.log("Failed: " + response);
}
});
}
On Android 2.2, 2.3, IOS I have no problems. Android 4.0 have some problems to load this into the panel.
Any ideas?
thanks in advance.
Okay, solved it by myself.
There was an asynchronous issue in Ext.Ajax.request:
onActivate : function(result, container) {
$.get("resources/web/about.html", function(data) {
result.setHtml(data);
});
}
Hope it helps somebody who is annoying by the same issue.
i am trying to do login application which takes id and password..when i click on logi button then it will connect to our local server by JSON..with the specified URL..the code is..
var loginReq = Titanium.Network.createHTTPClient();
loginReq.onload = function()
{
var json = this.responseText; alert(json);
var response = JSON.parse(json);
if (response.data.status == "success")
{ alert("Welcome ");
}
else
{ alert(response.data.status);
}
};
loginReq.onerror = function(event)
{
alert(event.toSource());
//alert("Network error");
};
loginBtn.addEventListener('click',function(e)
{ if (username.value != '' && password.value != '')
{
var url = 'our local url action=login&id='+username.value+'&pwd='+password.value;
loginReq.open("POST",url);
loginReq.send();
}
else
{
alert("Username/Password are required");
}
});
Here it is not connecting our URl..so it is entering into loginReq.onerror function...instead of loginReq.onload function..why it is throwing run time error.. The same code working fine with Iphone..
The Run Time Error is..
TypeError:Cannot call property toSource in object{'source':[Ti.Network.HttpClient],specified url} is not a function,it is a object.
This is wat the error..please let me Know...
Apparently the toSource() function does not exist in android, as it is an object. Try debugging and see what the object event contains.
You could do that by adding a line above the alert line, and adding a debug line to it.
Look in debug mode and see all variables
"toSource()" is not a documented function for either platform, and I also do not see it in the source for Titanium Mobile. If you aren't getting the error on iOS, I'm guessing it is because the error handler isn't getting called. Perhaps your emulator or device does not have internet access, whereas your iOS simulator or device does?
Regardless, error handling in the HTTPClient normally looks something like this:
loginReq.onerror = function(e)
{
Ti.API.info("ERROR " + e.error);
alert(e.error);
};