function onPlayerReady(event)
{
event.target.cueVideoById({
videoId: videos[index].vid,
startSeconds: videos[index].startSeconds,
endSeconds: videos[index].endSeconds,
suggestedQuality: videos[index].suggestedQuality
});
event.target.playVideo();
console.log('++++++++++++++++++++');
console.log(player.getVolume());
console.log(player.getDuration());
console.log(player.getCurrentTime());
console.log('++++++++++++++++++++');
}
and here is the output
++++++++++++++++++++
undefined
undefined
undefined
++++++++++++++++++++
What am I doing wrong?
Finally I got the answer
These function works when the player is in the state of playing, else won't work
if (event.data === YT.PlayerState.PLAYING) {
console.log(player.getVolume());
console.log(player.getDuration());
console.log(player.getCurrentTime());
}
Related
MyObj is the following component:
Item {
id:root
signal foo()
property string bar: "bar"
Component.onCompleted: root.foo()
}
When creating it dynamically via Qt.createComponent(...) -> comp.createObject(...) it is possible to connect JS functions to all signals, except destruction
Following code:
var comp = Qt.createComponent('MyObj.qml');
var finish = () => {
if(comp.status === Component.Error) {
console.log("Error loading component:", comp.errorString())
return
}
if(comp.status !== Component.Ready) {
console.log("Component not ready")
return
}
var obj = comp.createObject(mainWindow, {})
if(obj === null) {
console.log('Error creating object')
return
}
obj.foo.connect(() => console.log('foo!'))
obj.barChanged.connect(() => console.log('barChanged!'))
obj.destruction.connect(() => console.log('destruction!'))
}
if(comp.status !== Component.Loading)
finish();
else
comp.statusChanged.connect(finish);
produces the error:
qrc:/main.qml:32: TypeError: Cannot call method 'connect' of undefined
exactly at the line with obj.destruction.connect(...)
The documentation doesn't mention any such restriction.
What's wrong?
Putting:
Component.onDestruction: console.log("#destruction")
in MyObj works as usual, but that's not what I need.
I didn't realize JS needs the same syntax as QML for accessing properties of the superclass.
The following works just fine:
obj.Component.destruction.connect(() => console.log('destruction!'))
I've been testing on http calls with meteor, I used nitrous (because I had no access to my dev laptop during the weekend) and it worked fine.
But when I tried to run from my local pc it returns:
Exception in delivering result of invoking 'getMatch': TypeError:
Cannot read property 'duration' of undefined.
Any ideas of what could be the cause?
Method definition:
Dota = {};
Dota.getMatch = function() {
if (!Meteor.settings.steamToken)
throw new Meteor.Error(500, 'Enter a valid Steam Token in Meteor.settings');
var matchResponse = Meteor.http.get(
"https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001/?",
{
params:{
"match_id": "1305454585",
"key": Meteor.settings.steamToken
}
}
);
if (matchResponse.statusCode === 200) {
return matchResponse.data.result
}
else {
throw new Meteor.Error(500, "getMatch failed with error: "+matchResponse.statusCode);
}
}
Meteor.methods({
'getMatch': function(){
return Dota.getMatch();
}
})
Calling the method:
Meteor.call('getMatch', function(error, result){
var duration = numeral(result.duration).format('00:00:00');
Session.set('duration', duration);
var winner = Meteor.myFunctions.getWinner(result.radiant_win);
Session.set('winner', winner);
});
Template.layout.helpers({
winner: function () {
return Session.get('winner');
},
duration: function () {
return Session.get('duration');
}
});
Found a solution, I changed the location of
Meteor.methods({
'getMatch': function(){
return Dota.getMatch();
}
})
to server/server.js (I had it in packages/dota/dota.js) and now it works! Thanks #user3374348 for helping!
I've got the following route configuration: https://gist.github.com/chriswessels/76a64c421170095eb871
I'm getting the following error when attempting to load a route:
Exception in defer callback: TypeError: undefined is not a function
at manageLoadingIndicator (http://localhost:3000/both/router/routes.js?ef701fada29363a443a214f97988ce96ebaec025:30:10)
at RouteController.runHooks (http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:843:16)
at http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:2302:14
at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36)
at new Tracker.Computation (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:206:10)
at Object.Tracker.autorun (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:476:11)
at http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:2279:12
at Utils.extend._run.withNoStopsAllowed (http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:2248:21)
at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36)
at new Tracker.Computation (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:206:10)
It's talking about the following line, which is in a onBeforeAction hook:
function manageLoadingIndicator (pause) {
if (this.ready()) {
Session.set('loading', false);
this.next(); // THIS LINE HERE
} else {
Session.set('loading', true);
pause();
}
}
Why is this.next undefined? Help please!
Chris
You are mixing up different versions of Iron router:
Prior to iron router 1.0, onBeforeAction would proceed to action unless pause (the first arg to onBeforeAction is invoked. There is no .next() method.
From 1.0 onwards this has been changed. pause() is no longer passed as an argument. This is where the .next() method replaces it.
You are evidently running on an old version of iron router, so therefore your hook should look like this:
function manageLoadingIndicator (pause) {
if (this.ready()) {
Session.set('loading', false);
} else {
Session.set('loading', true);
pause();
}
}
Once you upgrade iron router, you need to change it to this:
function manageLoadingIndicator () {
if (this.ready()) {
Session.set('loading', false);
this.next();
} else {
Session.set('loading', true);
}
}
Anyone know what this works just fine
data: function() {
return Topics.findOne(this.params._id);
}
But this does not
data: function() {
return [Topics.findOne(this.params._id)];
}
It's not finding the this.params._id
Did a simple workaround
return {
_id: Topics.findOne(this.params._id)._id
}
I don't know why but this code is not working ? Why would it not ? I guess it is because scope problem I am having here :
function washAway(obj) {
alert($(obj)); // says HTML Object which is fine
setTimeout(function() {
alert($(obj)); // says undefined
$(obj).fadeOut("slow", function() {
$(this).remove();
});
}, 2000);
};
At the point where the function in the timeout executes, it has no way to know what obj is - it was a parameter passed into the method where the timeout was set up, but the function inside has no reference to it.
An alternative approach is to write a jQuery plugin to wait before it acts like this:
function($){ //to protect $ from noConflict()
$.fn.pause = function(duration) {
$(this).animate({ dummy: 1 }, duration);
return this;
};
}
Then you can use:
$(obj).pause(2000).fadeOut("slow", function() { $(this).remove(); });
Any ways, I've found my answer after a couple of try/wrong. But I am still wondering why it didn't work out.
Here is the code :
function washAway(obj) {
alert($(obj).attr("id"));
var a = function() {
var _obj = obj;
return function() {
$(_obj).fadeOut("slow", function() {
$(this).remove();
});
};
};
setTimeout(a(), 2000);
};
Edit : I think I understood the problem here :
Because we are talking about closures here, when washAway execution finishes, the variable obj is destroyed so setTimeOut function callback function can't use that resource because it is no more available on the stack and it is not also a global variable.