如何在 JS 中获取 Shoutcast 当前的曲目标题和插图



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

Shoutcast

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

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

提前致谢

以下 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。阅读本文中有关 CORS 的更多信息

没有 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);
        }
    });
}

最新更新