如何在 JS 中获取 Shoutcast 当前曲目标题和插图
How to get Shoutcast current track title and artwork in JS
我正在尝试创建一个自定义的广播播放器,它会自动更新当前流媒体音频的标题和插图。
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 支持此功能。
小ajaxjQuery例子:
// 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
songName.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);
}
});
}
我正在尝试创建一个自定义的广播播放器,它会自动更新当前流媒体音频的标题和插图。
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 支持此功能。
小ajaxjQuery例子:
// 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
songName.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);
}
});
}