如何从 audioscrobbler api 获取当前正在播放的歌曲?

发布于 2024-07-16 05:06:05 字数 692 浏览 6 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倦话 2024-07-23 05:06:05

根据 Zend Framework API 文档,您将获得SimpleXML 对象。 您可以使用 attributes() 方法:

$track->attributes()->nowplaying

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:

$track->attributes()->nowplaying
对你再特殊 2024-07-23 05:06:05

您可以尝试一下:

$track['nowplaying']

或:

$track->getAttrib('nowplaying')

或:

$attributes = $track->attributes();
echo $attributes['nowplaying']

但我在任何地方的文档中都没有看到它。

You can give these a try:

$track['nowplaying']

or:

$track->getAttrib('nowplaying')

or:

$attributes = $track->attributes();
echo $attributes['nowplaying']

I don't see it in the docs anywhere though.

星光不落少年眉 2024-07-23 05:06:05

对这个主题不太了解(除了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文