以下是Chrome浏览器控制台中显示的名为“params”的整个对象:
{videoSlot: video#videoSlot, slot: div#adSlot}
slot: div#adSlot
accessKey: ""
align: ""
draggable: false
...
videoSlot: video#videoSlot
accessKey: ""
loop: false
muted: false
...
当我做console.log(params)时,上面就是我所看到的。但如果我做console.log(params.videoSlot),它会显示
<video id="videoSlot" style="position:absolute; width:100%; height:100; ...></video>
这是视频的DOM元素。我想获取对象的元数据而不是DOM元素。我怎么能做到这一点?为什么会这样?
我正在编写一个代码,用于确定特定广告所播放的媒体播放器类型。玩家信息在此处作为“params”传递。
console.log(videoParams.muted)访问静音元数据并打印“false”。
但是,console.log(Object.keys(videoParams))打印出“[]”,空列表
Console.dir(videoParams)似乎打印出我想要的元数据,但是,我不知道如何捕获元数据信息并使用Object.keys(videoParams)进行迭代。
export default class MediaPlayerClassifier {
constructor() {
// map of events to arrays of pixels
this.identifier = {
'goog': 'GOOGLE_MEDIA_PLAYER',
'yimg': 'YAHOO_MEDIA_PLAYER',
'zzVpaidVideoPlayer': 'ZZ_MEDIA_PLAYER'
};
this.player = null;
}
determine(params, callback) {
videoParams = params.videoSlot
console.dir(videoParams);
var identifierKeys = Object.keys(this.identifier);
var value;
var that = this;
Object.keys(videoParams).forEach(function(key) {
value = videoParams[key];
console.log(value);
if (key === 'baseURI') {
console.log(value);
}
for (var i=0; i < identifierKeys.length; i++) {
var each = identifierKeys[i];
if (value && typeof value === 'string' && value.indexOf(each) !== -1) {
that.player = that.identifier[each];
return callback();
}
}
});
return;
}
getPlayerType() {
return this.player;
}
}