简体   繁体   English

Soundcloud当前曲目信息

[英]Soundcloud current track Info

Concerning the following site 关于以下网站

Pretty simple, but none the less I seem to be falling at the first hurdle on this. 非常简单,但我似乎仍然对此感到头疼。

Using the following code currently to try and obtain a track name and artist from the currently active soundcloud player (of which there are 4 ,with the class SCiframe) 当前使用以下代码尝试从当前活动的soundcloud播放器(其中有4个,其类为SCiframe)中获取曲目名称和艺术家。

$(function () {
    var $iframeElement = document.getElementsByClassName('SCiframe');
    var $widgets = SC.Widget(iframeElement);
    widgets.bind(SC.Widget.Events.READY, function () {
        widgets.bind(SC.Widget.Events.PLAY, function () {
            // get information about currently playing sound
            widgets.getCurrentSound(function (currentSound) {
                $('#trackInfo').append('Current Track: ' + currentSound.get('') + '');
            });
        });
    });
});

for one, the console is registering 'iframeElement is not defined' as an inital error. 首先,控制台将“ iframeElement未定义”注册为初始错误。 But all in all, I cant seem to get any useful data out of this to process. 但总而言之,我似乎无法从中得到任何有用的数据进行处理。

Where am i going wrong here? 我在哪里错了?

Kindest regards to the community. 对社区表示最诚挚的问候。

You have the variable names incorrect, they have "$" at the begining, 您的变量名不正确,它们的开头有“ $”,

$(function () {
    var $iframeElement = document.getElementsByClassName('SCiframe');
    var $widgets = SC.Widget($iframeElement);
    $widgets.bind(SC.Widget.Events.READY, function () {
        $widgets.bind(SC.Widget.Events.PLAY, function () {
                // get information about currently playing sound
                $widgets.getCurrentSound(function (currentSound) {
                $('#trackInfo').append('Current Track: ' + currentSound.get('') + '');
            });
        });
    });
});

EDIT: 编辑:

getElementsByClassName returns an array of results. getElementsByClassName返回结果数组。 So if there is only one iframe with "SCiframe" classname, you should pass first index of $iframeElement as paramater in SC.Widget, try this, 因此,如果只有一个iframe具有“ SCiframe”类名,则应在SC.Widget中将$ iframeElement的第一个索引作为参数传递,请尝试这样做,

$(function () {
    var $iframeElement = document.getElementsByClassName('SCiframe');
    var $widgets = SC.Widget($iframeElement[0]);
    $widgets.bind(SC.Widget.Events.READY, function () {
        $widgets.bind(SC.Widget.Events.PLAY, function () {
            // get information about currently playing sound
            $widgets.getCurrentSound(function (currentSound) {
                $('#trackInfo').append('Current Track: ' + currentSound.get('') + '');
            });
        });
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM