Monday, November 27, 2006
Thursday, November 16, 2006
Sunday, November 05, 2006
Wednesday, November 01, 2006
Thursday, September 28, 2006
Detecting user bandwidth with ActionScript
I've always wondered how to code my flash files to detect a user bandwidth. Well I've found it. The tools you need are Flash Communication Server 2 and Flash 8 and some experience with coding. The process is quite simple and logical considering if you are delivering content to the public and have to compensate for users with different connection speeds; bandwidths.
Here's the code -
1 nc = new NetConnection();
2 nc.onStatus = function(info) {
3 trace("Level: "+info.level+" Code: "+info.code);
4 if (info.code == "NetConnection.Connect.Success") {
5 trace("--- connected to: " + this.uri);
6 initStream();
7 }
8 };
9 nc.connect("rtmp:/videoplayer");
10
11 initStream = function(){
12 // create a NetStream
13 video_ns = new NetStream(nc);
14 // optional onStatus handler
15 video_ns.onStatus = function(info) {
16 trace("Level: " + info.level + " Code: " + info.code);
17 };
18 // attach the NetStream to a video object called videoObj on stage
19 videoObj.attachVideo(video_ns);
20 video_ns.play("100kbps_Stream", 0); // the parameter 0 will tell the server to play a recorded stream
21 }
22 stop();
Add the following to the frame in Flash 8 -
1 nc = new NetConnection();
2 nc.onStatus = function(info) {
3 trace("Level: " + info.level + " Code: " + info.code);
4 if (info.code == "NetConnection.Connect.Success") {
5 trace("--- connected to: " + this.uri);
7 }
8 };
9 NetConnection.prototype.onBWDone = function(p_bw) {
10 trace("onBWDone: "+p_bw);
11 }
12 NetConnection.prototype.onBWCheck = function() {
13 return ++counter; // Serverside, just ignore any return value and return the call count
14 }
15 nc.connect("rtmp:/bwcheck", true);
16 stop();
Now, in your FLA file add the following -
detected_bw = p_bw;
// close the NetConnection to bwcheck
this.close();
gotoAndStop(2);
To request the appropriate stream -
if(detected_bw >= 256){
useVideo = "256kbps_Stream";
bufferlength = 2;
} else if (detected_bw <256 && detected_bw >=100){ useVideo = "100kbps_Stream"; bufferlength = 3; } else { // bandwidth is too low, you best alert the user at this stage trace("bandwidth too low"); }
trace("bandwidth too low");
}
For the onStatus handler -
video_ns.onStatus = function(info) {
trace("Level: " + info.level + " Code: " + info.code);
};
dd this code to set the bufferlength:
video_ns.setBufferTime(bufferlength);
Also modify the play action by changing that line from this:
video_ns.play("100kbps_Stream", 0);
to this:
video_ns.play(useVideo, 0);
I will like to thank Stefan Richter and Adobe for the help.
Here's the code -
1 nc = new NetConnection();
2 nc.onStatus = function(info) {
3 trace("Level: "+info.level+" Code: "+info.code);
4 if (info.code == "NetConnection.Connect.Success") {
5 trace("--- connected to: " + this.uri);
6 initStream();
7 }
8 };
9 nc.connect("rtmp:/videoplayer");
10
11 initStream = function(){
12 // create a NetStream
13 video_ns = new NetStream(nc);
14 // optional onStatus handler
15 video_ns.onStatus = function(info) {
16 trace("Level: " + info.level + " Code: " + info.code);
17 };
18 // attach the NetStream to a video object called videoObj on stage
19 videoObj.attachVideo(video_ns);
20 video_ns.play("100kbps_Stream", 0); // the parameter 0 will tell the server to play a recorded stream
21 }
22 stop();
Add the following to the frame in Flash 8 -
1 nc = new NetConnection();
2 nc.onStatus = function(info) {
3 trace("Level: " + info.level + " Code: " + info.code);
4 if (info.code == "NetConnection.Connect.Success") {
5 trace("--- connected to: " + this.uri);
7 }
8 };
9 NetConnection.prototype.onBWDone = function(p_bw) {
10 trace("onBWDone: "+p_bw);
11 }
12 NetConnection.prototype.onBWCheck = function() {
13 return ++counter; // Serverside, just ignore any return value and return the call count
14 }
15 nc.connect("rtmp:/bwcheck", true);
16 stop();
Now, in your FLA file add the following -
detected_bw = p_bw;
// close the NetConnection to bwcheck
this.close();
gotoAndStop(2);
To request the appropriate stream -
if(detected_bw >= 256){
useVideo = "256kbps_Stream";
bufferlength = 2;
} else if (detected_bw <256 && detected_bw >=100){ useVideo = "100kbps_Stream"; bufferlength = 3; } else { // bandwidth is too low, you best alert the user at this stage trace("bandwidth too low"); }
trace("bandwidth too low");
}
For the onStatus handler -
video_ns.onStatus = function(info) {
trace("Level: " + info.level + " Code: " + info.code);
};
dd this code to set the bufferlength:
video_ns.setBufferTime(bufferlength);
Also modify the play action by changing that line from this:
video_ns.play("100kbps_Stream", 0);
to this:
video_ns.play(useVideo, 0);
I will like to thank Stefan Richter and Adobe for the help.
Saturday, July 22, 2006
CA Master State Championships 2006
Wednesday, June 21, 2006
Monday, June 12, 2006
Zaino day - polishing my baby.
Monday, June 05, 2006
Information Security - My opinion from this past weekend.
This past weekend I presented at the Marriott near LAX to a group of administrators, concerned parents and teachers from the Los Angeles Unified School District. The presentation was titled 'Privacy Protection: What You and Your Students Should Know' and from the positive feedback I received and interest in the information as a whole, I feel confident that information sharing on a topic is beneficial to computer beginners to the savvy user who can whip through online.
Presentation notes will be made available soon to interested users.
Presentation notes will be made available soon to interested users.
Subscribe to:
Posts (Atom)















