Flash Media Server Stream: Content Protection
I need to implement flash streams to restart our video on demand system, but either because I haven't worked with flash related systems before, or because I'm too stupid, I can't get the system to work the way it should ...
We need:
- Control of access to files and users with verification in the WebService every minute
- if the lease time has ended with an average stream: cancel the stream
- rtmp streaming
- dynamic bandwidth check
- Video playback with Flowplayer (existing license)
I have a streaming and bandwidth checker working, I just can't get the access control to work. I have no idea how I know which file is being played or how can I play the file depending on the key sent by the client.
Server side code (main.asc):
application.onAppStart = function()
{
trace("Starting application");
this.payload = new Array();
for (var i=0; i < 1200; i++) {
this.payload[i] = Math.random(); //16K approx
}
}
application.onConnect = function( p_client, p_autoSenseBW )
{
p_client.writeAccess = "";
trace("client at : " + p_client.uri);
trace("client from : " + p_client.referrer);
trace("client page: " + p_client.pageUrl);
// try to get something from the query string: works
var i = 0;
for (i = 0; i < p_client.uri.length; ++i)
{
if (p_client.uri[i] == '?')
{
++i;
break;
}
}
var loadVars = new LoadVars();
loadVars.decode(p_client.uri.substr(i));
trace(loadVars.toString());
trace(loadVars['foo']);
// And accept the connection
this.acceptConnection(p_client);
trace("accepted!");
//this.rejectConnection(p_client);
// A connection from Flash 8 & 9 FLV Playback component based client
// requires the following code.
if (p_autoSenseBW)
{
p_client.checkBandwidth();
}
else
{
p_client.call("onBWDone");
}
trace("Done connecting");
}
application.onDisconnect = function(client)
{
trace("client disconnecting!");
}
Client.prototype.getStreamLength = function(p_streamName) {
trace("getStreamLength:" + p_streamName);
return Stream.length(p_streamName);
}
Client.prototype.checkBandwidth = function() {
application.calculateClientBw(this);
}
application.calculateClientBw = function(p_client)
{
/* lots of lines copied from an adobe sample, appear to work */
}
Client code:
<head>
<script type="text/javascript" src="flowplayer-3.1.4.min.js"></script>
</head>
<body>
<a
class="rtmp"
href="rtmp://xx.xx.xx.xx/vod_project/test_flv.flv"
style="display: block; width: 520px; height: 330px"
id="player">
</a>
<script>
$f(
"player",
"flowplayer-3.1.5.swf",
{
clip: {
provider: 'rtmp',
autoPlay: false,
url: 'test_flv'
},
plugins: {
rtmp: {
url: 'flowplayer.rtmp-3.1.3.swf',
netConnectionUrl: 'rtmp://xx.xx.xx.xx/vod_project?foo=bar'
}
}
}
);
</script>
</body>
My first idea was to get the key from the query string, ask the web service what file and user this key is and play the file, but I can't figure out how to play the file from the server side.
My second idea was to let the player play the file, pass the key as a query string, and if the filename and key don't match, then reject the connection, but I can't find which file it is currently playing.
The only remaining idea I have is to create a list of all the files the user can open and set allowReadAccess or still it was called to allow those files, but that would be clunky due to the current infrastructure.
Any hints?
Thanks.
a source to share
I found FlowPlayers clip.connectionArgs today and I am currently implementing a solution.
the resulting code will look like this:
Server side main.asc onConnect:
application.onConnect( p_client, p_userid, p_streamname )
{
if (p_client.check_access(p_userid, p_streamname))
{
p_client.readAccess = "streams/_definst_/" + p_streamname;
this.acceptConnection(p_client);
}
else
{
this.rejectConnection(p_client);
}
}
Client side:
$f(
"player",
"flowplayer-3.1.5.swf",
{
clip: {
provider: 'rtmp',
autoPlay: false,
url: 'test_flv',
connectionArgs: ["12345", "test_flv"]
},
plugins: {
rtmp: {
url: 'flowplayer.rtmp-3.1.3.swf',
netConnectionUrl: 'rtmp://xx.xx.xx.xx/vod_project?foo=bar'
}
}
}
);
a source to share