public Music(Wz_Sound sound) { this.soundData = sound.ExtractSound(); this.pData = GCHandle.Alloc(this.soundData, GCHandleType.Pinned); this.hStream = Bass.CreateStream(pData.AddrOfPinnedObject(), 0, this.soundData.Length, BassFlags.Default); Music.GlobalVolumeChanged += this.OnGlobalVolumeChanged; }
public Music(Wz_Sound sound) { this.soundData = sound.ExtractSound(); this.pData = GCHandle.Alloc(this.soundData, GCHandleType.Pinned); this.hStream = Bass.BASS_StreamCreateFile(pData.AddrOfPinnedObject(), 0, this.soundData.Length, BASSFlag.BASS_DEFAULT); Music.GlobalVolumeChanged += this.OnGlobalVolumeChanged; }
public Music(Wz_Sound sound) { this.soundData = sound.ExtractSound(); mp3Reader = new Mp3FileReader(new MemoryStream(soundData)); waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()); waveOut.Init(mp3Reader); waveOut.PlaybackStopped += (src, e) => { if (IsLoop) { try { mp3Reader.Position = 0; waveOut.Play(); } catch (Exception) { // When ended for destruction } } }; Music.GlobalVolumeChanged += this.OnGlobalVolumeChanged; }
/// <summary> /// 比较两个节点绑定的值是否相同。 /// </summary> /// <param Name="dataNew">新的值。</param> /// <param Name="dataOld">旧的值。</param> /// <returns></returns> public virtual bool CompareData(object dataNew, object dataOld) { // skip virtual dir { if (dataNew is Wz_File fileNew && fileNew.IsSubDir) { dataNew = null; } if (dataOld is Wz_File fileOld && fileOld.IsSubDir) { dataNew = null; } } if (dataNew == null && dataOld == null) { return(true); } if (dataNew == null ^ dataOld == null) { return(false); } Type type = dataNew.GetType(); if (type != dataOld.GetType()) { return(false); } if (type.IsClass) { switch (dataNew) { case string str: return(str == (string)dataOld); case Wz_Image img: Wz_Image imgOld = (Wz_Image)dataOld; return(img.Size == imgOld.Size && img.Checksum == imgOld.Checksum); case Wz_File file: Wz_File fileOld = (Wz_File)dataOld; return(file.Type == fileOld.Type); case Wz_Png png: Wz_Png pngOld = (Wz_Png)dataOld; switch (this.PngComparison) { case WzPngComparison.SizeOnly: return(png.Width == pngOld.Width && png.Height == pngOld.Height); case WzPngComparison.SizeAndDataLength: return(png.Width == pngOld.Width && png.Height == pngOld.Height && png.DataLength == pngOld.DataLength); case WzPngComparison.Pixel: if (!(png.Width == pngOld.Width && png.Height == pngOld.Height && png.Form == pngOld.Form)) { return(false); } byte[] pixelNew = png.GetRawData(); byte[] pixelOld = pngOld.GetRawData(); if (pixelNew == null || pixelOld == null || pixelNew.Length != pixelOld.Length) { return(false); } for (int i = 0, i1 = pixelNew.Length; i < i1; i++) { if (pixelNew[i] != pixelOld[i]) { return(false); } } return(true); default: goto case WzPngComparison.SizeAndDataLength; } break; case Wz_Vector vector: Wz_Vector vectorOld = (Wz_Vector)dataOld; return(vector.X == vectorOld.X && vector.Y == vectorOld.Y); case Wz_Uol uol: return(uol.Uol == ((Wz_Uol)dataOld).Uol); case Wz_Sound sound: Wz_Sound soundOld = (Wz_Sound)dataOld; return(sound.Ms == soundOld.Ms && sound.DataLength == soundOld.DataLength); } } return(object.Equals(dataNew, dataOld)); }