How do I check if the playing song is (not) in English? - spotify-app

Is it possible to get the language of the currently playing song in spotify?
models.player.addEventListener('change', function(data)
{
var track = data.track.name, artist = data.track.artists[0].name;
var language = "?????";
});

Related

How to get "Entry" and "Exit" message on geospatial analytics in IBM bluemix

I am working on IBM Bluemix IOT application.I created devices and I am getting maps successfully. I created geospatial analytics service in bluemix also. In maps I am able to create geofence. When car enters geofence it is successfully giving entry message. But when car exits ,its not showing exit message.
Subscriptions.geoAlerts = new Subscription(window.config.notifyTopic, function(msg) {
if (!msg.destinationName.match(window.config.notifyTopic)) { return; }
try {
var data = JSON.parse(msg.payloadString);
console.log(data);
var id = data.deviceInfo.id;
//JR: Custom GEO notification
//var text = data.eventType;
var text = "Entry";
var fgColor = "white";
var bgColor = "rgba(0,0,0,0.8)";
var duration = 2000;
var c = demo.getCar(id);
if (c) {
c.addOverlay(text, duration, bgColor, fgColor);
}
/*
var id = data.id;
var text = data.text;
var fgColor = data.fgColor || "black";
var bgColor = data.bgColor || "rgba(255,255,255,0.9)";
var duration = data.duration || 3000;
var c = demo.getCar(id);
if (c) {
c.addOverlay(text, duration, bgColor, fgColor);
}
*/
} catch (e) { console.error(e.message); }
});
the above MQttClient.js I am using . Can any one give me suggestions highly appreciated. Thanks in advance
In addition to Paul's answer... if you haven't done so, make sure to specify:
"notifyOnExit" : "true",
on your call to the addRegion API.
The code as shown will display "Entry" for all events received including entry and exit events (as well as "hang out" events if the monitored region is configured for hangout detection). You should be using data.eventType as shown in the commented line of code (line 8) above.

angular push result to controller

(was not sure what to have as a title, so if you have a better suggestion, feel free to come up with one - I will correct)
I am working on an angular application where I have some menues and a search result list. I also have a document view area.
You can sort of say that the application behaves like an e-mail application.
I have a few controllers:
DateCtrl: creates a list of dates so the users can choose which dates they want to see posts from.
SourceCtrl: Creates a list of sources so the user can choose from which sources he/she wants to see posts from.
ListCtrl: The controller populating the list. The data comes from an elastic search index. The list is updated every 10-30 seconds (trying to find the best interval) by using the $interval service.
What I have tried
Sources: I have tried to make this a filter, but a user clicks two checkboxes the list is not sorted by date, but on which checkbox the user clicked first.
If it is possible to make this work as a filter, I'd rather continue doing that.
The current code is like this, it does not do what I want:
.filter("bureauFilter", function(filterService) {
return function(input) {
var selectedFilter = filterService.getFilters();
if (selectedFilter.length === 0) {
return input;
}
var out = [];
if (selectedFilter) {
for (var f = 0; f < selectedFilter.length; f++) {
for (var i = 0; i < input.length; i++) {
var myDate = input[i]._source.versioncreated;
var changedDate = dateFromString(myDate);
input[i]._source.sort = new Date(changedDate).getTime();
if (input[i]._source.copyrightholder === selectedFilter[f]) {
out.push(input[i]);
}
}
}
// return out;
// we need to sort the out array
var returnArray = out.sort(function(a,b) {
return new Date(b.versioncreated).getTime() - new Date(a.versioncreated).getTime();
});
return returnArray;
} else {
return input;
}
}
})
Date: I have found it in production that this cannot be used as a filter. The list of posts shows the latest 1000 posts, which is only a third of all posts arriving each day. So this has to be changed to a date-search.
I am trying something like this:
.service('elasticService', ['es', 'searchService', function (es, searchService) {
var esSearch = function (searchService) {
if (searchService.field === "versioncreated") {
// doing some code
} else {
// doing some other type of search
}
and a search service:
.service('searchService', function () {
var selectedField = "";
var selectedValue = "";
var setFieldAndValue = function (field, value) {
selectedField = field;
selectedValue = value;
};
var getFieldAndValue = function () {
return {
"field": selectedField,
"value": selectedValue
}
};
return {
setFieldAndValue: setFieldAndValue,
getFieldAndValue: getFieldAndValue
};
})
What I want to achieve is this:
When no dates or sources are clicked the whole list shall be shown.
When Source or Date are clicked it shall get the posts based on these selections.
I cannot use filter on Date as the application receives some 3000 posts a day and so I have to query elastic search to get the posts for the selected date.
Up until now I have put the elastic-search in the listController, but I am now refactoring so the es-search happens in a service. This so the listController will receive the correct post based on the selections the user has done.
Question is: What is the best pattern or method to use when trying to achieve this?
Where your data is coming from is pretty irrelevant, it's for you to do the hook up with your data source.
With regards to how to render a list:
The view would be:
<div ng-controller='MyController as myCtrl'>
<form>
<input name='searchText' ng-model='myCtrl.searchText'>
</form>
<ul>
<li ng-repeat='item in myCtrl.list | filter:myCtrl.searchText' ng-bind='item'></li>
</ul>
<button ng-click='myCtrl.doSomethingOnClick()'>
</div>
controller would be:
myApp.controller('MyController', ['ElasticSearchService',function(ElasticSearchService) {
var self = this;
self.searchText = '';
ElasticSearchService.getInitialList().then(function(list) {
self.list = list;
});
self.doSomethingOnClick = function() {
ElasticSearchService.updateList(self.searchText).then(function(list) {
self.list = list;
});
}
}]);
service would be:
myApp.service('ElasticSearchService', ['$q', function($q) {
var obj = {};
obj.getInitialList = function() {
var defer = $q.defer();
// do some elastic search stuff here
// on success
defer.resolve(esdata);
// on failure
defer.reject();
return defer.promise();
};
obj.updateList = function(param) {
var defer = $q.defer();
// do some elastic search stuff here
// on success
defer.resolve(esdata);
// on failure
defer.reject();
return defer.promise();
};
return obj;
}]);
This code has NOT been tested but gives you an outline of how you should approach this. $q is used because promises allow things to be dealt with asynchronously.

GeoFire geoQuery returning data

I'm newbie with Firebase + GeoFire and I'm having trouble with geoFire query function.
I want to add in an array the results from geoQuery function and return it in a function. But the data I have manipulating inside geoQuery.on method seems out of scope or not available or due to promises, I dont know... the fact is outside the geoquery.on method the variable sellers is empty.
How can I return results from geoQuery and save it into a return variable
//Set seller position in firebase db
var setPosition = function() {
navigator.geolocation.getCurrentPosition(setPositionSuccess, error, options);
//navigator.geolocation.watchPosition(setPositionSuccess, positionError, { enableHighAccuracy:true })
};
//Get sellers near buyer position
var getSellersForCurrentPosition = function() {
navigator.geolocation.getCurrentPosition(getPositionSuccess, error, options);
//navigator.geolocation.watchPosition(positionSuccess, positionError, { enableHighAccuracy:true })
};
//Callback function from html 5 geo api
function getPositionSuccess(pos) {
var crd = pos.coords;
var currentPosition = [crd.latitude, crd.longitude];
// Query radius
var radiusInKm = 2;
var firebaseRef = new Firebase(FBURL + "/geofire/sellers/");
var geoFire = new GeoFire(firebaseRef);
var geoQuery = geoFire.query({
center: currentPosition,
radius: radiusInKm
});
var sellers = [];
var oneSeller = {};
var onKeyEnteredRegistration = geoQuery.on("key_entered", function(key, location, distance) {
oneSeller = {
id: key,
distance: distance,
location: location
};
sellers.push(oneSeller);
});
var onReadyRegistration = geoQuery.on("ready", function() {
geoQuery.cancel();
});
return sellers;
}
By the way, how accurate is html5 geolocation? Is it different between desktop browser and mobile browser?
Geofire monitors the sellers in the range you indicate. Any time a seller enters/exits the range, it fires a key_entered or key_exited event. These events can happen at any time after you start the query. In JavaScript terms this is often described as: the callbacks happen asynchronously.
A simple event flow, might explain what happens best:
you call getPositionSuccess()
you start a Geoquery to monitor the sellers that are in range: geoFire.query()
no sellers are immediately in range, so your callback doesn't fire
the getPositionSuccess() function is done and exits
a seller comes in range
GeoFire fires the key_entered event and your callback runs
but getPositionSuccess() has already exited, so how can it return a value?
Even if you were to wait for the first seller to come into range before returning (not possible in a browser, but it is possible in other languages/environments), how will you return the value when a second seller comes in range?
For this reason, you have to deal with asynchronous data differently. Typically you do this by moving the code that would call the getPositionSuccess() function into the function.
Say you are now trying to do this:
var sellers = getPositionSuccess(pos);
sellers.forEach(function(seller) {
addSellerToMap(seller);
});
To handle the asynchronous nature of the events, you'd move this code into getPositionSuccess:
//Callback function from html 5 geo api
function getPositionSuccess(pos) {
var crd = pos.coords;
var currentPosition = [crd.latitude, crd.longitude];
// Query radius
var radiusInKm = 2;
var firebaseRef = new Firebase(FBURL + "/geofire/sellers/");
var geoFire = new GeoFire(firebaseRef);
var geoQuery = geoFire.query({
center: currentPosition,
radius: radiusInKm
});
var oneSeller = {};
geoQuery.on("key_entered", function(key, location, distance) {
oneSeller = {
id: key,
distance: distance,
location: location
};
addSellerToMap(oneSeller);
});
}
I understand that in your use-case your sellers won't move, so it may be more intuitive to think of them as a static list. But even in this case, the results are loaded from a remote database and it will take some time before that data is loaded. The modern web loads data asynchronously and all your code will have to deal with it in a way similar to what I outlined above.

AS3 pause button doesn't play paused song from array

I have a flash mp3 player with a play, pause and next button on one frame.
The songs are stored in an array.Everything works fine except for the
pause button. It pauses the music and save the song position in a variable.
When i click on the pause button again the song is supposed to play
from the saved song position which it does. The problem is it also
play the first song in the array. Not the song that was paused. I have tried
to find a solution on Google. But the topics i could find where about mp3 players that only played one song.
Here is the code. Thanks.
var i:Number = 0;
var myMusic:Sound = new Sound();
var mySongs:Array = ["Kalimba.mp3","Sleep Away.mp3","Maid with the Flaxen Hair.mp3"];
var soundFile:URLRequest = new URLRequest(mySongs[i++]);
var channel:SoundChannel = new SoundChannel();
var sTransform:SoundTransform = new SoundTransform();
var songPosition:Number;
var myContext:SoundLoaderContext = new SoundLoaderContext(5000);
myMusic.load(soundFile, myContext);
btnPlay.addEventListener(MouseEvent.CLICK, playMusic);
btnNext.addEventListener(MouseEvent.CLICK, nextMusic);
btnPause.addEventListener(MouseEvent.CLICK, pauseMusic);
channel.addEventListener(Event.SOUND_COMPLETE, nextMusic);
function playMusic(evt:MouseEvent):void
{
channel = myMusic.play(songPosition);
channel.addEventListener(Event.SOUND_COMPLETE, nextMusic);
}
function nextMusic(evt:Event):void
{
channel.stop();
var myMusic:Sound = new Sound();
var mySongs:Array = ["Kalimba.mp3","Sleep Away.mp3","Maid with the Flaxen Hair.mp3"];
var soundFile:URLRequest = new URLRequest(mySongs[i]);
myMusic.load(soundFile, myContext);
channel = myMusic.play(i);
channel.addEventListener(Event.SOUND_COMPLETE, nextMusic);
if(i==mySongs.length-1) {
i=0;
}
else {
i++;
}
}
var Paused:Boolean = false;
function pauseMusic(evt:MouseEvent):void
{
if(Paused==false) {
songPosition = channel.position;
channel.stop();
Paused = true;
}
else if(Paused==true) {
channel = myMusic.play(songPosition);
Paused = false;
}
}
You shouldn't keep adding the channel.addEventListener(Event.SOUND_COMPLETE, nextMusic);
Beacuse SOUND_COMPLETE events get fired when you pause.
Adding this eventlistener just once should suffice anyway.

array in node js behaves odd

I'm using node js to create a multi player game website. so every time a socket is connected I add that socket in an array like this
var users = [];
var games = [];
var joinKey = [];
var key = 0;
var usersKey = 101;
var gamesKey = 201;
io.sockets.on('connection', function (socket) {
socket.on('connect', function(){
console.log('connect');
var clientId = usersKey;
socket.clientId = clientId;
users[usersKey] = socket;
usersKey++;
socket.emit('getClientId', clientId);
console.log(socket.clientId + ' connected');
console.log('Total users: ' + users.length);
});
here total users shows 102 as user key is 101 and it automatically tales blank values from 0 to 100. this is not normal i guess. also if I retrieve the socket from other array using index, it is undefined if the index is string, like 'g201'
socket.on('createNewGame', function(){
var game = [];
var clientId = socket.clientId;
game[clientId] = socket;
console.log(game);
var gameId = 'g' + gamesKey;
gamesKey++;
games[gameId] = game;
console.log('Total Games: ' + games.length)
socket.gameId = gameId;
var publicKey = ++key;
joinKey[publicKey] = gameId;
socket.emit('gameCreated', publicKey);
});
I'm not getting how to insert and fetch if this is the behavior of array here
To answer your first point:
An array uses numerical indices running from 0.
When you manually place a value in at 101 it will fill the rest of the values in since it has to run from 0, these will be padded with undefined. (as per Andrew Barretts comment)
To answer your second point:
If you need to have an "associate array" or at least what people refer to as an associative array then you should use objects.
game= new Object();
game["g1"]=...
game["g25"]=...
...

Resources