flexPartyPlayer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/Gemfile +6 -0
  2. data/README +45 -0
  3. data/lib/corelib-08.30.2007.swc +0 -0
  4. data/lib/flexPartyPlayer.rb +42 -0
  5. data/lib/flexunit-08.30.2007.swc +0 -0
  6. data/sample.json +1 -0
  7. data/script/destroy +14 -0
  8. data/script/flex_compile +2 -0
  9. data/script/generate +14 -0
  10. data/src/FlexPlayer.mxml +34 -0
  11. data/src/assets/app_icons/icon_128.png +0 -0
  12. data/src/cc/varga/mvc/ApplicationContext.as +120 -0
  13. data/src/cc/varga/mvc/commands/data/LoadArtistDataCommand.as +61 -0
  14. data/src/cc/varga/mvc/commands/playlist/AddItemToPlaylist.as +13 -0
  15. data/src/cc/varga/mvc/commands/playlist/LoadPlaylistCommand.as +109 -0
  16. data/src/cc/varga/mvc/commands/system/DrawPlaylist.as +40 -0
  17. data/src/cc/varga/mvc/commands/system/Shutdown.as +51 -0
  18. data/src/cc/varga/mvc/commands/system/Startup.as +57 -0
  19. data/src/cc/varga/mvc/commands/video/AddVideoCommand.as +55 -0
  20. data/src/cc/varga/mvc/events/appBar/AppBarEvent.as +16 -0
  21. data/src/cc/varga/mvc/events/blipfm/feedloader/FeedLoaderEvent.as +17 -0
  22. data/src/cc/varga/mvc/events/controllers/ControllersEvent.as +59 -0
  23. data/src/cc/varga/mvc/events/menu/MenuEvent.as +13 -0
  24. data/src/cc/varga/mvc/events/player/PlayerEvent.as +29 -0
  25. data/src/cc/varga/mvc/events/playlist/PlaylistEvent.as +16 -0
  26. data/src/cc/varga/mvc/events/playlist/PlaylistURLEvent.as +57 -0
  27. data/src/cc/varga/mvc/events/playlist/controller/PlaylistControllerEvent.as +59 -0
  28. data/src/cc/varga/mvc/events/search/SearchEvent.as +17 -0
  29. data/src/cc/varga/mvc/events/serveradmin/ServerAdminEvent.as +15 -0
  30. data/src/cc/varga/mvc/events/sound/SoundEvent.as +16 -0
  31. data/src/cc/varga/mvc/events/system/SystemEvent.as +24 -0
  32. data/src/cc/varga/mvc/models/data/AppDataModel.as +17 -0
  33. data/src/cc/varga/mvc/models/player/PlayerModel.as +76 -0
  34. data/src/cc/varga/mvc/models/playlist/PlaylistModel.as +118 -0
  35. data/src/cc/varga/mvc/models/sound/ISound.as +12 -0
  36. data/src/cc/varga/mvc/models/sound/SoundModel.as +284 -0
  37. data/src/cc/varga/mvc/models/sound/SoundModelPlayer.as +8 -0
  38. data/src/cc/varga/mvc/services/KeyboardControl.as +60 -0
  39. data/src/cc/varga/mvc/views/blipfm/feedloader/FeedLoader.mxml +34 -0
  40. data/src/cc/varga/mvc/views/blipfm/feedloader/FeedLoaderMediator.as +68 -0
  41. data/src/cc/varga/mvc/views/controllers/Controllers.mxml +36 -0
  42. data/src/cc/varga/mvc/views/controllers/ControllersMediator.as +107 -0
  43. data/src/cc/varga/mvc/views/infoDisplay/InfoDisplay.mxml +20 -0
  44. data/src/cc/varga/mvc/views/infoDisplay/InfoDisplayMediator.as +51 -0
  45. data/src/cc/varga/mvc/views/menu/Menu.mxml +28 -0
  46. data/src/cc/varga/mvc/views/menu/MenuMediator.as +30 -0
  47. data/src/cc/varga/mvc/views/player/PlayerItem.mxml +11 -0
  48. data/src/cc/varga/mvc/views/player/PlayerWindow.mxml +73 -0
  49. data/src/cc/varga/mvc/views/player/PlayerWindowMediator.as +136 -0
  50. data/src/cc/varga/mvc/views/playlist/Playlist.mxml +22 -0
  51. data/src/cc/varga/mvc/views/playlist/PlaylistMediator.as +117 -0
  52. data/src/cc/varga/mvc/views/playlist/PlaylistStates.as +10 -0
  53. data/src/cc/varga/mvc/views/playlistItem/PlaylistItem.mxml +94 -0
  54. data/src/cc/varga/mvc/views/playlistItem/PlaylistItemMediator.as +87 -0
  55. data/src/cc/varga/mvc/views/playlistManager/PlaylistManager.mxml +7 -0
  56. data/src/cc/varga/mvc/views/playlistManager/PlaylistManagerMediator.as +15 -0
  57. data/src/cc/varga/mvc/views/playlisturl/PlaylistURL.mxml +41 -0
  58. data/src/cc/varga/mvc/views/playlisturl/PlaylistURLMediator.as +87 -0
  59. data/src/cc/varga/mvc/views/playlisturl/controller/PlaylistController.mxml +37 -0
  60. data/src/cc/varga/mvc/views/playlisturl/controller/PlaylistControllerMediator.as +79 -0
  61. data/src/cc/varga/mvc/views/search/Search.mxml +26 -0
  62. data/src/cc/varga/mvc/views/search/SearchMediator.as +31 -0
  63. data/src/cc/varga/mvc/views/server/administration/ServerAdmin.mxml +26 -0
  64. data/src/cc/varga/mvc/views/server/administration/ServerAdminMediator.as +51 -0
  65. data/src/cc/varga/mvc/views/visualisation/Visualisation.mxml +8 -0
  66. data/src/cc/varga/mvc/views/visualisation/VisualisationMediator.as +51 -0
  67. data/src/cc/varga/utils/URLHelper.as +52 -0
  68. data/src/cc/varga/utils/logging/Logger.as +94 -0
  69. data/src/com/automatastudios/audio/audiodecoder/AudioDecoder.as +84 -0
  70. data/src/com/automatastudios/audio/audiodecoder/decoders/AudioInfo.as +52 -0
  71. data/src/com/automatastudios/audio/audiodecoder/decoders/IDecoder.as +13 -0
  72. data/src/com/automatastudios/audio/audiodecoder/decoders/OggVorbisDecoder.as +221 -0
  73. data/src/com/automatastudios/audio/audiodecoder/decoders/WAVDecoder.as +325 -0
  74. data/src/com/automatastudios/audio/audiodecoder/events/AudioDecoderEvent.as +13 -0
  75. data/src/com/automatastudios/data/riff/RIFFChunkInfo.as +6 -0
  76. data/src/com/automatastudios/data/riff/RIFFParser.as +175 -0
  77. data/src/libs/appinf/appinf.json +0 -0
  78. data/src/libs/appinf/config.json +0 -0
  79. data/src/libs/appinf/sample.json +1 -0
  80. data/src/libs/appinf/server.json +0 -0
  81. data/src/nl/flexcoders/controls/YouTubePlayer.as +317 -0
  82. data/test/Test-app.xml +40 -0
  83. data/test/Test.mxml +35 -0
  84. data/views/jukebox.haml +30 -0
  85. metadata +157 -0
@@ -0,0 +1,52 @@
1
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2
+ //
3
+ //Authors: Franics Varga
4
+ //eMail: fv@varga-multimedia.com
5
+ //homepage: http://www.varga-multimedia.com
6
+ //
7
+ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8
+ //<a href='http://creativecommons.org/licenses/by-nc-sa/3.0/'>Creative Commons License<a\>
9
+ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
+ //
11
+ //You are free:
12
+ //
13
+ //to Share — to copy, distribute and transmit the work
14
+ //to Remix — to adapt the work
15
+ //Under the following conditions:
16
+ //
17
+ //Attribution — You must attribute the work in the manner specified by the author or licensor
18
+ //(but not in any way that suggests that they endorse you or your use of the work).
19
+ //
20
+ //Noncommercial — You may not use this work for commercial purposes.
21
+ //
22
+ //Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
23
+ //
24
+ //With the understanding that:
25
+ //
26
+ //Waiver — Any of the above conditions can be waived if you get permission from the copyright holder.
27
+ //Public Domain — Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license.
28
+ //Other Rights — In no way are any of the following rights affected by the license:
29
+ //
30
+ //Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations; The author's moral rights;
31
+ //
32
+ //Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights.
33
+ //Notice — For any reuse or distribution, you must make clear to others the license terms of this work.
34
+ //The best way to do this is with a link to this web page.
35
+ //
36
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
37
+ package cc.varga.utils
38
+ {
39
+ public class URLHelper
40
+ {
41
+ public function URLHelper()
42
+ {
43
+ }
44
+
45
+ public static function getFileURL(host:String, docID:String):String{
46
+ return host + "" + docID;
47
+ }
48
+
49
+ public function toString():String{ return "cc.varga.utils.logging.URLHelper"}
50
+ }
51
+
52
+ }
@@ -0,0 +1,94 @@
1
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2
+ //
3
+ //Authors: Franics Varga
4
+ //eMail: fv@varga-multimedia.com
5
+ //homepage: http://www.varga-multimedia.com
6
+ //
7
+ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8
+ //<a href='http://creativecommons.org/licenses/by-nc-sa/3.0/'>Creative Commons License<a\>
9
+ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
+ //
11
+ //You are free:
12
+ //
13
+ //to Share — to copy, distribute and transmit the work
14
+ //to Remix — to adapt the work
15
+ //Under the following conditions:
16
+ //
17
+ //Attribution — You must attribute the work in the manner specified by the author or licensor
18
+ //(but not in any way that suggests that they endorse you or your use of the work).
19
+ //
20
+ //Noncommercial — You may not use this work for commercial purposes.
21
+ //
22
+ //Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
23
+ //
24
+ //With the understanding that:
25
+ //
26
+ //Waiver — Any of the above conditions can be waived if you get permission from the copyright holder.
27
+ //Public Domain — Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license.
28
+ //Other Rights — In no way are any of the following rights affected by the license:
29
+ //
30
+ //Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations; The author's moral rights;
31
+ //
32
+ //Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights.
33
+ //Notice — For any reuse or distribution, you must make clear to others the license terms of this work.
34
+ //The best way to do this is with a link to this web page.
35
+ //
36
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
37
+ package cc.varga.utils.logging
38
+ {
39
+ // import flash.filesystem.File;
40
+ // import flash.filesystem.FileMode;
41
+ // import flash.filesystem.FileStream;
42
+ import cc.varga.mvc.ApplicationContext;
43
+
44
+ import flash.utils.getTimer;
45
+
46
+ public class Logger
47
+ {
48
+
49
+ private static var traceingStr : String = "";
50
+ //private static var tracingFile : File = new File(File.applicationDirectory.resolvePath("libs/logs/trace.log").toString());
51
+
52
+ private static var errorStr : String = "";
53
+ //private static var errorFile : File = new File(File.applicationDirectory.resolvePath("libs/logs/error.log").toString());
54
+
55
+ private static var debugStr : String = "";
56
+ //private static var debugFile : File = new File(File.applicationDirectory.resolvePath("libs/logs/debug.log").toString());
57
+
58
+ public function Logger(){}
59
+
60
+ public static function tracing(message:String, classpath : String):void{
61
+ traceingStr = "["+getTimer()+"].[TRACING].["+classpath+"] --> " + message;
62
+ trace(traceingStr);
63
+ (ApplicationContext.INSTANCE.contextView as FlexPlayer).debug.text += traceingStr + "\n";
64
+ //writeToFile(tracingFile, traceingStr);
65
+ }
66
+
67
+ public static function errorTracing(message:String, classpath : String):void{
68
+ errorStr = "["+getTimer()+"].[ERROR].["+classpath+"]--> " + message;
69
+ trace(errorStr);
70
+ (ApplicationContext.INSTANCE.contextView as FlexPlayer).debug.text += traceingStr + "\n";
71
+ //writeToFile(errorFile, errorStr);
72
+ }
73
+
74
+ public static function debugTracing(message:String, classpath : String):void{
75
+ debugStr= "["+getTimer()+"].[DEBUG].["+classpath+"]--> " + message;
76
+ trace(debugStr);
77
+ (ApplicationContext.INSTANCE.contextView as FlexPlayer).debug.text += traceingStr + "\n";
78
+ //writeToFile(debugFile, debugStr);
79
+ }
80
+
81
+ /*
82
+ private static function writeToFile(type:File, message:String):void{
83
+
84
+ var fileStream : FileStream = new FileStream();
85
+ fileStream.openAsync(type, FileMode.WRITE);
86
+ fileStream.writeUTFBytes(message);
87
+ fileStream.close();
88
+
89
+ }
90
+ */
91
+ public function toString():String{ return "cc.varga.utils.logging.Logger"}
92
+ }
93
+
94
+ }
@@ -0,0 +1,84 @@
1
+ package com.automatastudios.audio.audiodecoder {
2
+ import com.automatastudios.audio.audiodecoder.decoders.AudioInfo;
3
+ import com.automatastudios.audio.audiodecoder.decoders.IDecoder;
4
+
5
+ import flash.events.EventDispatcher;
6
+ import flash.events.Event;
7
+ import flash.events.IOErrorEvent;
8
+ import flash.events.ProgressEvent;
9
+ import flash.errors.EOFError;
10
+ import flash.net.URLStream;
11
+ import flash.utils.ByteArray;
12
+ import flash.utils.Endian;
13
+ import flash.utils.IDataInput;
14
+ import flash.media.Sound;
15
+ import flash.media.SoundChannel;
16
+ import flash.net.Socket;
17
+
18
+ public class AudioDecoder extends EventDispatcher {
19
+ private var _decoder:IDecoder;
20
+ private var _sound:Sound;
21
+ private var _soundChannel:SoundChannel;
22
+
23
+ public function AudioDecoder():void {
24
+ _sound = new Sound();
25
+ }
26
+
27
+ public function load(data:IDataInput, decoder:Class, bufferSize:uint = 1000, progressEventName:String = null):void {
28
+ if (progressEventName == null) {
29
+ if (data is URLStream) {
30
+ progressEventName = ProgressEvent.PROGRESS;
31
+ } else if (data is Socket) {
32
+ progressEventName = ProgressEvent.SOCKET_DATA;
33
+ }
34
+ }
35
+
36
+ _sound.addEventListener("sampleData", onSamplesRequest);
37
+
38
+ _decoder = (new decoder() as IDecoder);
39
+ _decoder.addEventListener(Event.INIT, onDecoderInit);
40
+ _decoder.addEventListener(Event.COMPLETE, onDecoderComplete);
41
+ _decoder.addEventListener(IOErrorEvent.IO_ERROR, onDecoderIOError);
42
+
43
+ _decoder.init(data, bufferSize, progressEventName);
44
+ }
45
+
46
+ public function play():SoundChannel {
47
+ _soundChannel = _sound.play();
48
+ return _soundChannel;
49
+ }
50
+
51
+ public function get sound():Sound {
52
+ return _sound;
53
+ }
54
+
55
+ public function get audioInfo():AudioInfo {
56
+ return _decoder.getAudioInfo();
57
+ }
58
+
59
+ public function getTotalTime():Number {
60
+ return _decoder.getTotalTime();
61
+ }
62
+
63
+ public function getPosition():Number {
64
+ return _decoder.getPosition();
65
+ }
66
+
67
+ private function onDecoderInit(event:Event):void {
68
+ dispatchEvent(event);
69
+ }
70
+
71
+ private function onDecoderComplete(event:Event):void {
72
+ dispatchEvent(event);
73
+ }
74
+
75
+ private function onDecoderIOError(event:IOErrorEvent):void {
76
+ dispatchEvent(event);
77
+ }
78
+
79
+ private function onSamplesRequest(event:*):void {
80
+ _decoder.getSamples(event.position, 4096, event.data);
81
+ }
82
+
83
+ }
84
+ }
@@ -0,0 +1,52 @@
1
+ package com.automatastudios.audio.audiodecoder.decoders {
2
+ public class AudioInfo {
3
+
4
+ public var decoder:String;
5
+ public var format:String;
6
+ public var channels:uint;
7
+ public var sampleRate:uint;
8
+ public var bitRateUpper:uint;
9
+ public var bitRateLower:uint;
10
+ public var bitRateNominal:uint;
11
+ public var blockAlign:uint;
12
+ public var bitsPerSample:uint;
13
+ public var sampleMultiplier:uint;
14
+ public var commentList:Array;
15
+ public var commentTable:Object;
16
+
17
+ public function AudioInfo():void {
18
+ commentList = new Array();
19
+ commentTable = new Object();
20
+ }
21
+
22
+ public function toString():String {
23
+ var result:String = "";
24
+ var i:uint;
25
+ var p:String;
26
+ var max:uint = commentList.length;
27
+
28
+ result += "decoder: " + decoder + "\n";
29
+ result += "format: " + format + "\n";
30
+ result += "channels: " + channels + "\n";
31
+ result += "sampleRate: " + sampleRate + "\n";
32
+ result += "bitRateUpper: " + bitRateUpper + "\n";
33
+ result += "bitRateLower: " + bitRateLower + "\n";
34
+ result += "bitRateNominal: " + bitRateNominal + "\n";
35
+ result += "blockAlign: " + blockAlign + "\n";
36
+ result += "bitsPerSample: " + bitsPerSample + "\n";
37
+ result += "sampleMultiplier: " + sampleMultiplier + "\n";
38
+
39
+ result += "commentList: \n";
40
+ for (i=0; i<max; ++i) {
41
+ result += "\t" + i + ": " + commentList[i] + "\n";
42
+ }
43
+
44
+ result += "commentTable: \n";
45
+ for (p in commentTable) {
46
+ result += "\t" + p + ": " + commentTable[p] + "\n";
47
+ }
48
+
49
+ return result;
50
+ }
51
+ }
52
+ }
@@ -0,0 +1,13 @@
1
+ package com.automatastudios.audio.audiodecoder.decoders {
2
+ import flash.events.IEventDispatcher;
3
+ import flash.utils.IDataInput;
4
+ import flash.utils.ByteArray;
5
+
6
+ public interface IDecoder extends IEventDispatcher {
7
+ function init(data:IDataInput, buffer:uint, progressEventName:String):void;
8
+ function getSamples(position:Number, numSamples:uint, sampleData:ByteArray):void;
9
+ function getAudioInfo():AudioInfo;
10
+ function getTotalTime():Number;
11
+ function getPosition():Number;
12
+ }
13
+ }
@@ -0,0 +1,221 @@
1
+ package com.automatastudios.audio.audiodecoder.decoders {
2
+ import cmodule.oggvorbis.CLibInit;
3
+
4
+ import flash.errors.EOFError;
5
+ import flash.events.EventDispatcher;
6
+ import flash.events.Event;
7
+ import flash.events.IOErrorEvent;
8
+ import flash.events.ProgressEvent;
9
+ import flash.errors.EOFError;
10
+ import flash.net.URLStream;
11
+ import flash.utils.ByteArray;
12
+ import flash.utils.Endian;
13
+ import flash.utils.IDataInput;
14
+
15
+ public class OggVorbisDecoder extends EventDispatcher implements IDecoder{
16
+ private static const READ_ERROR:int = -128;
17
+ private static const READ_NOT_VORBIS:int = -132;
18
+ private static const READ_VERSION:int = -134;
19
+ private static const READ_BAD_HEADER:int = -133;
20
+ private static const READ_FAULT:int = -129;
21
+
22
+ private static var decoder:*;
23
+ private var _rawData:IDataInput;
24
+ private var _data:ByteArray;
25
+ private var _bufferSize:uint;
26
+ private var _vorbisFileId:int;
27
+
28
+ private var _position:uint
29
+ private var _bytesTotal:uint;
30
+
31
+ private var _audioInfo:AudioInfo;
32
+ private var _convertMethod:Function;
33
+
34
+ private var _nextMethod:Function;
35
+
36
+ public function OggVorbisDecoder():void {
37
+ // do nothing, wait for init
38
+ }
39
+
40
+ public function init(data:IDataInput, bufferSize:uint, progressEventName:String):void {
41
+ var libInit:CLibInit;
42
+
43
+ _nextMethod = setupDecoder;
44
+
45
+ _rawData = data;
46
+ _data = new ByteArray();
47
+ _bufferSize = bufferSize;
48
+
49
+ if (decoder == null) {
50
+ libInit = new CLibInit();
51
+ decoder = libInit.init();
52
+ }
53
+
54
+
55
+ if (_rawData is ByteArray) {
56
+ _bytesTotal = (_rawData as ByteArray).length;
57
+ _data.length = _bytesTotal;
58
+ }
59
+
60
+ if (progressEventName != null) {
61
+ (data as EventDispatcher).addEventListener(progressEventName, onDataProgress);
62
+ } else {
63
+ _nextMethod();
64
+ }
65
+ }
66
+
67
+ public function getSamples(position:Number, numSamples:uint, sampleData:ByteArray):void {
68
+ var numBytes:uint = numSamples * _audioInfo.blockAlign / _audioInfo.sampleMultiplier;
69
+ var dataReadSize:int;
70
+ var sampleReadSize:int;
71
+ var rawSampleData:ByteArray = new ByteArray();
72
+ var i:uint;
73
+
74
+ rawSampleData.endian = Endian.LITTLE_ENDIAN;
75
+
76
+ dataReadSize = decoder.getSampleData(_vorbisFileId, numBytes, rawSampleData);
77
+
78
+ sampleReadSize = dataReadSize/_audioInfo.blockAlign;
79
+
80
+ if (dataReadSize == -1) {
81
+ dispatchEvent(new Event(Event.COMPLETE));
82
+ } else {
83
+ _position += dataReadSize;
84
+ rawSampleData.position = 0;
85
+
86
+ _convertMethod(sampleReadSize, rawSampleData, sampleData);
87
+ // pad with extra 0s as needed
88
+ for (i=sampleReadSize * _audioInfo.sampleMultiplier; i<numSamples; ++i) {
89
+ sampleData.writeFloat(0);
90
+ sampleData.writeFloat(0);
91
+ }
92
+ }
93
+ }
94
+
95
+ public function getAudioInfo():AudioInfo {
96
+ return _audioInfo;
97
+ }
98
+
99
+ public function getTotalTime():Number {
100
+ return decoder.getLength(_vorbisFileId);
101
+ }
102
+
103
+ public function getPosition():Number {
104
+ return decoder.getPosition(_vorbisFileId);
105
+ }
106
+
107
+ private function onDataProgress(event:ProgressEvent):void {
108
+ var size:uint
109
+
110
+ // need to move the data into a proper ByteArray
111
+ // FlaCC only works with ByteArrays at this timessss
112
+ _rawData.readBytes(_data, _data.length, _rawData.bytesAvailable);
113
+
114
+ _bytesTotal = event.bytesTotal;
115
+
116
+ _position += size;
117
+
118
+ if (_nextMethod != null) {
119
+ if (_bytesTotal > 0 && _data.bytesAvailable >= _bufferSize || _data.length == _bytesTotal) {
120
+
121
+ _nextMethod();
122
+ }
123
+ }
124
+ }
125
+
126
+ private function setupDecoder():void {
127
+ var result:int
128
+
129
+ result = decoder.setupDecoder(_data, _bytesTotal);
130
+
131
+ if (result > 0) {
132
+ _vorbisFileId = result;
133
+ _nextMethod = getHeaders;
134
+ _nextMethod();
135
+ } else {
136
+ _nextMethod = null;
137
+ dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR, false, false, "Bad audio format"));
138
+ }
139
+ }
140
+
141
+ private function getHeaders():void {
142
+ var infoObj:Object = decoder.getHeader(_vorbisFileId);
143
+ var p:String;
144
+ var i:uint;
145
+ var max:uint = infoObj.commentList.length;
146
+ var comment:String;
147
+ var equalIndex:int;
148
+
149
+ _audioInfo = new AudioInfo();
150
+ _audioInfo.decoder = "com.automatastudios.audio.audiodecoder.decoders.OggVorbisDecoder";
151
+ _audioInfo.format = "PCM";
152
+ _audioInfo.channels = infoObj.channels;
153
+ _audioInfo.sampleRate = infoObj.sampleRate;
154
+ _audioInfo.sampleMultiplier = 44100 / infoObj.sampleRate;
155
+ _audioInfo.bitRateUpper = infoObj.bitRateUpper;
156
+ _audioInfo.bitRateLower = infoObj.bitRateLower;
157
+ _audioInfo.bitRateNominal = infoObj.bitRateNominal;
158
+ _audioInfo.bitsPerSample = 16;
159
+
160
+ for (i=0; i<max; ++i) {
161
+ comment = infoObj.commentList[i];
162
+ _audioInfo.commentList.push(comment);
163
+
164
+ equalIndex = comment.indexOf("=");
165
+ if (equalIndex > -1) {
166
+ _audioInfo.commentTable[comment.substring(0, equalIndex)] = comment.substring(equalIndex + 1);
167
+ }
168
+ }
169
+
170
+ // hardcode 2 bytes-per-sample
171
+ _audioInfo.blockAlign = _audioInfo.channels * 2;
172
+
173
+ _nextMethod = null;
174
+
175
+ if (_audioInfo.sampleRate != 44100 && _audioInfo.sampleRate != 22050 && _audioInfo.sampleRate != 11025) {
176
+ dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR, false, false, "Bad sample rate"));
177
+ } else {
178
+
179
+ if (_audioInfo.channels == 1) {
180
+ _convertMethod = convertMono;
181
+ } else {
182
+ _convertMethod = convertStereo;
183
+ }
184
+
185
+ dispatchEvent(new Event(Event.INIT));
186
+ }
187
+ }
188
+
189
+ private function convertMono(numSamples:uint, inputData:ByteArray, outputData:ByteArray):void {
190
+ var i:uint;
191
+ var j:uint;
192
+ var sample:Number;
193
+
194
+ for (i=0; i<numSamples; ++i) {
195
+ sample = inputData.readShort() / 32767;
196
+ for (j=0; j< _audioInfo.sampleMultiplier; ++j) {
197
+ outputData.writeFloat(sample);
198
+ outputData.writeFloat(sample);
199
+ }
200
+ }
201
+ }
202
+
203
+ private function convertStereo(numSamples:uint, inputData:ByteArray, outputData:ByteArray):void {
204
+ var i:uint;
205
+ var j:uint;
206
+ var sample:Number;
207
+
208
+ for (i=0; i<numSamples; ++i) {
209
+ sample = inputData.readShort() / 32767;
210
+ for (j=0; j< _audioInfo.sampleMultiplier; ++j) {
211
+ outputData.writeFloat(sample);
212
+ }
213
+
214
+ sample = inputData.readShort() / 32767;
215
+ for (j=0; j< _audioInfo.sampleMultiplier; ++j) {
216
+ outputData.writeFloat(sample);
217
+ }
218
+ }
219
+ }
220
+ }
221
+ }