I am building a Music Player Component with my favorites songs by SoundCloud API and Ember Cli
我正在使用SoundCloud API和Ember Cli构建一个带有我最喜欢歌曲的音乐播放器组件
The Music Player is playing the audio anytime i select a song but i am trying now to play the nextFavorite once the the current song is finished.
音乐播放器在我选择一首歌时随时播放音频,但我现在正试着在当前歌曲结束后播放nextFavorite。
I need to access to the favorite model index of my favorites to get the next Favorite
我需要访问我最喜欢的模型索引以获得下一个收藏夹
Here the Music controller
这里是音乐控制器
player: Ember.computed.alias('controllers.player')
actions: {
setAsFavorite: function (favorite) {
var favorites, favorite
favorites = this.get('model');
if (favorite != null) {
this.get('player').set('favorites', favorites);
}
if (favorite != null) {
return this.get('player').send('selectFavorite', favorite, 0);
}
}
}
How can i access to the favorite index of my array favorites ?
如何访问我最喜欢的数组收藏夹索引?
return this.get('player').send('selectFavorite', favorite, 0);
In the code above i pass it as "0" but i need to pass this correct index of the favorite song i click as setAsFavorite
在上面的代码我把它传递为“0”,但我需要传递这个正确的索引,我点击的最喜欢的歌曲asAsAsFavorite
1 个解决方案
#1
1
Did some minor refacto on your code. Added index of the favorite of favorites array. Also provided a way of getting next song instantly
你的代码做了一些小的重构。添加了收藏夹阵列最喜欢的索引。还提供了一种即时获取下一首歌的方法
actions: {
setAsFavorite: function (favorite) {
var favorites = this.get('model');
var player = this.get('player');
if (Ember.isPresent(favorite)) {
player.set('favorites', favorites);
player.send('selectFavorite', favorite, favorites.indexOf(favorite));
// for next song
// player.send('selectFavorite', favorite, favorites.nextObject(favorite));
}
}
}
#1
1
Did some minor refacto on your code. Added index of the favorite of favorites array. Also provided a way of getting next song instantly
你的代码做了一些小的重构。添加了收藏夹阵列最喜欢的索引。还提供了一种即时获取下一首歌的方法
actions: {
setAsFavorite: function (favorite) {
var favorites = this.get('model');
var player = this.get('player');
if (Ember.isPresent(favorite)) {
player.set('favorites', favorites);
player.send('selectFavorite', favorite, favorites.indexOf(favorite));
// for next song
// player.send('selectFavorite', favorite, favorites.nextObject(favorite));
}
}
}