My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones    
 
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008 Gabriel Montagné Láscaris-Comneno and Alberto
// Brealey-Guzmán.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
////////////////////////////////////////////////////////////////////////////////

package com.rojored.controls
{

import com.rojored.controls.audioClasses.AudioEvent;
import flash.errors.IOError;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.TimerEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundLoaderContext;
import flash.media.SoundTransform;
import flash.net.URLRequest;
import flash.utils.Timer;
import mx.core.IMXMLObject;

//--------------------------------------
// Events
//--------------------------------------

/**
* Dispatched when the audio file has completed loading.
*
* @eventType flash.events.Event.COMPLETE
*/
[Event(name="complete")]

/**
* Dispatched when ID3 data is available for an MP3 sound.
*
* @eventType flash.events.Event.ID3
*/
[Event(name="id3")]

/**
* Dispatched when an error causes the load operation to fail.
*/
[Event(name="ioError", type="flash.events.IOErrorEvent")]

/**
* Dispatched when a connection has been opened.
*/
[Event(name="open")]

/**
* Dispatched continuosly while the video is playing.
*
* @eventType com.rojored.controls.audioClasses.AudioEvent
*/
[Event(name="playheadUpdate", type="com.rojored.controls.audioClasses.AudioEvent")]

/**
* Dispatched continuously until the FLV file has downloaded completely.
*
* @eventType flash.events.ProgressEvent
*/
[Event(name="progress", type="flash.events.ProgressEvent")]

/**
* Dispatched when the sound has finished playing.
*
* @eventType flash.events.Event
*/
[Event(name="soundComplete")]

/**
* Chromeless audio player that allows scrubbing and the use of embedded
* sources.
*
* @author Gabriel Montagné Láscaris-Comneno gabriel@rojored.com
*/
public class Audio extends EventDispatcher implements IMXMLObject
{

//--------------------------------------------------------------------------
//
// Constructor
//
//--------------------------------------------------------------------------

/**
* Constructor.
*/
public function Audio()
{
super();
}

//--------------------------------------------------------------------------
//
// Variables
//
//--------------------------------------------------------------------------

/**
* @private
*/
private var sound:Sound;

/**
* @private
*/
private var channel:SoundChannel;

/**
* @private
*/
private var soundTransform:SoundTransform;

/**
* @private
* Indicates the last measured time before pausing. Used to determine the
* playhead time when resuming.
*/
private var resumeTime:Number = 0;

/**
* @private
* Indicates the length of the sound we have we use it with bytes total
* and loaded to estimate the actual length of the audio being played
*/
private var loadedLength:Number = 0;

/**
* @private
*/
private var isInitialized:Boolean;

/**
* @private
*/
private var channelUpdateTimer:Timer;

//--------------------------------------------------------------------------
//
// Properties
//
//--------------------------------------------------------------------------

//--------------------------------------
// source
//--------------------------------------

/**
* @private
* Storage for the source property
*/
private var _source:Object;

[Bindable("sourceChanged")]

/**
* Relative path and filename of the audio file to play.
*/
public function get source():Object
{
return _source;
}

/**
* @private
*/
public function set source(value:Object):void
{
if (_source == value)
return;

stop();

_source = value;
dispatchEvent(new Event("sourceChanged"));

if (autoPlay)
play();
}

//--------------------------------------
// playheadTimeChanged
//--------------------------------------

/**
* @private
* Storage for the playheadTime property
*/
private var _playheadTime:Number = 0;

[Bindable("playheadUpdate")]

/**
* Playhead position, measured in seconds, since the audio starting
* playing.
*
* <p>Setting this property to a value in seconds performs a seek
* operation. If the audio is currently playing, it continues playing
* from the new playhead position. If the video is paused, it seeks to
* the new playhead position and remains paused. </p>
*/
public function get playheadTime():Number
{
return _playheadTime;
}

/**
* @private
*/
public function set playheadTime(value:Number):void
{
if (_playheadTime == value)
return;

var wasPaused:Boolean = _isPaused;
var wasPlaying:Boolean = _isPlaying;

pause();

_playheadTime = resumeTime = Math.min(value, loadedLength);

dispatchEvent(
new AudioEvent(
AudioEvent.PLAYHEAD_UPDATE,
false,
false,
_playheadTime
)
);

// TODO: we should we throw errors for out of range values?
// TODO: should we throw the autoPlay into this AND?
if (!wasPaused && wasPlaying)
play();
}

//--------------------------------------
// leftPeak
//--------------------------------------

/**
* @private
* Storage for the leftPeak property
*/
private var _leftPeak:Number = 0;

[Bindable("playheadUpdate")]

/**
* The current amplitude (volume) of the left channel, from 0 (silent) to
* 1 (full amplitude)
*/
public function get leftPeak():Number
{
return _leftPeak;
}

//--------------------------------------
// rightPeak
//--------------------------------------

/**
* @private
* Storage for the rightPeak property
*/
private var _rightPeak:Number = 0;

[Bindable("playheadUpdate")]

/**
* The current amplitude (volume) of the right channel, from 0 (silent) to
* 1 (full amplitude)
*/
public function get rightPeak():Number
{
return _rightPeak;
}

//--------------------------------------
// totalTime
//--------------------------------------

/**
* @private
* Storage for the totalTime property
*/
private var _totalTime:Number = 0;

[Bindable("progress")]
[Bindable("complete")]

/**
* Total length of the media, in milliseconds.
*/
// TODO: transform to seconds?
public function get totalTime():Number
{
return _totalTime;
}

//--------------------------------------
// volume
//--------------------------------------

/**
* @private
* Storage for the volume property
*/
private var _volume:Number = 1;

[Bindable("volumeChanged")]

/**
* The volume, ranging from 0 (silent) to 1 (full volume).
*/
public function get volume():Number
{
return _volume;
}

/**
* @private
*/
public function set volume(value:Number):void
{

if (_volume == value)
return;

_volume = value > 1 ? 1
: value < 0 ? 0
: value
;

updateSoundTransform();
dispatchEvent(new Event("volumeChanged"));
}

//--------------------------------------
// pan
//--------------------------------------

/**
* @private
* Storage for the pan property
*/
private var _pan:Number = 0;

[Bindable("panChanged")]

/**
* left-to-right panning of the sound, raging from -1 (full pan left) to 1
* (full pan right).
*/
public function get pan():Number
{
return _pan;
}

/**
* @private
*/
public function set pan(value:Number):void
{
if (_pan == value) return;
_pan = value < -1 ? -1
: value > 1 ? 1
: value
;
updateSoundTransform();
dispatchEvent(new Event("panChanged"));

}

//--------------------------------------
// isPlaying
//--------------------------------------

/**
* @private
* Storage for the isPlaying property
*/
private var _isPlaying:Boolean;

[Bindable("playheadUpdate")]
[Bindable("soundComplete")]

/**
* If <code>true</code>, the audio is currently playing.
*/
public function get isPlaying():Boolean
{
return _isPlaying && !_isBuffering;
}

/**
* @private
*/
public function set isPlaying(value:Boolean):void
{
if (_isPlaying == value)
return;

_isPlaying = value;
}

//--------------------------------------
// playing
//--------------------------------------

[Bindable("playheadUpdate")]
[Bindable("soundComplete")]

/**
* Small concesion for users familiar the VideoDisplay component API.
*/
public function get playing():Boolean
{
return isPlaying;
}

//--------------------------------------
// isPaused
//--------------------------------------

/**
* @private
* Storage for the isPaused property
*/
private var _isPaused:Boolean;

[Bindable("playheadUpdate")]

/**
* If <code>true</code>, the audio is currently paused.
*/
public function get isPaused():Boolean
{
return _isPaused;
}

//--------------------------------------
// isBuffering
//--------------------------------------

/**
* @private
* Storage for tha isBuffering property
*/
private var _isBuffering:Boolean;

[Bindable("playheadUpdate")]

/**
* If <code>true</code> the audio is being buffered.
*/
public function get isBuffering():Boolean
{
return _isBuffering;
}

//--------------------------------------
// bytesLoaded
//--------------------------------------

/**
* @private
* Storage for the bytesLoaded property
*/
private var _bytesLoaded:int;

[Bindable("progress")]

/**
* The number of bytes that are loaded for the audio file.
*/
public function get bytesLoaded():int
{
return _bytesLoaded;
}

//--------------------------------------
// bytesTotal
//--------------------------------------

/**
* @private
* Storage for the bytesTotal property
*/
private var _bytesTotal:int;

[Bindable("progress")]

/**
* The number of bytes in the entire audio file.
*/
public function get bytesTotal():int
{
return _bytesTotal;
}

//--------------------------------------
// album
//--------------------------------------

/**
* @private
* Storage for the album property
*/
private var _album:String = "";

[Bindable("id3")]

/**
* The name of the album; corresponds to the ID3 2.0 tag TALB.
*/
public function get album():String
{
return _album;
}

//--------------------------------------
// artist
//--------------------------------------

/**
* @private
* Storage for the artist property
*/
private var _artist:String = "";

[Bindable("id3")]

/**
* The name of the artist; corresponds to the ID3 2.0 tag TPE1.
*/
public function get artist():String
{
return _artist;
}

//--------------------------------------
// comment
//--------------------------------------

/**
* @private
* Storage for the comment property
*/
private var _comment:String = "";

[Bindable("id3")]

/**
* A comment about the recording; corresponds to the ID3 2.0 tag COMM.
*/
public function get comment():String
{
return _comment;
}

//--------------------------------------
// comment
//--------------------------------------

/**
* @private
* Storage for the genre property
*/
private var _genre:String = "";

[Bindable("id3")]

/**
* The genre of the song; corresponds to the ID3 2.0 tag TCON.
*/
public function get genre():String
{
return _genre;
}

//--------------------------------------
// songName
//--------------------------------------

/**
* @private
* Storage for the songName property
*/
private var _songName:String = "";

[Bindable("id3")]

/**
* The name of the song; corresponds to the ID3 2.0 tag TIT2.
*/
public function get songName():String
{
return _songName;
}

//--------------------------------------
// track
//--------------------------------------

/**
* @private
* Storage for the track property
*/
private var _track:String = "";

[Bindable("id3")]

/**
* The track number; corresponds to the ID3 2.0 tag TRCK.
*/
public function get track():String
{
return _track;
}

//--------------------------------------
// year
//--------------------------------------

/**
* @private
* Storage for the year property
*/
private var _year:String = "";

[Bindable("id3")]

/**
* The year of the recording; corresponds to the ID3 2.0 TYER.
*/
public function get year():String
{
return _year;
}

//--------------------------------------
// autoPlay
//--------------------------------------

[Bindable]

/**
* Specifies whether the audio should start playing immediately when the
* source property is set.
*/
public var autoPlay:Boolean = true;

//--------------------------------------
// autoRewind
//--------------------------------------

[Bindable]

/**
* Specifies whether the audio should be rewond to the beginning when play
* stops.
*/
public var autoRewind:Boolean = true; // TODO: double check functionality.

//--------------------------------------
// bufferTime
//--------------------------------------

[Bindable]

/**
* The number of seconds to preload a streaming sound into a buffer before
* the sound starts to stream.
*/
public var bufferTime:Number = 1000;

[Bindable]

//--------------------------------------
// checkPolicyFile
//--------------------------------------

/**
* Specifies whether the existence of a cross-domain policy file should be
* checked upon. This is neccessary if ID3 tags are to be processed, but
* the source needs to be inside the security sandbox.
*
* <p>Sandbox security errors will be swallowed by the component.</p>
*/
public var checkPolicyFile:Boolean = true;

//--------------------------------------
// playheadUpdateInterval
//--------------------------------------

[Bindable]

/**
* Specifies the amount of time, in milliseconds, between each
* <code>playheadUpdate</code> event.
*/
public var playheadUpdateInterval:Number = 250;

//--------------------------------------------------------------------------
//
// Methods
//
//--------------------------------------------------------------------------

/**
* @private
*/
public function initialized(document:Object, id:String):void
{
isInitialized = true;
if (_source && autoPlay)
play();
}

/**
* @private
*/
private function prepareSound():void
{

// if we have to actually load the sound
if (_source is String)
loadSound(String(_source));

// or is it embeded
if (_source is Class)
instantiateSoundFromClass(Class(_source));

}

/**
* @private
*/
private function loadSound(url:String):void
{

soundCleanup();
sound = new Sound();

attachSoundListeners();

sound.load(
new URLRequest(url),
new SoundLoaderContext(bufferTime, checkPolicyFile)
);

}

/**
* @private
*/
private function instantiateSoundFromClass(soundClass:Class):void
{

sound = new soundClass() as Sound;
loadedLength = sound.length;
_totalTime = sound.length;
_bytesTotal = sound.bytesTotal;
_bytesLoaded = sound.bytesLoaded;

// fake that we loaded everything instantaneously to force binding
// refresh.
// TODO: actually send a progress event with the appropriate data.
dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS));

sound_id3Handler(null); // force id3 refresh

dispatchEvent(new Event(Event.COMPLETE));

}

/**
* @private
*/
private function updateSoundTransform():void
{
soundTransform = soundTransform || new SoundTransform();
soundTransform.volume = volume;
soundTransform.pan = pan;
if (channel)
channel.soundTransform = soundTransform;
}

/**
* @private
*/
private function cleanup():void
{
soundCleanup();
channelCleanup();
}

/**
* @private
*/
private function soundCleanup():void
{
if (!sound)
return;

try
{
sound.close();
}
catch (error:IOError)
{
// channel was not open, nothing to worry about.
}

removeSoundListeners();
sound = null;
}

/**
* @private
*/
private function channelCleanup():void
{
if (!channel) return;

channel.removeEventListener(
Event.SOUND_COMPLETE,
channel_soundCompleteHandler
);

channelUpdateTimer.stop();
channelUpdateTimer.removeEventListener(
TimerEvent.TIMER,
channelUpdateTimer_timerHandler
);
channel = null;
}

/**
* @private
*/
private function attachSoundListeners():void
{
if (!sound)
return;

sound.addEventListener(Event.COMPLETE, sound_completeHandler);
sound.addEventListener(Event.ID3, sound_id3Handler);
sound.addEventListener(Event.OPEN, sound_openHandler);
sound.addEventListener(IOErrorEvent.IO_ERROR, sound_ioErrorHandler);
sound.addEventListener(ProgressEvent.PROGRESS, sound_progressHandler);
}

/**
* @private
*/
private function removeSoundListeners():void
{

if (!sound)
return;

sound.removeEventListener(Event.COMPLETE, sound_completeHandler);
sound.removeEventListener(Event.ID3, sound_id3Handler);
sound.removeEventListener(Event.OPEN, sound_openHandler);
sound.removeEventListener(IOErrorEvent.IO_ERROR, sound_ioErrorHandler);
sound.removeEventListener(
ProgressEvent.PROGRESS,
sound_progressHandler
);

}

/**
* @private
*/
private function primeChannel():void
{
if (!channel)
return;

channel.soundTransform = soundTransform;
channel.addEventListener(
Event.SOUND_COMPLETE,
channel_soundCompleteHandler
);
channelUpdateTimer = new Timer(playheadUpdateInterval);

channelUpdateTimer.addEventListener(
TimerEvent.TIMER,
channelUpdateTimer_timerHandler
);

channelUpdateTimer.start();
}

/**
* @private
*/
private function resetID3Tags():void
{

// reset properties
_artist = _album = _comment = _genre = _songName = _track = _year =
"";

dispatchEvent(new Event(Event.ID3));
}

/**
* @private
*/
private function resetLoadingInfo():void
{

_bytesTotal = _bytesLoaded = _totalTime = 0;

// TODO: pack the appropriate params.
dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS));
}

/**
* @private
*/
private function relayEvent(event:Event):void
{
dispatchEvent(event);
}

/**
* Starts playing the audio.
*/
public function play():void
{

if (!isInitialized)
return;

if (_isPlaying || !_isPaused)
stop();

if (!_source)
return;

if (!sound)
prepareSound();

if (!soundTransform)
updateSoundTransform();

channelCleanup();

channel = sound.play(resumeTime);

primeChannel();

_isPlaying = true;
_isPaused = false;

}

/**
* Pauses the audio.
*/
public function pause():void
{
if (!_isPlaying || _isPaused)
return;

resumeTime = _playheadTime;
channel.stop();

_isPlaying = false;
_isPaused = true;
}

/**
* Stops the audio.
*/
public function stop():void
{
resetID3Tags();
resetLoadingInfo();

if (channel) channel.stop();
cleanup();

resumeTime = 0;

_isPlaying = false;
_isPaused = false;
}

//--------------------------------------------------------------------------
//
// Event handlers
//
//--------------------------------------------------------------------------

/**
* @private
*/
private function channelUpdateTimer_timerHandler(event:TimerEvent):void
{
// Mostly used for when paused; if we don't check for updates, we
// could dispatch PLAYHEAD_UPDATE many times without having
// anything new to really broadcast
// TODO: double check and optimize
var broadcastChange:Boolean = (
(_isBuffering != sound.isBuffering)
|| (_leftPeak != channel.leftPeak)
|| (_rightPeak != channel.rightPeak)
|| (!_isPaused && (_playheadTime != channel.position))
);

if (!broadcastChange)
return;

_isBuffering = sound.isBuffering;
_leftPeak = channel.leftPeak;
_rightPeak = channel.rightPeak;

// this is for scrubbing while paused.
if (!_isPaused) _playheadTime = channel.position;

dispatchEvent(
new AudioEvent(
AudioEvent.PLAYHEAD_UPDATE,
false,
false,
_playheadTime
)
);
}

/**
* @private
*/
private function channel_soundCompleteHandler(event:Event):void
{
if (autoRewind)
{
stop();
if (autoPlay)
play();
}
else
{
pause();
}
relayEvent(event);
}

/**
* @private
*/
private function sound_completeHandler(event:Event):void
{
relayEvent(event);
}

/**
* @private
*/
private function sound_openHandler(event:Event):void
{
relayEvent(event);
}

/**
* @private
*/
private function sound_progressHandler(event:ProgressEvent):void
{
_bytesLoaded = event.bytesLoaded;
_bytesTotal = event.bytesTotal;
loadedLength = sound.length;

// loadedLength indicates the length of the sound we have
// actually already loaded. we use bytes total and loaded to
// project, more or less, how long the sound will end up being.
_totalTime = Math.ceil(
loadedLength / (_bytesLoaded / _bytesTotal)
);
relayEvent(event);
}

/**
* @private
*/
private function sound_ioErrorHandler(event:IOErrorEvent):void
{
stop();

// we only want to relay the event if it's being handled outside
// as well... nasty runtime errors we're not interested in.
if (hasEventListener(IOErrorEvent.IO_ERROR))
relayEvent(event);
}

/**
* @private
*/
private function sound_id3Handler(event:Event = null):void
{
try
{
_artist = sound.id3.artist || "";
_album = sound.id3.album || "";
_comment = sound.id3.comment || "";
_genre = sound.id3.genre || "";
_songName = sound.id3.songName || "";
_track = sound.id3.track || "";
_year = sound.id3.year || "";
}
catch (error:SecurityError)
{
// nothing too bad. we just don't have security permission to
// see the id3 tags of the current file.
}
relayEvent(event || new Event(Event.ID3));
}
}
}

Change log

7204636fef2f by gabriel montagnĂ© láscaris-comneno <gabr...@rojored.com> on Oct 22, 2010   Diff
Reorganized code into separate components
Go to: 
Sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 26610 bytes, 1148 lines
Powered by Google Project Hosting