-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ouzhou
committed
Jul 18, 2019
1 parent
90e3642
commit b69273c
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
flex_sdk_4.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |