Created
November 16, 2012 13:02
-
-
Save arisetyo/4087191 to your computer and use it in GitHub Desktop.
HTML5 Audio Player with Knockout.js Playlist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<audio id="audioplayer" controls="controls" autoplay="autoplay" data-bind="attr:{src: selectedFile}"></audio> | |
<p>Selected song: <span id="audioplayer" data-bind="text: selectedSong"></span></p> | |
<img data-bind="attr:{src: selectedCover}" width="200"/> | |
<tbody data-bind="foreach: availableSongs"> | |
<tr> | |
<td data-bind="text: artist"></td> | |
<td><img data-bind="attr:{src: cover}" width="60"/> <span data-bind="text: album"></span></td> | |
<td data-bind="text: title"></td> | |
<td><a href="#" data-bind="click: $root.selectSong">PLAY</a></td> | |
</tr> | |
</tbody> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Overall viewmodel for this screen, along with initial state | |
function PlaylistViewModel() { | |
var self = this; | |
self.availableSongs = [{ id:0, artist: "The AATS", album: "The AATS", cover: "audio/the_aats.jpeg", title: "Hae Man! V2", file:"audio/the_aats-hae_man_v2.mp3" }, { id:1, artist: "The AATS", album: "The AATS", cover: "audio/the_aats.jpeg", title: "Piyambakan", file:"audio/the_aats-piyambakan.mp3" }]; | |
self.selectedFile = ko.observable(); | |
self.selectedCover = ko.observable(); | |
self.selectedSong = ko.observable(); | |
self.selectSong = function(data) { | |
self.selectedCover(data.cover); | |
self.selectedFile(data.file); | |
self.selectedSong(data.artist+" - "+data.title); | |
} | |
} | |
ko.applyBindings(new PlaylistViewModel()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment