-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_audio_formt.js
130 lines (114 loc) · 9.18 KB
/
test_audio_formt.js
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
124
125
126
127
128
129
130
/*
Thanks to westonruter (http://github.com/westonruter) for the idea of including
base64 encoded files in the tests http://gist.github.com/253174
*/
var CUIAudioTest = new Class({
Implements: [Events],
initialize: function(){
this.name = 'html5 audio test';
this.version = 1.0;
this.donotdebugoptions = true;
this.playableFormats = [];
this.unPlayableFormats = [];
this.audioSupport = false;
this.progress = 0;
this.addEvents({'completedTest': $empty, 'completedAllTests': $empty});
this.audioTests = new Hash({
'mp3': {'extensions':['mp3'],'mime':'audio/mpeg','file':'data:audio/mpeg;base64,//MoxAAAAANIAAAAAExBTUUzLjk2LjFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//MoxDsAAANIAAAAAFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV'},
'ogg': {'extensions':['ogg'],'mime':'audio/ogg','file':'data:audio/ogg;base64,T2dnUwACAAAAAAAAAACEXphXAAAAADKlPqQBHgF2b3JiaXMAAAAAAUSsAAAAAAAAgLsAAAAAAAC4AU9nZ1MAAAAAAAAAAAAAhF6YVwEAAADG29GAD0j/////////////////MgN2b3JiaXM4AAAAQU87IGFvVHVWIGI0YiBbMjAwNTExMTddIChiYXNlZCBvbiBYaXBoLk9yZydzIGxpYlZvcmJpc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Nu2b9y6ruu%2B7/vCka3rui78wjEMRwEA4AkOAEAFNqyOcFI0FlhoyEoAIAMAgDAGIYMQQgYhhJBSSiGllBIAADDgAAAQYEIZKDRkRQAQJwAAGEMppJRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkgppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkqppJRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoplVJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSCgCQinAAkHowoQwUGrISAEgFAACMUUopxpyDEDHmGGPQSSgpYsw5xhyUklLlHIQQUmktt8o5CCGk1FJtmXNSWosx5hgz56SkFFvNOYdSUoux5ppr7qS0VmuuNedaWqs115xzzbm0FmuuOdecc8sx15xzzjnnGHPOOeecc84FAOA0OACAHtiwOsJJ0VhgoSErAYBUAAACGaUYc8456BBSjDnnHIQQIoUYc845CCFUjDnnHHQQQqgYc8w5CCGEkDnnHIQQQgghcw466CCEEEIHHYQQQgihlM5BCCGEEEooIYQQQgghhBA6CCGEEEIIIYQQQgghhFJKCCGEEEIJoZRQAABggQMAQIANqyOcFI0FFhqyEgAAAgCAHJagUs6EQY5Bjw1BylEzDUJMOdGZYk5qMxVTkDkQnXQSGWpB2V4yCwAAgCAAIMAEEBggKPhCCIgxAABBiMwQCYVVsMCgDBoc5gHAA0SERACQmKBIu7iALgNc0MVdB0IIQhCCWBxAAQk4OOGGJ97whBucoFNU6iAAAAAAAAwA4AEA4KAAIiKaq7C4wMjQ2ODo8AgAAAAAABYA%2BAAAOD6AiIjmKiwuMDI0Njg6PAIAAAAAAAAAAICAgAAAAAAAQAAAAICAT2dnUwAELAAAAAAAAACEXphXAgAAAE3ViFYCAQEACg%3D%3D'},
'wav': {'extensions':['wav'],'mime':'audio/x-wav','file':'data:audio/x-wav;base64,UklGRnwAAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YVgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'},
'aif': {'extensions':['aif','aiff'],'mime':'audio/x-aiff','file':'data:audio/x-aiff;base64,Rk9STQAAADhBSUZGQ09NTQAAABIAAQAAAAUAEEALu4AAAAAAAABTU05EAAAACgAAAAAAAAAAAAAAAAAAAAAAAA%3D%3D'}
});
},
runTests: function() {
try {
this.audioTests.each(function(item, index){
try {
var audio = new Audio();
} catch(e) {
this.fireEvent('completedAllTests');
}
if(audio.canPlayType(item['mime']) != 'no') {
// If this event fires the file can play
// (Didn't fire properly using moo's addEvent method)
audio.addEventListener('canplaythrough', function(e){
this.updateFormats(true,item['mime'],item['extensions']);
}.bind(this), false);
// If this event fires the file cannot play
document.id(audio).addEvent('error', function(e){
this.updateFormats(false,item['mime'],item['extensions']);
}.bind(this));
// try loading audio
audio.src = item['file'];
audio.load();
} else {
this.updateFormats(false,item['mime'],item['extensions']);
}
}.bind(this));
} catch(e) {
this.fireEvent('completedAllTests');
}
},
updateFormats: function(canplay,mime,extensions) {
if (!this.audioSupport) {
this.audioSupport = true;
}
if (canplay) {
this.playableFormats.combine(extensions);
} else {
this.unPlayableFormats.combine(extensions);
}
this.progress += 1;
this.fireEvent('completedTest',mime);
if (this.progress == this.audioTests.getLength()) {
this.fireEvent('completedAllTests');
}
},
getPlayableFormats: function() {
return this.playableFormats;
},
getUnPlayableFormats: function() {
return this.unPlayableFormats;
},
getAudioSupport: function() {
return this.audioSupport;
}
});
// everything below here just generates the test page. it'll all get scrapped
// when we fully integrate and plug HTML5 into the soundplayer...
window.addEvent('domready', function(){
audiotest = new CUIAudioTest();
audiotest.addEvent('completedAllTests', function() {
var resultsdiv = new Element('div', {
'styles': {'width':400,'margin': '0 auto','padding-top':200,'font-family':'helvetica,arial,sans-serif'}
}).inject(document.body);
if (audiotest.getAudioSupport()) {
new Element('h2', {
'styles':{'font':'2em/1.5em HelveticaNeueLTStd-UltLt,"HelveticaNeueLT Std UltLt","Helvetica Neue Ultra Light","Helvetica Neue",HelveticaNeue-UltraLight,HelveticaLTStd-Light,Helvetica,Arial,sans-serif','font-weight':'100'},
html: 'Good News'
}).inject(resultsdiv);
var successp = new Element('p', {
html: 'Your browser supports HTML5 audio, so we can do neat things with it. Specifically, it can play: '
}).inject(resultsdiv);
new Element('span', {
'styles': {'color':'#090','font-weight':'bold'},
html: audiotest.getPlayableFormats().join(' ')
}).inject(successp);
var failp = new Element('p', {
html: 'Unfortunately all good things have a downside. Your browser stinks at playing: '
}).inject(resultsdiv);
new Element('span', {
'styles': {'color':'#c00','font-weight':'bold'},
html: audiotest.getUnPlayableFormats().join(' ')
}).inject(failp);
} else {
new Element('h2', {
html: 'Bad News'
}).inject(resultsdiv);
var successp = new Element('p', {
html: 'Your browser doesn\'t jibe with HTML5 audio. That\'s pretty weak.'
}).inject(resultsdiv);
}
});
audiotest.runTests();
});