/// <summary> /// 获取本地存储的信号文件列表 /// </summary> /// <returns></returns> public static List<MusicInfo> GetLocalMusicList() { if (!currentISF.DirectoryExists("Musics")) { currentISF.CreateDirectory("Musics"); } string[] paths = currentISF.GetFileNames("Musics/*.sgn"); LocalMusicInfos = new List<MusicInfo>(paths.Length); IsolatedStorageFileStream isfs = null; StreamReader sr = null; MusicInfo mi = null; foreach (string p in paths) { using (isfs = new IsolatedStorageFileStream("Musics/" + p, FileMode.Open, FileAccess.Read, currentISF)) { using (sr = new StreamReader(isfs)) { try { mi = new MusicInfo(); mi.MusicName = sr.ReadLine();//name mi.IsDefault = sr.ReadLine().Equals("0") ? false : true;//IsDefault mi.Key = sr.ReadLine();//key mi.MusicLengthMill = int.Parse(sr.ReadLine());//musicLengthMill mi.Speed = int.Parse(sr.ReadLine());//speed mi.MusicData = sr.ReadLine();//data LocalMusicInfos.Add(mi); } catch (Exception) { sr.Close(); isfs.Close(); currentISF.DeleteFile("Musics/" + p); } sr.Close(); } isfs.Close(); } } return LocalMusicInfos; }
/// <summary> /// 删除本地存储的sgn文件和音乐文件 /// </summary> /// <param name="mi"></param> /// <returns></returns> public static bool DeleteLocalSignAndMusic(MusicInfo mi) { currentISF.DeleteFile("Musics/" + mi.Key + "_Sign.sgn"); currentISF.DeleteFile("Musics/" + mi.Key); return true; }
/// <summary> /// 加载一个歌曲数据并解析 /// </summary> /// <param name="sc"></param> private void Load(MusicInfo mi) { speed = mi.Speed; //计算到敲击点延迟 CalcDelayOffset(); //解析实体类 string[] datas = mi.MusicData.Split(','); CadenceSigns = new CadenceSign[datas.Length]; string temp = string.Empty; int delaytime = 0; int ttime = 0; int i = 0; foreach (string t in datas) { temp = t.Substring(0, 2); ttime = int.Parse(t.Substring(3, t.Length - 3)); delaytime += ttime; CadenceSign cs = new CadenceSign(); cs.drumType = CommHelper.DrumTypeToKeyCode(temp); cs.DelayTimeMill = delaytime; //图像 Image img = new Image(); if (cs.drumType == DrumType.FaceAll) { img.Width = 45; img.Height = 45; img.Source = ResourceMgr.SignimgBgCache[1]; } else if (cs.drumType == DrumType.SideAll) { img.Width = 45; img.Height = 45; img.Source = ResourceMgr.SignimgBgCache[3]; } else if (cs.drumType == DrumType.RightFace || cs.drumType == DrumType.LeftFace) { img.Width = 35; img.Height = 35; img.Source = ResourceMgr.SignimgBgCache[0]; } else { img.Width = 35; img.Height = 35; img.Source = ResourceMgr.SignimgBgCache[2]; } //img.Visibility = System.Windows.Visibility.Collapsed; //TranslateTransform ttf = new TranslateTransform(); //ttf.X = 0; ttf.Y = 0; //img.RenderTransform = new TranslateTransform(); img.RenderTransform = null; img.Effect = null; img.CacheMode = new BitmapCache(); if (cs.drumType == DrumType.RightFace || cs.drumType == DrumType.LeftFace || cs.drumType == DrumType.RightSide || cs.drumType == DrumType.LeftSide) { Canvas.SetLeft(img, signLeftLocation); Canvas.SetTop(img, 33); } else { Canvas.SetLeft(img, signLeftLocation); Canvas.SetTop(img, 28); } cs.currentSign = img; CadenceSigns[i] = cs; i++; } //添入显示控件 foreach (CadenceSign cs in CadenceSigns) { LayoutRoot.Children.Add(cs.currentSign); } AddLastBecloud(); firstlongTime = CadenceSigns[0].DelayTimeMill; signCount = CadenceSigns.Length; }
/// <summary> /// 播放解析后的信号 /// </summary> public void Play(MusicInfo mi) { if (isStart) return; if (CadenceSigns == null || CadenceSigns.Length <= 0) { Load(mi); } ///Res/Musics/xiaji.wma //meMusic.Stop(); meMusic.AutoPlay = false; if (mi.IsDefault) { meMusic.Source = new Uri(CommHelper.MusicBasePath + mi.Key, UriKind.Relative); } else { meMusic.SetSource(CommHelper.GetMusicStream(mi.Key)); } //主线程界面刷新器 dtWindows.Interval = new TimeSpan(0, 0, 0, 0, 10); dtWindows.Tick += new EventHandler(dtWindows_Tick); dtWindows.Start(); //辅助线程 logicThread = new Timer(dtWindows_Tick_BG, null, 0, 500); isStart = true; }
/// <summary> /// 读取音乐资源 /// </summary> private void ReadMusicXML() { Stream s = Application.GetResourceStream(new Uri("Res/MusicList.xml", UriKind.Relative)).Stream; XmlReader xr = XmlReader.Create(s); //xr.ReadToNextSibling("/Musics/Music"); while (xr.Read()) { XmlNodeType xnt = xr.NodeType; if (xr.LocalName.Equals("Music")) { MusicInfo mi = new MusicInfo(); for (int i = 0; i < xr.AttributeCount; i++) { xr.MoveToAttribute(i); if (xr.Name.Equals("Name", StringComparison.CurrentCultureIgnoreCase)) { mi.MusicName = xr.Value; } else if (xr.Name.Equals("Length", StringComparison.CurrentCultureIgnoreCase)) { mi.MusicLengthMill = xr.ReadContentAsInt(); } else if (xr.Name.Equals("Data", StringComparison.CurrentCultureIgnoreCase)) { mi.MusicData = xr.Value; } else if (xr.Name.Equals("Key", StringComparison.CurrentCultureIgnoreCase)) { mi.Key = xr.Value; } else if (xr.Name.Equals("Speed", StringComparison.CurrentCultureIgnoreCase)) { mi.Speed = xr.ReadContentAsInt(); } } MusicInfos.Add(mi); } } }
/// <summary> /// 删除本地存储的sgn文件和音乐文件 /// </summary> /// <param name="mi"></param> /// <returns></returns> public static bool DeleteLocalSignAndMusic(MusicInfo mi) { currentISF.DeleteFile("Musics/" + mi.Key + "_Sign.sgn"); currentISF.DeleteFile("Musics/" + mi.Key); return(true); }