private void PlayerBtn_Click(object sender, EventArgs e)
        {
            var isPlay = (sender as Button).Text == "播放";

            if (isPlay)
            {
                string RTSPStreamURI = this.StreamURI.Text;// "rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov";
                channelID = PlayerSdk.EasyPlayer_OpenStream(RTSPStreamURI, this.panel1.Handle, RENDER_FORMAT, isTCP ? 1 : 0, "", "", callBack, IntPtr.Zero, isHardEncode);
                if (channelID > 0)
                {
                    PlayerSdk.EasyPlayer_SetFrameCache(channelID, 3);
                    this.PlayerBtn.Text     = "停止";
                    this.DecodeType.Enabled = false;
                }
            }
            else
            {
                int ret = PlayerSdk.EasyPlayer_CloseStream(channelID);
                if (ret == 0)
                {
                    this.PlayerBtn.Text     = "播放";
                    this.DecodeType.Enabled = true;
                    channelID = -1;
                    this.panel1.Refresh();
                }
            }
        }
        /// <summary>
        /// 视频缓冲区设置.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void CacheFream_ValueChanged(object sender, EventArgs e)
        {
            if (channelID <= 0)
            {
                return;
            }

            var cache = (sender as TrackBar).Value;
            int ret   = PlayerSdk.EasyPlayer_SetFrameCache(channelID, cache);
        }
Beispiel #3
0
        private void UserControl1_Load(object sender, EventArgs e)
        {
            //HwndSource hs = (HwndSource)PresentationSource.FromDependencyObject(asd);
            //IntPtr ip = hs.Handle;
            PlayerSdk.EPInit();
            int channelID = PlayerSdk.EasyPlayer_OpenStream("rtsp://*****:*****@172.16.21.80:554/h264/ch1/main/av_stream", panel1.Handle, PlayerSdk.RENDER_FORMAT.DISPLAY_FORMAT_RGB24_GDI, 1, "admin", "itc123456", PlayerSdk.EPcallBack, IntPtr.Zero, false);

            if (channelID > 0)
            {
                PlayerSdk.EasyPlayer_SetFrameCache(channelID, 3);
            }
        }
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            PlayerSdk.EPInit();
            //IntPtr hwnd = ((HwndSource)PresentationSource.FromVisual(VideoPictureBox)).Handle;
            HwndSource hs1 = (HwndSource)PresentationSource.FromDependencyObject(gg1);
            HwndSource hs2 = (HwndSource)PresentationSource.FromDependencyObject(gg2);
            IntPtr     ip  = hs2.Handle;
            //IntPtr ip1 = hs1.Handle;
            int channelID = PlayerSdk.EasyPlayer_OpenStream("rtsp://172.16.21.209:554/1", VideoPictureBox.Handle, PlayerSdk.RENDER_FORMAT.DISPLAY_FORMAT_RGB24_GDI, 1, "", "", PlayerSdk.EPcallBack, IntPtr.Zero, false);

            if (channelID > 0)
            {
                PlayerSdk.EasyPlayer_SetFrameCache(channelID, 3);
            }
        }
Beispiel #5
0
        public async Task <bool> Play(bool showErrors, bool doPing = true, string customAdr = "")
        {
            try {
                if (MainForm.m.lite && settings.isMainPlayer)
                {
                    settings.channelID = 1;
                    return(false);
                }

                if (InvokeRequired)
                {
                    Invoke((MethodInvoker) delegate {
                        Play(showErrors, doPing);
                    });
                    return(false);
                }

                string fullAdr = customAdr;
                if (fullAdr == "")
                {
                    fullAdr = settings.GetCombined();
                }

                Uri combinedUrl = ConfirmAdr(showErrors, fullAdr, doPing);
                if (combinedUrl == null)
                {
                    return(false);
                }

                Console.WriteLine("playing " + combinedUrl.ToString());

                if (IsPlaying())
                {
                    StopPlaying();
                }

                settings.channelID = PlayerSdk.EasyPlayer_OpenStream(combinedUrl.ToString(),
                                                                     p_Player.Handle, PlayerSdk.RENDER_FORMAT.DISPLAY_FORMAT_RGB24_GDI,
                                                                     1, "", "", null, IntPtr.Zero, false);

                if (IsPlaying())
                {
                    PlayerSdk.EasyPlayer_SetFrameCache(settings.channelID, 3);
                }
                else
                {
                    if (showErrors)
                    {
                        MessageBox.Show("Failed to attach to channel!");
                    }

                    Console.WriteLine("FAILED TO ATTACH");
                    StopPlaying();
                }
            } catch (Exception e) {
                if (showErrors)
                {
                    Tools.ShowPopup("Failed to init player stream!\nShow more?", "Error Occurred!", e.ToString());
                }
                Console.WriteLine("PLAY " + e.ToString());
                StopPlaying();
                return(false);
            }

            return(IsPlaying());
        }
        /// <summary>
        /// 开始播放rtsp
        /// </summary>
        public void startPlay()
        {
            try
            {
                //todo 要去掉
                //Thread.Sleep(100);
                logger.Info("将要播放编号[" + messageModel.memberNo + "]的图像,rtsp地址是:" + messageModel.videoData.rtspUrl);

                if (!"start".Equals(messageModel.videoMessageType))
                {
                    return;
                }

                string rtspPath = messageModel.videoData.rtspUrl;
                if (null == rtspPath || "".Equals(rtspPath))
                {
                    logger.Info("将要播放编号[" + messageModel.memberNo + "]的图像,但是没有rtsp地址");
                    return;
                }

                channelId = PlayerSdk.EasyPlayer_OpenStream(rtspPath, rtspPanel.Handle, PlayerSdk.RENDER_FORMAT.DISPLAY_FORMAT_RGB24_GDI, 1, "", "", mainForm.callBack, IntPtr.Zero, mainForm.isHardEncode);
                logger.Info("播放的图像的channelID:" + channelId);
                if (channelId > 0)
                {
                    videoPlayStatus = true;

                    PlayerSdk.EasyPlayer_SetFrameCache(channelId, 3);
                    int  ret;
                    bool covered = null == messageModel.videoData.covered ? true : (bool)messageModel.videoData.covered;
                    if (covered)
                    {
                        ret = PlayerSdk.EasyPlayer_SetShownToScale(channelId, 0);
                    }
                    else
                    {
                        ret = PlayerSdk.EasyPlayer_SetShownToScale(channelId, 1);
                    }
                    logger.Info("关闭其它窗口音频");
                    mainForm.resetAllVolumeStatus();
                    logger.Info("打开当前窗口音频图标");
                    changeVolumeStatus(true);
                    //int retStartAudio = PlayerSdk.EasyPlayer_PlaySound(channelId);//播放音频
                    //logger.Info("播放音频状态:" + retStartAudio);
                    //if (retStartAudio == 0)
                    //{
                    //    //关闭其它窗口音频
                    //    logger.Info("关闭其它窗口音频");
                    //    mainForm.resetAllVolumeStatus();
                    //    logger.Info("打开当前窗口音频图标");
                    //    changeVolumeStatus(true);
                    //}
                }
                else //拉流失败
                {
                    logger.Info("拉流失败");
                    channelId = 0;
                    mainForm.tcpServerService.notifyErrMsg(messageModel.memberNo, "播放错误!");
                }
            }
            catch (Exception e)
            {
                logger.Error("", e);
            }
        }