bool Reload(double time) { Stream m = null; int i = 0; try { for (i = 0; i < times.Count; i++) { if (times[i] >= time) { m = this.CreateStream(); m.Position = kfs[i] - 4; newFrame = true; break; } } } catch (Exception e) { m = null; } if (m != null) { VideoCache.Clear(); AudioCache.Clear(); var dm = MainStream; if (dm != null) { Task.Run(async() => { await Task.Delay(1000); dm.Dispose(); }); } MainStream = m;; Debug.WriteLine(time + "==> TIMER:" + times[i] + " KFS:{0}({0:X})", kfs[i]); } if (!running) { running = true; Debug.WriteLine("==running:true=="); Task.Run(async() => { try { while (true) { if (VideoCache.Count > 1024 || AudioCache.Count > 1024) { await Task.Delay(500); //Debug.WriteLine("@@@ WAIT:RUNNING:" + VideoCache.Count + "|" + AudioCache.Count + " @@@"); continue; }/* * if (MainStream != m && MainStream != null) { * m = MainStream; * Debug.WriteLine("==running:update=="); * }*/ if (!this.readPreviousTag(MainStream)) { break; } } Debug.WriteLine("==running:false=="); Debug.WriteLine("END:" + MainStream.Position + "/" + MainStream.Length); running = false; } catch (Exception ERR) { Debug.WriteLine("==running:catch=="); running = false; await Task.Delay(3000); Debug.WriteLine(ERR); Reload(time); //throw; } }); } return(m != null); }
bool Reload(double time) { Stream m = null; try { for (int i = 0; i < times.Count; i++) { if (times[i] >= time) { m = this.CreateStream(); //Debug.WriteLine("====Reload:"+i+"=====:" ); Debug.WriteLine(time + "==> TIMER:" + times[i] + " KFS:{0}({0:X})", kfs[i]); m.Position = kfs[i] - 4; VideoCache.Clear(); AudioCache.Clear(); break; } } } catch (Exception e) { m = null; Debug.WriteLine(e); } if (m == null) { return(false); } else { MainStream = m; } if (!running) { running = true; Debug.WriteLine("==running:true=="); Task.Run(async() => { try { while (true) { if (VideoCache.Count > 1024 || AudioCache.Count > 1024) { await Task.Delay(500); //Debug.WriteLine("@@@ WAIT:RUNNING:" + VideoCache.Count + "|" + AudioCache.Count + " @@@"); continue; } if (!this.readPreviousTag(MainStream)) { break; } } Debug.WriteLine("==running:false=="); running = false; } catch (Exception ERR) { Debug.WriteLine("==running:false=="); running = false; Debug.WriteLine(ERR); Reload(time + 5); //throw; } }); } return(true); }