public MainWindow() { try { this.WindowStartupLocation = WindowStartupLocation.CenterScreen; // FFMPEG 库路径不能为空。 PolyvPlayerSDK.MediaElement.FFmpegDirectory = @"./ffmpeg"; InitializeComponent(); DownLoadVideo = new DownLoadVideo(); NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(networkchanged); System.Windows.Threading.DispatcherTimer infoTimer = new System.Windows.Threading.DispatcherTimer(); infoTimer.Tick += (obj, e) => { string stayInVideoTime = Media.StayInVideoTime.ToString(@"hh\:mm\:ss"); string realPlayVideoTime = Media.RealPlayVideoTime.ToString(@"hh\:mm\:ss"); stayInVideoLbl.Content = stayInVideoTime; realPlayVideoLbl.Content = realPlayVideoTime; }; infoTimer.Interval = new TimeSpan(0, 0, 1); infoTimer.Start(); //播放初始化账号信息,不能为空 VIDTextBox.Text = ""; //VIDTextBox.Text = ""; string userId = ""; string secretkey = ""; string readToken = ""; //初始化必要参数,播放和下载均需要初始化 DownLoadVideo.initAccountInfo(userId, secretkey, readToken); Media.initAccountInfo(userId, secretkey, readToken); PolyvPlayerSDK.MediaElement.FFmpegMessageLogged += OnMediaFFmpegMessageLogged; //初始化观看者信息,观看者的ip,不能为空 string viewerIp = ""; string viewerId = ""; string viewerName = ""; Media.initPlayerInfo(viewerIp, viewerId, viewerName); Media.MessageLogged += OnMediaMessageLogged; Media.MediaOpened += (ms, me) => { int time = Convert.ToInt32(Media.NaturalDuration.TimeSpan.TotalSeconds); string timestr = string.Format("{0:00}:{1:00}:{2:00}", time / 3600, time / 60, time % 60); durationLbl.Content = timestr; }; Media.MediaOpening += Media_MediaOpening; Media.MediaOpened += Media_MediaOpened; Media.MediaFailed += Media_MediaFailed; Media.MediaEnded += MediaEndedEvent; Media.SeekingEnded += Media_SeekingEnded; Media.BufferingStarted += MediaBufferingStartEvent; Media.BufferingEnded += MediaBufferingEndEvent; // DownLoadVideo.OnDownloadCompleted += DownloadCompletedEvent; DownLoadVideo.OnDownloadProgress += DownloadProgressEvent; DownLoadVideo.OnDeleteInfo += DeleteInfoEvent; IList <BitRate> customList = new List <BitRate>(); customList.Add(new BitRate() { ID = 1, Name = "标清" }); customList.Add(new BitRate() { ID = 2, Name = "高清" }); customList.Add(new BitRate() { ID = 3, Name = "超清" }); comboBox.ItemsSource = customList; comboBox.DisplayMemberPath = "Name"; comboBox.SelectedValuePath = "ID"; comboBox.SelectedValue = 1; // 初始化跑马灯 String content = "保利威视频点播"; Single fontSize = 14; Color fontColor = Color.SkyBlue; Media.InitScrollText(content, fontSize, fontColor); Media.StartDrawScrollText(); } catch (Exception ex) { System.Diagnostics.Debug.Print(ex.Message); } }
public void DownloadProgressEvent(string videoId, long receiveBytes, long totalBytes, DownLoadVideo obj) //public void DownloadProgressEvent(string videoId, long receiveBytes, long totalBytes) { try { this.Dispatcher.Invoke(new Action(() => { tipsLabel.Content = "已下载" + ((receiveBytes * 100) / totalBytes).ToString() + "%"; })); } catch (Exception ex) { } }