root/as3/SiOPM/trunk/samples/SiOPMJavaScriptBridge/siopm.js

リビジョン 2697, 7.3 kB (コミッタ: keim, コミット時期: 3 年 前)

サウンドライブラリ SiON ver0.5.3 更新 tutrial 追加など

Line 
1 /*
2  * original:jsmml by Yuichi Tateno
3  * http://coderepos.org/share/wiki/JSMML
4  * http://rails2u.com/
5  *
6  * Modifyed by keim
7  * http://www.yomogi.sakura.ne.jp/~si/
8  *
9  * The MIT Licence.
10  */
11
12
13 // SIOPM object
14 //------------------------------
15 SIOPM = function() {};
16
17
18
19
20 // version informations
21 //------------------------------
22 SIOPM.VERSION = '0.4.0';
23 SIOPM.SWF_VERSION = 'SWF has not loaded.';
24 SIOPM.toString = function() { return 'SIOPM_VERSION: ' + SIOPM.VERSION + '/ SWF_VERSION: ' + SIOPM.SWF_VERSION; };
25
26
27
28
29 // variables for setting
30 // - change settings by modifying these variables BEFORE calling initialize().
31 //------------------------------
32 SIOPM.urlSWF         = 'siopm.swf';
33 SIOPM.mmlPlayerDivID = 'siopmPlayerDiv';
34 SIOPM.mmlPlayerID    = 'siopmPlayer';
35 SIOPM.mmlPlayer      = undefined;
36
37
38
39
40 // variables updated inside.
41 // - you can check the status by refering these variables.
42 //------------------------------
43 // flag ok to use.
44 SIOPM.loaded = false;
45 // flag ok to play sound.
46 SIOPM.compiled = false;
47 // flag playing sound.
48 SIOPM.playing = false;
49 // flag paused.
50 SIOPM.paused = false;
51
52 // progression status of compiling (0,1). this can refer from onCompileProgress().
53 SIOPM.compileProgress = 0;
54 // title of the loaded mml data.
55 SIOPM.title = "";
56
57
58
59
60 // callback functions
61 // - impelement thses functions to handle events.
62 //------------------------------
63 // call back when finish initializing.
64 SIOPM.onLoad = function() {};
65
66 // call back while compiling.
67 SIOPM.onCompileProgress = function() {};
68
69 // call back when finish compiling.
70 SIOPM.onCompileComplete = function() { SIOPM.play(); };
71
72 // call back while playing sound.
73 SIOPM.onStream = function() {};
74
75 // call back before the stream starts.
76 SIOPM.onStreamStart = function() {};
77
78 // call back after the stream stops.
79 SIOPM.onStreamStop = function() {};
80
81 // call back after fading in.
82 SIOPM.onFadeInComplete = function() {};
83
84 // call back after fading out.
85 SIOPM.onFadeOutComplete = function() {};
86
87 // call back when error appears.
88 SIOPM.onError = function() {};
89
90
91
92
93 // operations
94 // - call these functions to operate SiOPM.
95 //------------------------------
96 // compile mml string. this calls back onCompileProgress(), onCompileComplete() and onError() inside.
97 SIOPM.compile = function(_mml) { SIOPM.mmlPlayer._compile(_mml); SIOPM.compiled = false; }
98
99 // play sound. call this after compile completed. this calls back onStreamStart(), onSteam() and onError() inside.
100 SIOPM.play = function() { SIOPM.mmlPlayer._play(); SIOPM.paused = false; }
101
102 // stop sound. this calls back onStreamStop() inside.
103 SIOPM.stop = function() { SIOPM.mmlPlayer._stop(); SIOPM.paused = false; }
104
105 // pause sound. you can resume by calling play().
106 SIOPM.pause = function() { SIOPM.mmlPlayer._pause(); SIOPM.paused = true; }
107
108 // translate the TSSCP mml to SiOPM mml.
109 SIOPM.trans = function(_tss) { return SIOPM.mmlPlayer._trans(_tss); }
110
111 // control/refer volume by Number (0,1), you can refer a volume to call this without any arguments.
112 SIOPM.volume = function() { return SIOPM.mmlPlayer._volume(arguments[0]); }
113
114 // control/refer panning by Number (-1,1), you can refer a panning to call this without any arguments.
115 SIOPM.pan = function() { return SIOPM.mmlPlayer._pan(arguments[0]); }
116
117 // control/refer position by Number (unit in milli-second), you can refer the position to call this without any arguments.
118 SIOPM.position = function() { return SIOPM.mmlPlayer._position(arguments[0]); }
119
120 // fade in time (unit in second).
121 SIOPM.fadeIn = function() { return SIOPM.mmlPlayer._fadeIn(arguments[0]); }
122
123 // fade out time (unit in second).
124 SIOPM.fadeOut = function() { return SIOPM.mmlPlayer._fadeOut(arguments[0]); }
125
126 // initialize. call this first of all. ussualy call this in body.onLoad(). this calls back onLoad() when the SiOPM is initialized successfully.
127 SIOPM.initialize = function() {
128     // check swf object
129     if (! document.getElementById(SIOPM.mmlPlayerDivID)) {
130         // check flash players major version
131         if (getFlashPlayerVersion(0) < 10) {
132             SIOPM.onError("The SiOPM module is only available on Flash Player 10.");
133             return;
134         }
135        
136         // insert swf object
137         // create <div> tag
138         var swfName = SIOPM.urlSWF + '?' + (new Date()).getTime();
139         var div = document.createElement('div');
140         div.id = SIOPM.mmlPlayerDivID;
141         div.style.display = 'inline';
142         div.width = 1;
143         div.height = 1;
144         document.body.appendChild(div);
145
146         if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
147             // ns
148             var o = document.createElement('object');
149             o.id = SIOPM.mmlPlayerID;
150             o.classid = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
151             o.width = 1;
152             o.height = 1;
153             o.setAttribute('data', swfName);
154             o.setAttribute('type', 'application/x-shockwave-flash');
155             var p = document.createElement('param');
156             p.setAttribute('name', 'allowScriptAccess');
157             p.setAttribute('value', 'always');
158             o.appendChild(p);
159             div.appendChild(o);
160         } else {
161             // ie
162             var object = '<object id="' + SIOPM.mmlPlayerID + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="1" height="1">';
163             object    += '<param name="movie" value="' + swfName + '" />';
164             object    += '<param name="bgcolor" value="#FFFFFF" />';
165             object    += '<param name="quality" value="high" />';
166             object    += '<param name="allowScriptAccess" value="always" />';
167             object    += '</object>';
168             div.innerHTML = object;
169         }
170     }
171 }
172
173 // get Flash player version numbers. argument requires sub numbers.
174 function getFlashPlayerVersion(subs) {
175     return (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) ?
176         navigator.plugins["Shockwave Flash"].description.match(/([0-9]+)/)[subs] :
177         (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")).GetVariable("$version").match(/([0-9]+)/)[subs];
178 }
179
180
181
182
183 //------------------------------------------------------------------------------------------------------------------------
184 // internal functions
185 //------------------------------
186 // callback from siopm.swf
187 SIOPM._internal_onLoad = function(version) {
188     SIOPM.SWF_VERSIOPM = version;
189     SIOPM.loaded = true;
190     SIOPM.mmlPlayer = document.getElementById(SIOPM.mmlPlayerID);
191     SIOPM.onLoad();
192 }
193 SIOPM._internal_onCompileProgress = function(progress) {
194     SIOPM.compileProgress = progress;
195     SIOPM.onCompileProgress();
196 }
197 SIOPM._internal_onCompileComplete = function(title) {
198     SIOPM.title = title;
199     SIOPM.compiled = true;
200     SIOPM.compileProgress = 1;
201     SIOPM.onCompileComplete();
202 }
203 SIOPM._internal_onError = function(message) {
204     SIOPM.onError(message);
205 }
206 SIOPM._internal_onStream = function() {
207     SIOPM.onStream();
208 }
209 SIOPM._internal_onStreamStart = function() {
210     SIOPM.playing = true;
211     SIOPM.onStreamStart();
212 }
213 SIOPM._internal_onStreamStop = function() {
214     SIOPM.playing = false;
215     SIOPM.onStreamStop();
216 }
217 SIOPM._internal_onFadeInComplete = function () {
218     SIOPM.onFadeInComplete();
219 }
220 SIOPM._internal_onFadeOutComplete = function () {
221     SIOPM.onFadeOutComplete();
222 }
223
224
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。