public void GetVideoSource(VideoDefinition definition, VideoInfo info) { if (definition == null || string.IsNullOrEmpty(definition.url) || currentDefinitionUrl == definition.url) { return; } currentDefinitionUrl = definition.url; CurrentDefinitionName = definition.name; System.Diagnostics.Debug.WriteLine("获取播放源:" + definition.url); HttpHelper.httpGet(definition.url, (ar) => { App.HideLoading(); string result = HttpHelper.SyncResultTostring(ar); if (result != null) { ResourceInfo videosResult = null; try { videosResult = JsonConvert.DeserializeObject <ResourceInfo>(result); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("LoadChannelCompleted json 解析错误" + ex.Message); App.JsonError(result); } if (videosResult == null) { JsonError(result); } else if (videosResult.status == "ok" && videosResult.info != null) { if (CallbackManager.currentPage != null) { CallbackManager.currentPage.Dispatcher.BeginInvoke(() => { MediaSource = new Uri(videosResult.info, UriKind.RelativeOrAbsolute); App.MainViewModel.AddRememberVideo(info); CurrentDefinitionName = definition.name; // VideoDownloadUrl = info.downloadUrl; System.Diagnostics.Debug.WriteLine("视频地址 : " + videosResult.info); }); } } } //else //{ // App.ShowToast("获取视频数据失败,请检查网络或重试"); //} }); }
private void DefinitionChange(object sender, System.Windows.Input.GestureEventArgs e) { TextBlock textBlock = sender as TextBlock; VideoDefinition definition = textBlock.DataContext as VideoDefinition; if (definition != null) { App.PlayerModel.CurrentDefinitionName = definition.name; App.PlayerModel.IsChangeDefinition = true; leaveSilderValue = pbVideo.Value; App.PlayerModel.GetVideoSource(definition, App.PlayerModel.currentVideo); } DefinitionList.Visibility = System.Windows.Visibility.Collapsed; }
private void PlayerM3U8Video(List <VideoDefinition> listVideos) { if (listVideos.Count == 0) { return; } isM3U8Video = true; int downIndex = 0; for (int i = 0; i < listVideos.Count; i++) { if (listVideos[i].name == "高清") { downIndex = i; break; } } VideoDefinition Definition = listVideos[downIndex]; GetM3U8VideoSource(Definition, currentVideo); }
/*private void cm_ContactFound(object sender, ContactFoundEventArgs e) * { * if (e.ContactFound != null) * { * Contact.Text = e.ContactFound.DisplayName; * if (e.PhoneLabel != null) * { * Number.Text = e.PhoneLabel + " : " + e.PhoneNumber; * } * else * { * Number.Text = e.PhoneNumber; * } * } * }*/ private void timerTick(Object sender, Object e) { Call call = ((InCallModel)this.DataContext).GetCurrentCall(); if (call == null) { return; } //startTime = (DateTimeOffset)call.CallStartTimeFromContext; TimeSpan callDuration = new TimeSpan(call.Duration * TimeSpan.TicksPerSecond); var hh = callDuration.Hours; var ss = callDuration.Seconds; var mm = callDuration.Minutes; Status.Text = hh.ToString("00") + ":" + mm.ToString("00") + ":" + ss.ToString("00"); string audioPayloadType = ""; string audioDownloadBandwidth = ""; string audioUploadBandwidth = ""; string videoPayloadType = ""; string videoDownloadBandwidth = ""; string videoUploadBandwidth = ""; CallParams param = call.CurrentParams; ((InCallModel)this.DataContext).MediaEncryption = param.MediaEncryption.ToString(); CallStats audioStats = null; try { audioStats = call.GetStats(StreamType.Audio); } catch { } if (audioStats != null) { audioDownloadBandwidth = String.Format("{0:0.00}", audioStats.DownloadBandwidth); audioUploadBandwidth = String.Format("{0:0.00}", audioStats.UploadBandwidth); ((InCallModel)this.DataContext).ICE = audioStats.IceState.ToString(); } PayloadType audiopt = param.UsedAudioPayloadType; if (audiopt != null) { audioPayloadType = audiopt.MimeType + "/" + audiopt.ClockRate; } if (param.VideoEnabled) { CallStats videoStats = call.GetStats(StreamType.Video); if (videoStats != null) { videoDownloadBandwidth = String.Format("{0:0.00}", videoStats.DownloadBandwidth); videoUploadBandwidth = String.Format("{0:0.00}", videoStats.UploadBandwidth); } PayloadType videopt = param.UsedVideoPayloadType; if (videopt != null) { videoPayloadType = videopt.MimeType; } VideoDefinition receivedVideoSize = param.ReceivedVideoDefinition; String NewReceivedVideoSize = String.Format("{0}x{1}", receivedVideoSize.Width, receivedVideoSize.Height); String OldReceivedVideoSize = ((InCallModel)this.DataContext).ReceivedVideoSize; if (OldReceivedVideoSize != NewReceivedVideoSize) { ((InCallModel)this.DataContext).ReceivedVideoSize = String.Format("{0}x{1}", receivedVideoSize.Width, receivedVideoSize.Height); ((InCallModel)this.DataContext).IsVideoActive = false; if (NewReceivedVideoSize != "0x0") { ((InCallModel)this.DataContext).IsVideoActive = true; } } VideoDefinition sentVideoSize = param.SentVideoDefinition; ((InCallModel)this.DataContext).SentVideoSize = String.Format("{0}x{1}", sentVideoSize.Width, sentVideoSize.Height); ((InCallModel)this.DataContext).VideoStatsVisibility = Visibility.Visible; } else { ((InCallModel)this.DataContext).VideoStatsVisibility = Visibility.Collapsed; } string downloadBandwidth = audioDownloadBandwidth; if ((downloadBandwidth != "") && (videoDownloadBandwidth != "")) { downloadBandwidth += " - "; } if (videoDownloadBandwidth != "") { downloadBandwidth += videoDownloadBandwidth; } ((InCallModel)this.DataContext).DownBandwidth = String.Format("{0} kb/s", downloadBandwidth); string uploadBandwidth = audioUploadBandwidth; if ((uploadBandwidth != "") && (videoUploadBandwidth != "")) { uploadBandwidth += " - "; } if (videoUploadBandwidth != "") { uploadBandwidth += videoUploadBandwidth; } ((InCallModel)this.DataContext).UpBandwidth = String.Format("{0} kb/s", uploadBandwidth); string payloadType = audioPayloadType; if ((payloadType != "") && (videoPayloadType != "")) { payloadType += " - "; } if (videoPayloadType != "") { payloadType += videoPayloadType; } ((InCallModel)this.DataContext).PayloadType = payloadType; }
public static bool IsHD(VideoDefinition def) => def == VideoDefinition.High1080p || def == VideoDefinition.High1080i || def == VideoDefinition.High720p;
public void PlayerVideo(VideoInfo info) { currentVideo = info; //设置多媒体控件的网络视频资源 if (info.downloadUrl.Count > 0) { App.PlayerModel.PayVisibility = Visibility.Collapsed; App.PlayerModel.LoadVisibility = Visibility.Visible; int downIndex = 0; for (int i = 0; i < info.downloadUrl.Count; i++) { if (info.downloadUrl[i].name == "高清") { downIndex = i; break; } } VideoDefinition Definition = info.downloadUrl[downIndex]; GetVideoSource(Definition, info); } else { //尝试获取数据源 string playSourceUrl = CommonData.GetVideoResourceUrl + "&videoId=" + info.videoId; System.Diagnostics.Debug.WriteLine("获取播放源2:" + playSourceUrl); HttpHelper.httpGet(playSourceUrl, (ar) => { string result = HttpHelper.SyncResultTostring(ar); if (result != null) { VideoDetailResult videosDetailResult = null; try { videosDetailResult = JsonConvert.DeserializeObject <VideoDetailResult>(result); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("LoadChannelCompleted json 解析错误" + ex.Message); App.JsonError(result); } if (videosDetailResult == null) { JsonError(result); } else if (videosDetailResult != null && videosDetailResult.err_code == HttpHelper.rightCode && videosDetailResult.data != null && videosDetailResult.data.detail != null) { if (CallbackManager.currentPage != null) { CallbackManager.currentPage.Dispatcher.BeginInvoke(() => { //todo App.HideLoading(); LoadVisibility = Visibility.Collapsed; ErrMsg = "格式不支持"; PayVisibility = Visibility.Visible; //info.downloadUrl = videosDetailResult.data.downloadUrl; //info.downloadUrl = videosDetailResult.data.videoSources; //PlayerM3U8Video(videosDetailResult.data.videoSources); }); } } else { if (CallbackManager.currentPage != null) { CallbackManager.currentPage.Dispatcher.BeginInvoke(() => { App.HideLoading(); LoadVisibility = Visibility.Collapsed; ErrMsg = videosDetailResult.err_msg; PayVisibility = Visibility.Visible; }); } } } else { if (CallbackManager.currentPage != null) { CallbackManager.currentPage.Dispatcher.BeginInvoke(() => { App.HideLoading(); LoadVisibility = Visibility.Collapsed; // App.ShowToast("获取数据失败,请检查网络或重试"); }); } } }); } }