diff options
author | 2019-12-10 08:19:07 +0100 | |
---|---|---|
committer | 2020-02-04 19:16:01 +0100 | |
commit | 997339efe2a907f10ed665eadf400a49794c6872 (patch) | |
tree | dd10354a98a1d8fe200ac8d89f27b8fd5a58356d /src/js/playlist.js | |
parent | 4cb50b346d13d25b5aef0fe62c16e6407bb43d54 (diff) |
FUNCT Added playlist
Diffstat (limited to 'src/js/playlist.js')
-rw-r--r-- | src/js/playlist.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/js/playlist.js b/src/js/playlist.js new file mode 100644 index 0000000..4739efc --- /dev/null +++ b/src/js/playlist.js @@ -0,0 +1,49 @@ +import { load as load_template } from './templates'; +import Mustache from 'mustache'; + +import { mediaplayer } from 'agl-js-api'; + +var template; +var root; +var currentTrackIndex; +var page = { + playlist: {}, + isPlaying: function() { + return this.selected; + } +}; + +function load() { + mediaplayer.playlist().then(function(playlist){ + page.playlist = playlist.list; + show(); + }); +} + +export function show() { + root.innerHTML = Mustache.render(template, page); +} + + +export function init(node) { + + mediaplayer.on_playlist_changes(function(playlist){ + page.playlist = playlist.list; + show(); + }); + + mediaplayer.on_metadata_changes(function(metadata){ + if( metadata && metadata.track && metadata.track.index !== currentTrackIndex ) { + currentTrackIndex = metadata.track.index; + load(); + } + }); + load_template('playlist.template.html').then(function(result) { + template = result; + root = node; + Mustache.parse(template); + show(); + }, function(error) { + console.error('ERRROR loading main template', error); + }); +}
\ No newline at end of file |