-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathWebcam.hx
60 lines (56 loc) · 2.69 KB
/
Webcam.hx
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
/* ************************************************************************ */
/* */
/* haXe Video */
/* Copyright (c)2007 Nicolas Cannasse */
/* Copyright (c)2011 af83 */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* Lesser General Public License or the LICENSE file for more details. */
/* */
/* ************************************************************************ */
class Webcam {
var nc : flash.net.NetConnection;
var ns : flash.net.NetStream;
var cam : flash.media.Camera;
var mic : flash.media.Microphone;
var file : String;
var share : String;
public function new(host, file,?share, token, width, height, fps) {
this.file = file;
this.share = share;
this.cam = flash.media.Camera.getCamera();
if( this.cam == null )
throw "Webcam not found";
this.cam.setMode(width, height, fps, true);
this.mic = flash.media.Microphone.getMicrophone();
this.nc = new flash.net.NetConnection();
this.nc.addEventListener(flash.events.NetStatusEvent.NET_STATUS,onEvent);
this.nc.connect(host, token);
}
public function getCam() {
return this.cam;
}
function onEvent(e) {
if( e.info.code == "NetConnection.Connect.Success" ) {
this.ns = new flash.net.NetStream(nc);
this.ns.addEventListener(flash.events.NetStatusEvent.NET_STATUS, onEvent);
this.ns.publish(this.file,this.share);
} else if (e.info.code == "NetStream.Publish.Start") {
this.ns.attachCamera(this.cam);
this.ns.attachAudio(this.mic);
//this.ns.bufferTime = 1;
}
}
public function doStop() {
if( this.ns != null )
this.ns.close();
this.nc.close();
}
}