如何在JS中获得Shoutcast当前曲目标题和艺术作品

时间:2017-04-05 14:42:21

标签: javascript html5 api audio shoutcast

我正在尝试创建一个自定义的广播播放器,它会自动更新当前流媒体音频的标题和插图。

Shoutcast确实有一个API,但它只使用其Dev ID,但Shoutcast最近没有提供任何Dev ID。所以我需要另一种解决方法。

有一些PHP解决方案,但由于我不懂语言,我找不到他们的解决方案。请提供一些关于如何获取当前曲目标题,艺术作品甚至艺术家名称的示例或提示。

提前致谢

2 个答案:

答案 0 :(得分:3)

以下shoutcast页面为您提供:

Current song:     http://yourstream:port/currentsong?sid=#
Last 20 songs:    http://yourstream:port/played.html?sid#
Next songs:       http://yourstream:port/nextsongs?sid=#
提供流的播放器必须支持

nextsongs?sid=#。 sc_trans支持此功能。

一个小的ajax jQuery示例:

// Get current song
function NowPlaying(){
    $.ajax({
        url: "http://www.mofosounds.com:8000/currentsong?sid=#", 
        type: "GET",
        success: function(result) {
            $("#playing").html(result);
        }
    });
}

// Update every 5 seconds
setInterval(function(){
    NowPlaying();
}, 5000);

注意:为了执行跨域ajax请求,必须启用CORS。在此article

中了解有关CORS的更多信息

答案 1 :(得分:0)

没有 CORS

歌曲名称.php

$songName = file_get_contents('http://yourip:port/currentsong?sid=#');
echo $songName;

更改功能

// Get current song
function NowPlaying(){
    $.ajax({
        url: "songName.php", 
        type: "GET",
        success: function(result) {
            $("#playing").html(result);
        }
    });
}
相关问题