-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.html
123 lines (103 loc) · 4.67 KB
/
example.html
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html>
<head>
<title>Transistor demo page</title>
<meta charset="utf-8" />
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="./lib/amplify.min.js"></script>
<script src="./lib/require.js"></script>
<script type="text/javascript">
// Two helper methods to set and get a cookie
// See http://www.w3schools.com/js/js_cookies.asp
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}
</script>
<style type="text/css">
</style>
</head>
<body>
<h1>Transistor demo page</h1>
<script type="text/javascript">
// Let's use the global namespace. This is just a demo after all...
var radio = null;
SM2_DEFER = true;
require(['./lib/soundmanager2-nodebug-jsmin.js', 'lib/transistor-async.js'], function() {
window.soundManager = new SoundManager();
window.soundManager.url = './lib/';
window.soundManager.beginDelayedInit();
// nested require needed because lib/transistor-async is build
// as a bundle of define statements. is there a way of doing
// this that doesn't require two require's?
require(['transistor'], function (Transistor) {
// We need an API Session, API Secret and API Key. Since we don't want to
// store it in this file, use a cookie
var cfg = {
"key": getCookie("api_key"),
"secret": getCookie("api_secret"),
"session": getCookie("api_session")
}
// No cookie found? Let's ask the user
if (cfg.key==null || cfg.key=='') {
alert('To use this you have to get an last.fm API Key, API Secret and create an API Session. http://www.last.fm/api/account');
cfg.key=prompt("Please enter your API KEY:","");
cfg.secret=prompt("Please enter your API SECRET:","");
cfg.session=prompt("Please enter your API SESSION:","");
setCookie("api_key",cfg.key,365);
setCookie("api_secret",cfg.secret,365);
setCookie("api_session",cfg.session,365);
}
// Create a new radio
radio = new Transistor(cfg);
// Show the "tune" link
$('#tune').show();
function onPlay(id, track) {
onResume.apply(this, arguments);
$('h1').text('You are listening to '+track.title+' by '+track.artist);
}
function onResume(id, track) {
$('#play').hide();
$('#pause, #skip, #love, #ban').show();
}
function onPause(id, track) {
$('#play').show();
$('#pause, #skip, #love, #ban').hide();
}
// Set up event handlers
amplify.subscribe('transistorplayer:playing', radio, onPlay);
amplify.subscribe('transistorplayer:resumed', radio, onResume);
amplify.subscribe('transistorplayer:paused', radio, onPause);
});
});
function tune() {
radio.tune($('#station').val());
$('#play').show();
}
</script>
<input type="text" value="lastfm://user/marekventur" id="station">
<a href="#" onclick="tune();" style="display:none;" id="tune">Tune</a></br>
<a href="#" onclick="radio.play();" style="display:none;" id="play">Play</a></br>
<a href="#" onclick="radio.pause();" style="display:none;" id="pause">Pause</a></br>
<a href="#" onclick="radio.skip();" style="display:none;" id="skip">Skip</a></br>
<a href="#" onclick="radio.love();" style="display:none;" id="love">Love</a></br>
<a href="#" onclick="radio.ban();" style="display:none;" id="ban">Ban</a></br>
</body>
</html>