-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.as
119 lines (98 loc) · 2.71 KB
/
index.as
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
import mx.utils.Base64Encoder;
import mx.graphics.codec.JPEGEncoder;
// var doMain = stage.loaderInfo.url;
// var currSwfUrl = doMain.substring(0,doMain.lastIndexOf("/"));
// Security.loadPolicyFile(currSwfUrl + "/crossdomain.xml");
// Security.loadPolicyFile("http://stream.morecanai.com:1935/stage/crossdomain.xml");
var nc = null;
var ns = null;
var serverName;
var streamName;
var videoObj = new Video(800, 450);
videoObj.smoothing = true;
function info(value) {
try {
ExternalInterface.call("Ouzzplayer.status", value);
} catch (err) {
// empty
}
}
function createLiveStream() {
nc = new NetConnection();
nc.client = this;
nc.addEventListener(NetStatusEvent.NET_STATUS, function(event) {
info(event.info.code);
if (event.info.code == "NetConnection.Connect.Success") {
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, function(event) {
info(event.info.code);
});
var nsClientObj = new Object();
ns.client = nsClientObj;
ns.bufferTime = 1; // 3秒不会卡
ns.play(streamName);
videoObj.attachNetStream(ns);
addChild(videoObj);
}
});
nc.connect(serverName);
}
function destoryLiveStream() {
if (ns != null) {
ns.close();
ns = null;
}
if (nc != null) {
nc.close();
nc = null;
}
}
function startLive(server, stream) {
serverName = server;
streamName = stream;
destoryLiveStream();
createLiveStream();
}
function snapshot() {
try{
var imager = new BitmapData(800, 450, true, 0);
imager.draw(videoObj);
var e = new JPEGEncoder(100);
var actual_IMG = e.encode(imager);
var b64 = new Base64Encoder();
b64.encodeBytes(actual_IMG);
return b64.toString();
}catch(err) {
info(err)
}
}
function pause() {
if (ns != null) {
ns.pause();
}
}
function resume() {
if (ns != null) {
ns.resume();
}
}
function togglePause() {
if (ns != null) {
ns.togglePause();
}
}
try {
ExternalInterface.addCallback("startLive", startLive);
ExternalInterface.addCallback("stopLive", destoryLiveStream);
ExternalInterface.addCallback("snapshot", snapshot);
ExternalInterface.addCallback("pause", pause);
ExternalInterface.addCallback("resume", resume);
ExternalInterface.addCallback("togglePause", togglePause);
ExternalInterface.call("console.log", 'player is ok');
} catch (err) {
// empty
}
// startLive("rtmp://192.168.0.216:1935/", "vod");
// startLive("rtmp://cyberplayerplay.kayw ang.cn/cyberplayer/", "demo201711-L1");
// startLive("rtmp://stream.morecanai.com/stage/", "138424375820?morecantokenendtime=1564135106&morecantokenstarttime=1564134506&morecantokenhash=4cOHKVtkXE2pgGDX5Fco2BebtSKbDlOJyyGq60P6HC4=");
// setTimeout(snapshot, 4000);