AxisCommunications / locomote-video-player

Media Player in Adobe Flash with RTSP support. (THIS PROJECT IS NO LONGER MAINTAINED)
BSD 3-Clause "New" or "Revised" License
133 stars 79 forks source link

stopped playing every 135 secs, why??? #145

Closed xinlingyun2015 closed 4 years ago

xinlingyun2015 commented 9 years ago

Hi, I am playing a rtsp stream within a local network, and it stopped playing for every 135s (or so), the bcTimerHandler function is called, why???

xinlingyun2015 commented 9 years ago

It turns out that the rtsp server need a heart beat, otherwise the server automatically disconnected the connection. So I add a heart beat of GET_PARAMETERS rtsp request, and the problem solved. After that, this locomote player works great! Thanks to the author again!

noseglid commented 9 years ago

Glad you got it to work. I think that would be a nice feature to have in Locomote. Would you mind sharing your code?

xinlingyun2015 commented 9 years ago

Sure. It is a very simple, all in RTSPClient.as. Just add the following timer:

private var heartBeatTimer:Timer; heartBeatTimer = new Timer(10*1000); heartBeatTimer.addEventListener(TimerEvent.TIMER, heartBeatTick);

private function heartBeatTick(e:TimerEvent):void { try{ sendHeartBeatReq(); }catch (ex:Error) { trace(ex.message + ex.getStackTrace()); } } private function sendHeartBeatReq():void { var command:String = "GET_PARAMETER"; if (!this.supportCommand(command)) { command = "PLAY"; } var req:String = command + " " + getControlURL() + " RTSP/1.0\r\n" + "CSeq: " + (++cSeq) + "\r\n" + "User-Agent: " + userAgent + "\r\n" + "Session: " + session + "\r\n" + auth.authorizationHeader("GET_PARAMETER", authState, authOpts, urlParsed, digestNC++) + "\r\n"; Logger.log('RTSP OUT:', req); if (handle != null) { handle.writeUTFBytes(req); } }

Then, at the end of RTSTClient.start(), start the timer: heartBeatTimer.start();

That's all. Have a good day!