Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
ouzhou committed Jul 18, 2019
1 parent 90e3642 commit b69273c
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flex_sdk_4.6
94 changes: 94 additions & 0 deletions index.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// 文档参考
// https://www.cnblogs.com/savageworld/archive/2006/07/28/462434.html
// https://www.oschina.net/uploads/doc/flex-doc-3.2/flash/net/NetStream.html

import mx.utils.Base64Encoder;
import mx.graphics.codec.JPEGEncoder;

var nc = null;
var ns = null;
var serverName;
var streamName;

var console = {
info: function(value) {
ExternalInterface.call("console.info", value);
},
log: function(value) {
ExternalInterface.call("console.log", value);
},
error: function(value) {
ExternalInterface.call("console.error", value);
}
};

function createLiveStream() {
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, function(event) {
console.info("nc: " + event.info.code);
if (event.info.code == "NetConnection.Connect.Success") {
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, function(event) {
console.info("ns: " + event.info.code);
});
var nsClientObj = new Object();
ns.client = nsClientObj;
ns.bufferTime = 3; // 3秒不会卡
ns.play(streamName);
videoObj.attachNetStream(ns);
}
});
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 shot() {
var matrix:Matrix = new Matrix();
matrix.scale(5, 4);

var imager = new BitmapData(800, 450, true, 0);
imager.draw(videoObj, matrix);



var e = new JPEGEncoder(100);
var actual_IMG = e.encode(imager);

var b64 = new Base64Encoder();
b64.encodeBytes(actual_IMG);
// Ouzzplayer
ExternalInterface.call("Ouzzplayer.shot", b64.toString());

}

// TODO
// function pause() {}

startLive("rtmp://cyberplayerplay.kaywang.cn/cyberplayer/", "demo201711-L1");

try {
ExternalInterface.addCallback("startLive", startLive);
ExternalInterface.addCallback("stopLive", destoryLiveStream);
ExternalInterface.addCallback("shot", shot);
} catch (err) {
console.error(err);
}
Binary file added index.fla
Binary file not shown.
53 changes: 53 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<head>
<title>index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
html,
body {
height: 100%;
}
body {
margin: 0;
padding: 0;
overflow: hidden;
}
#flashContent {
width: 800px;
height: 450px;
}
</style>
</head>
<body>
<div id="flashContent">
<object
type="application/x-shockwave-flash"
data="index.swf"
width="100%"
height="100%"
id="app"
bgcolor="#000000"
>
<param name="allowfullscreen" value="true" /><param
name="allowscriptaccess"
value="always"
/><param name="wmode" value="opaque" /><param
name="menu"
value="false"
/>
</object>
</div>

<script>
var Ouzzplayer = {
shot: function(str) {
var bs64 = `data:image/jpeg;base64,${str}`;
console.log(bs64);
// window.open(bs64);
}
};
const app = document.getElementById("app");
</script>
</body>
</html>
Binary file added index.swf
Binary file not shown.

0 comments on commit b69273c

Please sign in to comment.