forked from lieberkind/Club101
/
screen.coffee
68 lines (57 loc) · 1.9 KB
/
screen.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
jQuery ->
# add local files to playlist
$(".upload-song").change =>
# initial song upload will move upload element to dialog window
if $(this).parent('.controller-container')
$('.init-app').hide();
$(".upload-song").prependTo('#playlist-dialog');
$(".initially-hidden").removeClass('initially-hidden');
initPlayButton()
# add local songs to playlist
files = $(".upload-song")[0].files
# chrome workaround
window.URL = window.webkitURL if (window.webkitURL)
# set playlist and song titles
playlist = []
for file in files
lastDotPos = file.name.lastIndexOf(".")
title = file.name.substring(0, lastDotPos)
url = window.URL.createObjectURL(file)
playlist.push({title: title, url: url})
songPlayer.setPlaylist(playlist)
# view playlist on click
$(".view-playlist").click ->
songPlayer.outputPlaylist()
$( "#playlist-dialog" ).dialog
modal: true
resizable: false
# for file in files
# binaryReader = new FileReader()
# binaryReader.readAsBinaryString(file)
# binaryReader.onloadend = ->
# dv = new jDataView(this.result)
# if (dv.getString(3, dv.byteLength - 128) == 'TAG')
# title = dv.getString(30, dv.tell());
# # artist = dv.getString(30, dv.tell());
# # album = dv.getString(30, dv.tell());
# # year = dv.getString(4, dv.tell());
# console.log(title);
initPlayButton = ->
# music controller: jQueryUI button style
$( ".play-pause" ).button
text: false
icons:
primary: "ui-icon-play"
.click ->
# start
if songPlayer.unstarted()
songPlayer.start()
console.log("unstarted")
# resume
else if songPlayer.current.paused is true
songPlayer.play()
console.log("resume")
# pause
else
songPlayer.pause()
console.log("pause")