Javascript 使用Shoutcast,显示正在播放的唱片集艺术
我在一个HTML播放器中有一个70x70的小盒子,我想把它放在相册插图中,以符合我现在从shoutcast服务器播放的信息。有没有一种方法,使用shoutcast服务器提供的艺术家歌曲信息,我可以搜索web服务(amazon/last.fm)并让它将(最有可能的)专辑封面放在那里 下面是我现在使用的JS代码:Javascript 使用Shoutcast,显示正在播放的唱片集艺术,javascript,shoutcast,albumart,Javascript,Shoutcast,Albumart,我在一个HTML播放器中有一个70x70的小盒子,我想把它放在相册插图中,以符合我现在从shoutcast服务器播放的信息。有没有一种方法,使用shoutcast服务器提供的艺术家歌曲信息,我可以搜索web服务(amazon/last.fm)并让它将(最有可能的)专辑封面放在那里 下面是我现在使用的JS代码: jQuery(document).ready(function() { pollstation(); //refresh the data every 30 seconds
jQuery(document).ready(function() {
pollstation();
//refresh the data every 30 seconds
setInterval(pollstation, 30000);
});
// Accepts a url and a callback function to run.
function requestCrossDomain( callback ) {
// Take the provided url, and add it to a YQL query. Make sure you encode it!
var yql = 'http://s7.viastreaming.net/scr/yql.php?port='+port+'&username='+user+'&callback=?';
// Request that YSQL string, and run a callback function.
// Pass a defined function to prevent cache-busting.
jQuery.getJSON( yql, cbFunc );
function cbFunc(data) {
// If we have something to work with...
if ( data ) {
// Strip out all script tags, for security reasons. there shouldn't be any, however
data = data[0].results.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
data = data.replace(/<html[^>]*>/gi, '');
data = data.replace(/<\/html>/gi, '');
data = data.replace(/<body[^>]*>/gi, '');
data = data.replace(/<\/body>/gi, '');
// If the user passed a callback, and it
// is a function, call it, and send through the data var.
if ( typeof callback === 'function') {
callback(data);
}
}
// Else, Maybe we requested a site that doesn't exist, and nothing returned.
else throw new Error('Nothing returned from getJSON.');
}
}
function pollstation() {
requestCrossDomain(function(stationdata) {
var lines = stationdata.split('|+|');
jQuery('#sname').html(lines[0]);
jQuery('#sgenre').html(lines[1]);
jQuery('#clisteners').html(lines[2]);
jQuery('#bitrate').html(lines[3]);
jQuery('#artist_block').html('' + jQuery.trim(lines[4]) + '');
var prev = lines[5].split('+|+');
jQuery('#np_table').html('');
for (var i = 0; i < 8; i++)
{
if(typeof(prev[i]) != 'undefined')
{
jQuery('#np_table').append('<tr>'+'<td>'+ prev[i] + '</td>'+'</tr>');
jQuery("tr:odd").css("background-color", "#154270");
}
}
jQuery('#mplayers').html(lines[6]);
jQuery('#mobile').html(lines[7]);
jQuery();
} );
}
jQuery(文档).ready(函数(){
pollstation();
//每30秒刷新一次数据
设定间隔(轮询站,30000);
});
//接受要运行的url和回调函数。
函数requestCrossDomain(回调){
//获取提供的url,并将其添加到YQL查询中。确保对其进行编码!
var yql=http://s7.viastreaming.net/scr/yql.php?port=“+port+”&用户名=“+user+”&回调=?”;
//请求该YSQL字符串,并运行回调函数。
//传递定义的函数以防止缓存破坏。
getJSON(yql,cbFunc);
函数cbFunc(数据){
//如果我们有事情要做。。。
如果(数据){
//出于安全考虑,去掉所有脚本标记。但是,不应该有任何脚本标记
数据=数据[0]。结果。替换(/]*>[\s\s]*?/gi',);
data=data.replace(/]*>/gi',);
data=data.replace(//gi',);
data=data.replace(/]*>/gi',);
data=data.replace(//gi',);
//如果用户传递了回调,则
//是一个函数,调用它,并通过数据变量发送。
if(typeof callback==='function'){
回调(数据);
}
}
//否则,可能我们请求了一个不存在的站点,但没有返回任何内容。
else抛出新错误('getJSON未返回任何内容');
}
}
函数pollstation(){
requestCrossDomain(函数(stationdata){
变量行=stationdata.split(“|+|”);
jQuery('#sname').html(第[0]行);
jQuery('#sgenre').html(第[1]行);
jQuery('#clisteners').html(第[2]行);
jQuery(“#比特率”).html(第[3]行);
jQuery('#artist_block').html('+jQuery.trim(第[4]行])+'');
var prev=行[5]。拆分(“+|+”);
jQuery('#np_table').html('';
对于(变量i=0;i<8;i++)
{
if(typeof(prev[i])!=“未定义”)
{
jQuery('#np_table').append('++'+prev[i]+'+'+'');
css(“背景色”,“#154270”);
}
}
jQuery('#mplayers').html(第[6]行);
jQuery('#mobile').html(第[7]行);
jQuery();
} );
}
下面是HTML:
<div id="col_left">
<div id="now_playing">
<div id="np_ribbon"><span>Now Playing</span></div>
<div id="np_img"><img name="nowplayingimage" src="" width="70" height="70" alt="album cover" style="background-color: #000000" /></div>
<div id="artist_block">
<span class="artist_name"><strong>Artist:</strong> Artist name</span><br />
<span class="song_name"><strong>Song:</strong> "song title"</span><br />
<span class="album_name"><strong>Album:</strong> Album Name</span> <br />
</div>
<div id="player">
<div id="container"><script type="text/javascript" src="http://shoutcast.mixstream.net/js/external/flash/s7.viastreaming.net:8790:0:::999999:::1"></script></div>
</div>
</div><!-- end now playing -->
<div id="recent">
<div class="table_title">Recently Played</div>
<table id="np_table">
</table>
</div><!-- end recent -->
</div><!-- end col_left -->
现在玩
艺术家:艺术家姓名
歌曲:“歌曲标题”
相册:相册名称
最近玩
很自然,我希望图像显示在div“np_img”所在的位置。任何关于使用什么代码以及如何实现它的想法。你可能可以从我的代码中看出我是个业余爱好者,所以请保持清晰和温和。:) 您可以使用。它支持,所以你可以直接在你的网页中使用它,而不用担心跨域
正如@Brad所提到的,iTunes已经做到了。特别是:
(…)如果此类宣传内容:(i)仅放在宣传
促销内容所基于的内容;(ii)接近
“在iTunes上下载”或“在应用商店上可用”徽章(如适用)
经苹果公司批准),作为iTunes内页面的直接链接
或者消费者可以购买推广内容的应用商店。(……)
下面是代码的样子:
function refreshArtwork(artist, track) {
$.ajax({
url: 'http://itunes.apple.com/search',
data: {
term: artist + ' ' + track,
media: 'music'
},
dataType: 'jsonp',
success: function(json) {
if(json.results.length === 0) {
$('img[name="nowplayingimage"]').attr('src', '');
return;
}
// trust the first result blindly...
var artworkURL = json.results[0].artworkUrl100;
$('img[name="nowplayingimage"]').attr('src', artworkURL);
}
});
}
对谢谢我现在就要看这个,但我肯定我可能不知道该如何实现它。该数据的许可证是什么?我知道,至少对亚马逊来说,如果你不想把他们的数据链接到亚马逊去购买音乐,你就不能使用他们的数据。如果是这样的话,我不介意把它链接回任何人,只要它有效。所以我可能需要给我一些iTunes附属帐户。这里是实时代码。我已经把你提供的代码注释掉了。提前谢谢你的帮助。