GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: the flash recorder for chirrp, written with haXe
Homepage: http://chirrp.net/
Clone URL: git://github.com/why/chirrup.git
commit  5c056792207413245e7ab9acefe44a7688cd6f53
tree    774c7aa9f637e378358bb11803ea44671ba15885
parent  d7120a4ff128b4b337a2d886d41e0132a74a9fdb
chirrup / Rec.hx
100644 229 lines (194 sloc) 5.25 kb
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
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.external.ExternalInterface;
import flash.net.NetStream;
import flash.text.TextField;
import flash.text.TextFormat;
import haxe.Timer;
 
class RecOffPng extends BitmapData {}
class RecOnPng extends BitmapData {}
class RecHoverPng extends BitmapData {}
class PlayUpPng extends BitmapData {}
class PlayDownPng extends BitmapData {}
 
class Rec extends Base {
 
  static var recButton : SimpleButton;
  static var stopButton : SimpleButton;
  static var playButton : SimpleButton;
  static var countdown : TextField;
  static var countfont : TextFormat;
  static var countclip : MovieClip;
  static var soundsgood : MovieClip;
 
  static var tokenExp : EReg = ~/^200 token (\w+)$/;
 
  static var uuid : String;
  static var user : String;
  static var url : String;
  static var clock : Timer;
  static var start : Float = 0;
  static var used : Float = 0;
 
  static function timeRecording() {
    if (Base.elapsedTime() > 0) {
      if (start == 0) {
        start = Timer.stamp();
      }
 
      used = (Timer.stamp() - start);
      countdown.text = "" + Std.int(Base.seconds - used);
      countdown.setTextFormat(countfont);
      if (used >= Base.seconds) {
        stopRecording(null);
        clock.stop();
      }
    }
  }
 
  static function startRecording(e) {
    stopButton.visible = true;
    recButton.visible = false;
    Base.record(uuid + ".flv", function(ns) {
      start = 0;
      clock = new Timer(200);
      clock.run = timeRecording;
    });
  }
 
  static function playRecording(e) {
    Base.play(uuid + ".flv");
  }
 
  static function reRecord(e) {
    recButton.visible = true;
    stopButton.visible = false;
    playButton.visible = false;
    countdown.text = "8";
    countdown.setTextFormat(countfont);
    countclip.visible = true;
    soundsgood.visible = false;
  }
 
  static function publish(e) {
    soundsgood.visible = false;
    var r = new haxe.Http(Base.server + "/publish?id=" + uuid + "&user=" + user + "&timing=" + Std.int(used * 1000));
    r.onData = function(r)
    {
      if (tokenExp.match(r))
      {
        var token = tokenExp.matched(1);
        ExternalInterface.call("finishChirrp", token);
      }
    };
    r.request(false);
  }
 
  static function stopRecording(e) {
    Base.stop();
    clock.stop();
    stopButton.visible = false;
    playButton.visible = true;
    countclip.visible = false;
    soundsgood.visible = true;
  }
 
  static function main() {
    uuid = Base.random(32);
    user = flash.Lib.current.loaderInfo.parameters.user;
 
    //
    // Record button
    //
    var rec_off = new RecOffPng(0, 0);
    var rec_hit = new MovieClip();
    rec_hit.graphics.beginFill(0);
    Base.drawCircle(rec_hit, 54, 54, 36);
 
    recButton =
      Base.addBitmapButton(
        rec_off,
        new RecHoverPng(0, 0),
        rec_hit,
        startRecording
      );
 
    recButton.x = 40;
    recButton.y = 10;
 
    //
    // Stop button
    //
    var stop_on = new RecOnPng(0, 0);
 
    stopButton =
      Base.addBitmapButton(
        stop_on,
        stop_on,
        rec_hit,
        stopRecording
      );
 
    stopButton.visible = false;
    stopButton.x = 40;
    stopButton.y = 10;
 
    //
    // Play button
    //
    var play_up = new PlayUpPng(0, 0);
    var play_down = new PlayDownPng(0, 0);
 
    playButton =
      Base.addBitmapButton(
        play_up,
        play_down,
        rec_hit,
        playRecording
      );
 
    playButton.visible = false;
    playButton.x = 40;
    playButton.y = 10;
 
    //
    // Countdown instrument
    //
    countfont = new TextFormat();
    countfont.font = "Verdana";
    countfont.size = 72;
    countfont.bold = true;
    countfont.color = 0;
 
    var mcmed = new TextFormat();
    mcmed.font = "Verdana";
    mcmed.size = 14;
    mcmed.bold = true;
    mcmed.color = 0;
 
    countclip = new MovieClip();
    var mct = new TextField();
    mct.text = "You have";
    mct.setTextFormat(mcmed);
    countclip.addChild(mct);
 
    countdown = new TextField();
    countdown.text = "8";
    countdown.setTextFormat(countfont);
    countclip.addChild(countdown);
    countdown.x = 10;
    countdown.y = 4;
    flash.Lib.current.addChild(countclip);
 
    var mct2 = new TextField();
    mct2.text = "seconds";
    mct2.setTextFormat(mcmed);
    mct2.x = 3;
    mct2.y = 72;
    countclip.addChild(mct2);
 
    countclip.x = 220;
    countclip.y = 20;
 
    //
    // Sounds good?
    //
    var med = new TextFormat();
    med.font = "Verdana";
    med.size = 25;
    med.bold = true;
    med.color = 0;
 
    var soundstxt = new TextField();
    soundstxt.text = "Sounds good?";
    soundstxt.width = 250;
    soundstxt.height = 50;
    soundstxt.setTextFormat(med);
 
    var okLink = Base.addLink("OK, I'm all done!", publish);
    var noLink = Base.addLink("Nah, record it again.", reRecord);
 
    soundsgood = new MovieClip();
    soundsgood.addChild(soundstxt);
    soundsgood.addChild(okLink);
    soundsgood.addChild(noLink);
 
    okLink.x = 30;
    okLink.y = 40;
    noLink.x = 20;
    noLink.y = 62;
 
    flash.Lib.current.addChild(soundsgood);
    soundsgood.visible = false;
    soundsgood.x = 170;
    soundsgood.y = 20;
  }
}