Skip to content

Instantly share code, notes, and snippets.

@shvyrev
Created June 16, 2014 07:10
Show Gist options
  • Save shvyrev/eaf6c9c03d82e2877a41 to your computer and use it in GitHub Desktop.
Save shvyrev/eaf6c9c03d82e2877a41 to your computer and use it in GitHub Desktop.
/**
* Created by s.shvyrev on 23.05.2014.
*/
package com.comdi.kraken.player.utils.environment_test {
import com.comdi.kraken.player.utils.environment_test.event.EnvironmentTestErrorEvent;
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.events.TimerEvent;
import flash.net.NetStream;
import flash.utils.Timer;
import org.osmf.media.MediaPlayer;
public class NetStreamWatcher extends EventDispatcher {
private var _netStream:NetStream;
private var _traceLoader:TraceNetLoader;
private var _timer:Timer = new Timer(1000);
private var _minBitrate:int;
private var _player:MediaPlayer;
public function NetStreamWatcher(target:IEventDispatcher = null) {
_timer.addEventListener(TimerEvent.TIMER, handler_timer);
_timer.start();
super(target);
}
private function handler_timer(event:TimerEvent):void {
if(!_netStream)
return;
if(_minBitrate < _netStream.info.maxBytesPerSecond){
dispatchEvent(new EnvironmentTestErrorEvent(EnvironmentTestErrorEvent.BANDWIDTH_ERROR, "Low bit rate: " + _netStream.info.maxBytesPerSecond, true, false));
}
}
public function get traceLoader():TraceNetLoader {
_traceLoader = null;
_traceLoader = new TraceNetLoader();
_traceLoader.onNetStream = getNetStream;
return _traceLoader;
}
public function set netStream(value:NetStream):void {
_netStream = value;
}
private function getNetStream(value:NetStream):void {
log("getNetStream", value);
_netStream = value;
}
public function get minBitrate():int {
return _minBitrate;
}
public function set minBitrate(value:int):void {
_minBitrate = value;
}
public function set player(value:MediaPlayer):void {
_player = value;
}
}
}
@donotfeedaslender
Copy link

 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment