Spotify App API:标签页、播放列表 UI 刷新
我正在构建一个带有四个选项卡页面的 Spotify 应用程序。所有选项卡的内容都会在应用程序初始加载时加载。每个选项卡都包含一个或多个播放列表,这些播放列表由来自第 3 方 Web API 的数据填充,这些数据被解析为 Spotify 曲目。
所选选项卡工作正常。播放列表按预期显示。问题在于最初隐藏但后来被选择的选项卡。选择后,播放列表如下所示:
未完全呈现的播放列表
<div class="sp-list sp-light" tabindex="0">
<div style="height: 100px; ">
</div>
</div>
当我调整 Spotify 桌面应用程序的大小时,播放列表最终呈现:
为了填充播放列表,我使用“标准”Spotify 模型和意见:
var playlist = new views.List(tempPlaylist);
//where tempPlaylist is a new models.Playlist();
//that has been populated with tempPlaylist.add(search.tracks[0].uri);
playerPlaylistDiv.append(playlist.node);
我只在使用选项卡时遇到这个问题。当在一个长页面上显示所有内容时,所有播放列表都会完全呈现。我想知道这是否与时间有关:我隐藏了尚未完全渲染的内容?任何想法都非常感激。
我以这种方式处理选项卡更改:
/* Handle URI arguments */
models.application.observe(models.EVENT.ARGUMENTSCHANGED, tabs);
/* Handle tab changes */
function tabs() {
var args = models.application.arguments;
// Hide all sections
$('section').hide();
// Show current section
$("#" + args[0]).show();
}
仅供参考,我正在使用 Spotify 预览版 0.8.10.3。
I am building a Spotify App with four tab pages. The content of all tabs are loaded on initial load of the app. Each tab contain one or more playlists that are being populated with data from 3rd party web apis that are resolved into spotify tracks.
The selected tab works fine. the playlist show up a expected. The problem is with tabs that are initially hidden but later selected. Here the playlist looks like this when selected:
Looking in the Inspector I can see that the content has not yet rendered:
<div class="sp-list sp-light" tabindex="0">
<div style="height: 100px; ">
</div>
</div>
When I do a resize of the Spotify desktop app, the playlist is finally rendered:
rendered playlist after resize
To populate the playlist I use the 'standard' spotify models and views:
var playlist = new views.List(tempPlaylist);
//where tempPlaylist is a new models.Playlist();
//that has been populated with tempPlaylist.add(search.tracks[0].uri);
playerPlaylistDiv.append(playlist.node);
I am only seing this issue when using tabs. When displaying all content on one long page all playlists are fully rendered. I wonder if it has to do with timing: that I am hiding content that has not yet fully rendered? Any thoughts much appreciated.
I handle tab changes this way:
/* Handle URI arguments */
models.application.observe(models.EVENT.ARGUMENTSCHANGED, tabs);
/* Handle tab changes */
function tabs() {
var args = models.application.arguments;
// Hide all sections
$('section').hide();
// Show current section
$("#" + args[0]).show();
}
FYI I am using the Spotify preview 0.8.10.3.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不确定这是同一件事,但我在尝试从 playlist-uris 动态创建曲目列表时遇到了类似的问题;也无法更接近地追踪它(包含的 DOM 肯定已渲染并准备就绪);它只发生在某些播放列表上,从来没有发生在专辑上。
我能够通过“克隆”播放列表来规避这个问题 - 显然有一个“性能”打击......
我不确定这里有什么,但也许这对你有帮助:)
PS。另外 - 确保你在index.html()中有一个doctype声明,如果没有的话,spotify客户端会做一些奇怪的事情。
I am not sure this is the same thing, but I ran into similar issues trying to create tracklistings from playlist-uris on the fly; also couldn't track it down any closer (the containing DOM was certainly rendered and ready); and it only happened on certain playlists, never e.g. on albums.
I was able to circumentvent this problem by "cloning" playlist - obviously there's a "performance" hit ...
I am not sure what's on here, but maybe that helps you along :)
PS. Also - make sure you have a doctype-declaration in index.html (), the spotify client does some weird things if you don't.
我找到的解决方案是这样的:
我将其向下箭头指向显示/隐藏内容的问题,因为在没有选项卡的情况下显示完整内容永远不会导致问题。因此,我现在不再使用 .show()/.hide() ,而是通过将各部分的高度设置为 100%/0 来隐藏和显示内容:
不知道为什么这样做有效,但它确实有效(至少对我来说)。
The solution I've found is this:
I arrowed it down to being an issue with showing/hiding the content since showing the full content without tabs never causes issues. So instead of using .show()/.hide() I now hide and show the content by setting the height of the sections to 100%/0:
Not sure why this works, but it does (for me at least).
我遇到了同样的问题(请参阅 Spotify List 对象创建自localStorage 数据出现空白)并通过在任何处理之前执行 div 的 hide()/show() 来修复它。以前我正在构建播放列表,然后对 div 进行 show() 操作,然后导致出现一个空白列表。
I had the same problem (see Spotify List objects created from localStorage data come up blank) and fixed it by doing the hide()/show() of divs before any processing. Previously I was constructing the playlist and then show()ing the div after which led to a blank list.
我想我实际上已经成功解决了这个问题,而且我认为这是无懈可击的。
基本上,我试图通过尝试说服 API 它需要通过隐藏事物/滚动事物/移动事物来重新绘制播放列表来解决这个问题,这些事物偶尔会起作用,但从未一致地起作用。我从来没有想过要更改播放列表本身。或者至少让 API 认为播放列表已更改。
您可以通过在 Playlist 对象上触发事件来实现此目的。
这些只是 Spotify 的标准功能,并且列表会更新,因为它认为播放列表中的内容发生了变化。希望这对某人有帮助!
I think I've actually managed to solve this and I think it's bulletproof.
Basically I was trying to solve this by trying to convince the API that it needed to redraw the playlist by hiding things/scrolling things/moving things which worked occasionally but never consistently. It never occurred to me to change the playlist itself. Or at least make the API think the playlist has changed.
You can do so by firing an event on the Playlist object.
These are just standard Spotify functions and the list updates because it thinks something has changed in the playlist. Hope this helps someone!