如何从 audioscrobbler api 获取当前正在播放的歌曲?
我正在使用 zend 框架从 audioscrobbler api 获取信息。 响应格式如下:
<recenttracks user="RJ">
<track nowplaying="true">
<artist mbid="2f9ecbed-27be-40e6-abca-6de49d50299e">Aretha Franklin</artist>
<name>Sisters Are Doing It For Themselves</name>
<mbid/>
<album mbid=""/>
<url>www.last.fm/music/Aretha+Franklin/_/Sisters+Are+Doing+It+For+Themselves</url>
<date uts="1213031819">9 Jun 2008, 17:16</date>
<streamable>1</streamable>
</track>
...
</recenttracks>
我正在访问这样的元素:
$track->name
如何获取 nowplaying 值?
I am using the zend framework to get info from the audioscrobbler api. The response format is like this:
<recenttracks user="RJ">
<track nowplaying="true">
<artist mbid="2f9ecbed-27be-40e6-abca-6de49d50299e">Aretha Franklin</artist>
<name>Sisters Are Doing It For Themselves</name>
<mbid/>
<album mbid=""/>
<url>www.last.fm/music/Aretha+Franklin/_/Sisters+Are+Doing+It+For+Themselves</url>
<date uts="1213031819">9 Jun 2008, 17:16</date>
<streamable>1</streamable>
</track>
...
</recenttracks>
I am accessing elements as such:
$track->name
How can I get the nowplaying value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 Zend Framework API 文档,您将获得SimpleXML 对象。 您可以使用 attributes() 方法:
According to the Zend Framework API Documentation you are getting a SimpleXML object. You can read an attribute of a
SimpleXMLElement
with it's attributes() method:您可以尝试一下:
或:
或:
但我在任何地方的文档中都没有看到它。
You can give these a try:
or:
or:
I don't see it in the docs anywhere though.
对这个主题不太了解(除了 Audioscrobbler 协议),谷歌搜索似乎表明
$track->getAttribute("nowplaying")
应该可以解决问题。 HTH。Not really knowing much about this subject (except for the Audioscrobbler protocol), googling for it seems to indicate that
$track->getAttribute("nowplaying")
should do the trick. HTH.