private void InitPlayer(string videoUri, NetworkCredential account, Size size = default(Size)) { hostedPlayer = new HostedPlayer(); playerDisposables.Add(hostedPlayer); if (size != default(Size)) { videoBuffer = new VideoBuffer(size.Width, size.Height, PixFrmt.bgra32); } else { videoBuffer = new VideoBuffer(720, 576, PixFrmt.bgra32); } hostedPlayer.SetVideoBuffer(videoBuffer); MediaStreamInfo.Transport transport = MediaStreamInfo.Transport.Tcp; MediaStreamInfo streamInfo = null; if (account != null) { streamInfo = new MediaStreamInfo(videoUri, transport, new UserNameToken(account.UserName, account.Password)); } else { streamInfo = new MediaStreamInfo(videoUri, transport); } playerDisposables.Add( hostedPlayer.Play(streamInfo, this) ); InitPlayback(videoBuffer, true); }
public void InitPlayer(string videoUri, NetworkCredential account, Size sz = default(Size)) { player = new HostedPlayer(); playerDisposables.Add(player); if (sz != default(Size)) { videoBuff = new VideoBuffer((int)sz.Width, (int)sz.Height, PixFrmt.bgra32); } else { videoBuff = new VideoBuffer(720, 576, PixFrmt.bgra32); } player.SetVideoBuffer(videoBuff); MediaStreamInfo.Transport transp = MediaStreamInfo.Transport.Udp; MediaStreamInfo mstrInfo = null; if (account != null) { mstrInfo = new MediaStreamInfo(videoUri, transp, new UserNameToken(account.UserName, account.Password));//, transp, null); } else { mstrInfo = new MediaStreamInfo(videoUri, transp); } playerDisposables.Add( player.Play(mstrInfo, this) ); InitPlayback(videoBuff, true); //{ // playing controls // btnPause.Click += play; // btnResume.Click += play; //} }
private void InitializePlayer(string videoUri, NetworkCredential account, Size size = default(Size)) { OnConnect(this, null); dispatcher = Dispatcher.CurrentDispatcher; player = new HostedPlayer(); disposables.Add(player); if (size != default(Size)) { buffer = new VideoBuffer(size.Width, size.Height, PixFrmt.bgra32); } else { buffer = new VideoBuffer(720, 576, PixFrmt.bgra32); } player.SetVideoBuffer(buffer); MediaStreamInfo.Transport transport = MediaStreamInfo.Transport.Tcp; MediaStreamInfo streamInfo = null; if (account != null) { streamInfo = new MediaStreamInfo(videoUri, transport, new UserNameToken(account.UserName, account.Password)); } else { streamInfo = new MediaStreamInfo(videoUri, transport); } disposables.Add(player.Play(streamInfo, this)); TimeSpan renderInterval; try { int fps = 30; fps = (fps <= 0 || fps > 100) ? 100 : fps; renderInterval = TimeSpan.FromMilliseconds(1000 / fps); } catch { renderInterval = TimeSpan.FromMilliseconds(1000 / 30); } var cancellationTokenSource = new CancellationTokenSource(); disposables.Add(Disposable.Create(() => { cancellationTokenSource.Cancel(); })); var cancellationToken = cancellationTokenSource.Token; var renderingTask = Task.Factory.StartNew(() => { using (buffer.Lock()) { try { while (!cancellationToken.IsCancellationRequested) { using (var processingEvent = new ManualResetEventSlim(false)) { var dispOp = dispatcher.BeginInvoke(() => { using (Disposable.Create(() => processingEvent.Set())) { if (!cancellationToken.IsCancellationRequested) { DrawFrame(buffer); } } }); processingEvent.Wait(cancellationToken); } cancellationToken.WaitHandle.WaitOne(renderInterval); } } catch (OperationCanceledException) { //swallow exception } catch (Exception e) { } finally { } } }, cancellationToken); }