/// <summary> /// 媒体文件转换为VM /// </summary> /// <param name="itemlist"></param> /// <returns></returns> public void ViewModelParse(AMS_PlayListMd5Model playlist) { _id = playlist.Id; _Number = playlist.PlayListNo; _SubmitDate = playlist.ReleaseDate; _BeginDate = playlist.EffectDate; _EndDate = playlist.EndDate; _BeginTime = DateTime.Parse(playlist.PlayVideoItems[0].PlayTime); _ItemList.Clear(); for (int i = 0; i < playlist.PlayVideoItems.Count; i++) { PlaylistItemViewModel itemvm = new PlaylistItemViewModel(); itemvm.Name = playlist.PlayVideoItems[i].Name; itemvm.FilePath = playlist.PlayVideoItems[i].RelativeUrl; itemvm.Md5Value = playlist.PlayVideoItems[i].md5value; if (i + 1 >= playlist.PlayVideoItems.Count) { itemvm.SunTime = playlist.PlayElapsed; } else { itemvm.SunTime = int.Parse((DateTime.Parse(playlist.PlayVideoItems[i + 1].PlayTime) - DateTime.Parse(playlist.PlayVideoItems[i].PlayTime)).TotalSeconds.ToString().Split('.')[0]); } _ItemList.Add(itemvm); } }
/// <summary> /// 循环添加媒体文件 /// </summary> public bool LoopMedia() { try { if (_ItemList.Count < 1) { throw new Exception("媒体文件不能为空!"); } if (_LoopTime < 1) { throw new Exception("信息填写错误!请仔细检查!"); } else { foreach (PlaylistItemViewModel item in _ItemList) { if (item.SunTime < 1) { throw new Exception("请填入有效的播放时长!"); } } int loopsetime = _LoopTime * 60; bool flish = false; while (!flish) { foreach (PlaylistItemViewModel item in _ItemList) { if (loopsetime < 0) { flish = true; break; } else { loopsetime = loopsetime - item.SunTime; } PlaylistItemViewModel loopitme = new PlaylistItemViewModel(); loopitme.FilePath = item.FilePath; loopitme.Name = item.Name; loopitme.SunTime = item.SunTime; loopitme.Md5Value = item.Md5Value; _LoopList.Add(loopitme); } } return(true); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); return(false); } }