Ejemplo n.º 1
0
        public static void FadeTracks(string group, Mp3Info mp3, Dictionary <string, Mp3Info> buttonMp3s, double volume)
        {
            if (group.GetGroupName() == nameof(Group.Background))
            {
                var activePlayer = buttonMp3s.FirstOrDefault(x => x.Value != null && x.Value.IsActive && x.Value.Group == Group.Background).Value?.MP;

                if (mp3.MP == null)
                {
                    mp3.MP = new MediaPlayer();
                }
                mp3.MP.Open(new Uri(mp3.Path));

                if (activePlayer != null)
                {
                    mp3.MP.Volume = 0;
                    int fadeTimeInSeconds = 5;

                    Timer t = new Timer();
                    t.Interval = 1000;
                    t.Tick    += new EventHandler((s, ea) => fadeTimeInSeconds = HandleTick(activePlayer, mp3.MP, fadeTimeInSeconds, volume, s));
                    mp3.MP.Play();
                    t.Start();
                }
                else
                {
                    mp3.MP.Volume = volume / 10;
                    mp3.MP.Play();
                }
            }
            else
            {
                mp3.MP.Volume = volume / 10;
                mp3.MP.Play();
            }
        }
Ejemplo n.º 2
0
        public static void SaveSettings(Dictionary <string, Mp3Info> buttonMp3s, string preferredPath = null)
        {
            var mp3ToSave = new Dictionary <string, Mp3Info>();

            PreferredPath = preferredPath;

            foreach (KeyValuePair <string, Mp3Info> mp3 in buttonMp3s)
            {
                if (mp3.Value != null)
                {
                    Mp3Info mp = new Mp3Info(mp3.Value.Path, mp3.Value.Group, mp3.Value.Name);
                    mp.MP = null;

                    mp3ToSave.Add(mp3.Key, mp);
                }
            }

            var saveObject = new SaveInfo {
                Mp3Info       = mp3ToSave,
                PreferredPath = string.IsNullOrWhiteSpace(preferredPath) ? PreferredPath : preferredPath
            };

            var saved = JsonConvert.SerializeObject(saveObject);

            File.WriteAllText("Soundboardsettings.txt", saved);
        }
Ejemplo n.º 3
0
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            var mp3info = new Mp3Info();
            var mp3Moder = new Mp3Modifications();
            foreach (var file in _fileList)
            {
                mp3info.SetTagsFromName(file);

                if (CheckToGetNameFromTag.IsChecked.Value)
                {
                    try
                    {
                       mp3Moder.GetNamesFromTags(file);
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show(exp.Message.ToString(), "There was a error");
                    }
                }
                if (CheckToTranslit.IsChecked.Value)
                {
                    try
                    {
                        mp3Moder.ChangeNamesToTranslit(file);
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show(exp.Message.ToString(), "There was a error");
                    }
                }
            }
        }
Ejemplo n.º 4
0
		public virtual int sceMp3LowLevelInit(int id, int unknown)
		{
			Mp3Info mp3Info = getMp3Info(id);
			// Always output in stereo, even if the input is mono
			mp3Info.Codec.init(0, 2, 2, 0);

			return 0;
		}
Ejemplo n.º 5
0
		public virtual int sceMp3GetMaxOutputSample(int id)
		{
			Mp3Info mp3Info = getMp3Info(id);
			//if (log.DebugEnabled)
			{
				Console.WriteLine(string.Format("sceMp3GetMaxOutputSample returning 0x{0:X}", mp3Info.MaxSamples));
			}
			return mp3Info.MaxSamples;
		}
Ejemplo n.º 6
0
		public virtual int sceMp3GetSamplingRate(int id)
		{
			Mp3Info mp3Info = getMp3Info(id);
			//if (log.DebugEnabled)
			{
				Console.WriteLine(string.Format("sceMp3GetSamplingRate returning 0x{0:X}", mp3Info.SampleRate));
			}
			return mp3Info.SampleRate;
		}
Ejemplo n.º 7
0
 /// <summary>
 /// This method is called when the USB storage device is mounted.
 /// </summary>
 /// <param name="sender">The object that raised the event.</param>
 /// <param name="e">The event arguments.</param>
 private static void RemovableMedia_Insert(object sender, MediaEventArgs e)
 {
     volInfo = e.Volume;
     Mp3Info.SaveInfo();
     foreach (Connection connection in WT32.Connections.Values)
     {
         SendTracks(connection, true);
     }
 }
Ejemplo n.º 8
0
		public override void start()
		{
			ids = new Mp3Info[2];
			for (int i = 0; i < ids.Length; i++)
			{
				ids[i] = new Mp3Info(i);
			}

			base.start();
		}
Ejemplo n.º 9
0
		public virtual int sceMp3Init(int id)
		{
			Mp3Info mp3Info = getMp3Info(id);
			mp3Info.init();
			if (log.InfoEnabled)
			{
				Console.WriteLine(string.Format("Initializing Mp3 data: channels={0:D}, samplerate={1:D}kHz, bitrate={2:D}kbps.", mp3Info.ChannelNum, mp3Info.SampleRate, mp3Info.BitRate));
			}

			return 0;
		}
Ejemplo n.º 10
0
 private void Previous()
 {
     if (_library.PlayedSongs.Count > 0)
     {
         Pause();
         _currSong     = _library.Previous();
         Player.Source = new Uri(_currSong.FullPath);
         lblCurrentlyPlaying.Content = _currSong.Name;
         Player.Play();
         _isPlaying = true;
     }
 }
Ejemplo n.º 11
0
		public virtual int sceMp3GetInfoToAddStreamData(int id, TPointer32 writeAddr, TPointer32 writableBytesAddr, TPointer32 readOffsetAddr)
		{
			Mp3Info info = getMp3Info(id);
			writeAddr.setValue(info.InputBuffer.WriteAddr);
			writableBytesAddr.setValue(info.WritableBytes);
			readOffsetAddr.setValue(info.InputBuffer.FilePosition);

			//if (log.DebugEnabled)
			{
				Console.WriteLine(string.Format("sceMp3GetInfoToAddStreamData returning writeAddr=0x{0:X8}, writableBytes=0x{1:X}, readOffset=0x{2:X}", writeAddr.getValue(), writableBytesAddr.getValue(), readOffsetAddr.getValue()));
			}
			return 0;
		}
Ejemplo n.º 12
0
 private void Play(bool next = false)
 {
     Pause();
     if (_library.Songs != null && _library.Songs.Count > 0)
     {
         if (_currSong == null || next)
         {
             _currSong     = _library.Next();
             Player.Source = new Uri(_currSong.FullPath);
             lblCurrentlyPlaying.Content = _currSong.Name;
         }
         Player.Play();
         _isPlaying = true;
     }
 }
Ejemplo n.º 13
0
		public virtual int sceMp3LowLevelDecode(int id, TPointer sourceAddr, TPointer32 sourceBytesConsumedAddr, TPointer samplesAddr, TPointer32 sampleBytesAddr)
		{
			Mp3Info mp3Info = getMp3Info(id);
			int result = mp3Info.Codec.decode(sourceAddr.Address, 10000, samplesAddr.Address);
			//if (log.DebugEnabled)
			{
				Console.WriteLine(string.Format("sceMp3LowLevelDecode result=0x{0:X8}, samples=0x{1:X}", result, mp3Info.Codec.NumberOfSamples));
			}
			if (result < 0)
			{
				return SceKernelErrors.ERROR_MP3_LOW_LEVEL_DECODING_ERROR;
			}

			sourceBytesConsumedAddr.setValue(result);
			sampleBytesAddr.setValue(mp3Info.Codec.NumberOfSamples * 4);

			return 0;
		}
Ejemplo n.º 14
0
        public static Mp3Info GetMp3Info(string FileName)
        {
            //打开文件
            FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);

            Encoding FileEncoding = Encoding.GetEncoding("GBK");
            //获取MP3文件最后128个字节,ID3信息保存于此,如果获取失败,则返回null
            const int seekPos = 128;

            fs.Seek(-seekPos, SeekOrigin.End); //从文件尾部开始往回seek到128字节处
            int rl = 0;

            byte[] Last128 = new byte[seekPos];
            rl = fs.Read(Last128, 0, seekPos); //将最后的128个字节读出来放入byte[]中
            fs.Seek(0, SeekOrigin.Begin);      //恢复Seek位置
            //关闭文件
            fs.Close();

            //将mp3最后的128个字节格式化为Mp3Info
            Mp3Info myMp3Info = FormatMp3Info(Last128, FileEncoding);

            //返回
            return(myMp3Info);
        }
Ejemplo n.º 15
0
        public MusicItem AddItem(string name, string listname, bool b = false)
        {
            MusicItem se       = null;
            bool      Searched = false;

            foreach (MusicListItem iy in Groups)
            {
                if (iy.Name == listname)
                {
                    Searched = true;
                }
            }
            if (Searched)
            {
                if (IsInList(name, listname))
                {
                    return(null);
                }
                else
                {
                    int a = 0;
                    for (int i = 0; i < Items.Count; i++)
                    {
                        if (Items[i].Tag != null)
                        {
                            if (Items[i].Tag.ToString() == listname)
                            {
                                a = a + 1;
                            }
                        }
                    }
                    DuiBaseControl ix = null;
                    foreach (DuiBaseControl ixx in Items)
                    {
                        if (ixx.Name.Replace("list_", "") == listname)
                        {
                            ix = ixx;
                        }
                    }
                    if (File.Exists(name))
                    {
                        #region 本地音乐
                        Mp3Info info = MP3Info.GetMp3Info(name);

                        string   artists       = info.Artist;
                        string   album         = info.Album;
                        string   length        = info.MusicLength;
                        string   title         = info.Title;
                        DuiLabel infoforsinger = new DuiLabel();
                        infoforsinger.TextRenderMode = System.Drawing.Text.TextRenderingHint.AntiAlias;
                        infoforsinger.Size           = new Size(140, 20);
                        if (artists != "")
                        {
                            infoforsinger.Text = "-" + artists;
                        }
                        infoforsinger.Location  = new Point(160, 4);
                        infoforsinger.ForeColor = Color.FromArgb(220, 220, 220);
                        infoforsinger.Font      = new Font("微软雅黑", 9F);
                        infoforsinger.Name      = "infoforsinger";

                        DuiPictureBox albumpic = new DuiPictureBox();
                        albumpic.Size                  = new Size(50, 50);
                        albumpic.Location              = new Point(5, 0);
                        albumpic.Name                  = "albumpic";
                        albumpic.BackgroundImage       = Properties.Resources.default_album;
                        albumpic.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
                        albumpic.Visible               = false;

                        DuiLabel infoforTimer = new DuiLabel();
                        infoforTimer.Size           = new Size(70, 20);
                        infoforTimer.Text           = length;
                        infoforTimer.Location       = new Point(350, 4);
                        infoforTimer.ForeColor      = Color.FromArgb(255, 255, 255);
                        infoforTimer.Font           = new Font("微软雅黑", 9F);
                        infoforTimer.Name           = "infoforTimer";
                        infoforTimer.TextRenderMode = System.Drawing.Text.TextRenderingHint.AntiAlias;

                        DuiButton btnplay = new DuiButton();
                        btnplay.Size         = new Size(20, 20);
                        btnplay.Location     = new Point(295, 3);
                        btnplay.NormalImage  = Properties.Resources.list_btn_play_normal;
                        btnplay.HoverImage   = Properties.Resources.list_btn_play_hover;
                        btnplay.PressedImage = Properties.Resources.list_btn_play_press;
                        btnplay.MouseClick  += Btnplay_MouseDown;
                        btnplay.MouseEnter  += Btnplay_MouseEnter;
                        btnplay.MouseLeave  += Btnplay_MouseLeave;
                        btnplay.Name         = "btnplay";
                        btnplay.Tag          = name;
                        btnplay.Visible      = false;

                        DuiButton btnpause = new DuiButton();
                        btnpause.Size         = new Size(20, 20);
                        btnpause.Location     = new Point(295, 3);
                        btnpause.NormalImage  = Properties.Resources.list_btn_pause_normal;
                        btnpause.HoverImage   = Properties.Resources.list_btn_pause_hover;
                        btnpause.PressedImage = Properties.Resources.list_btn_pause_press;
                        btnpause.MouseClick  += Btnpause_MouseClick;
                        btnpause.Name         = "btnpause";
                        btnpause.Tag          = name;
                        btnpause.MouseEnter  += Btnpause_MouseEnter;
                        btnpause.MouseLeave  += Btnpause_MouseLeave;
                        btnpause.Visible      = false;

                        DuiButton btndel = new DuiButton();
                        btndel.Size         = new Size(20, 20);
                        btndel.Location     = new Point(317, 3);
                        btndel.NormalImage  = Properties.Resources.btn_del_h;
                        btndel.HoverImage   = Properties.Resources.btn_del_n;
                        btndel.PressedImage = Properties.Resources.btn_del_p;
                        btndel.MouseClick  += Btndel_MouseClick;
                        btndel.MouseEnter  += Btndel_MouseEnter;
                        btndel.MouseLeave  += Btndel_MouseLeave;
                        btndel.Name         = "btndel";
                        btndel.Tag          = listname;
                        btndel.Visible      = false;

                        DuiLabel lbl = new DuiLabel();
                        lbl.TextRenderMode = System.Drawing.Text.TextRenderingHint.AntiAlias;
                        lbl.Size           = new System.Drawing.Size(160, 17);
                        if (Path.GetFileNameWithoutExtension(name).Length > 14)
                        {
                            lbl.Text        = Path.GetFileNameWithoutExtension(name).Remove(13).Insert(13, "...");
                            lbl.Tag         = Path.GetFileNameWithoutExtension(name);
                            lbl.MouseEnter += Lbl_MouseEnter;
                            lbl.MouseLeave += Lbl_MouseLeave;
                        }
                        else
                        {
                            lbl.Text = Path.GetFileNameWithoutExtension(name);
                            lbl.Tag  = Path.GetFileNameWithoutExtension(name);
                        }
                        lbl.Location  = new Point(10, 4);
                        lbl.ForeColor = Color.FromArgb(255, 255, 255);
                        lbl.Font      = new Font("微软雅黑", 9F);
                        lbl.Name      = "lbl";


                        DuiBaseControl listx = new DuiBaseControl();
                        listx.BackColor = Color.FromArgb(0, Color.Black);
                        listx.Width     = Width;
                        listx.Height    = 25;
                        listx.Controls.Add(lbl);
                        listx.Controls.Add(infoforsinger);
                        listx.Controls.Add(infoforTimer);
                        listx.Controls.Add(btndel);
                        listx.Controls.Add(btnplay);
                        listx.Controls.Add(btnpause);
                        listx.Controls.Add(albumpic);
                        listx.MouseDown        += Listx_MouseDown;
                        listx.MouseUp          += Listx_MouseUp;
                        listx.MouseMove        += Listx_MouseMove;
                        listx.MouseEnter       += Listx_MouseEnter;
                        listx.MouseLeave       += Listx_MouseLeave;
                        listx.MouseDoubleClick += Listx_MouseDoubleClick;
                        listx.MouseClick       += Listx_MouseClick;
                        listx.Name              = name;
                        listx.Height            = 25;
                        listx.Tag = listname;

                        if (!b)
                        {
                            Items.Add(listx);
                        }
                        else
                        {
                            Items.Insert(Items.IndexOf(ix) + a + 1, listx);
                        }

                        foreach (MusicListItem iy in Groups)
                        {
                            if (iy.Name == listname)
                            {
                                MusicItem m = new MusicItem();
                                m.Path       = name;
                                m.IsOnline   = false;
                                m.ParentName = listname;
                                if (title != "")
                                {
                                    m.Name = title;
                                }
                                else
                                {
                                    m.Name = lbl.Tag.ToString();
                                }
                                m.Singer = artists;
                                iy.musics.Add(m);
                            }
                        }

                        if (OpenedList == listname)
                        {
                            listx.Visible = true;
                        }
                        else
                        {
                            listx.Visible = false;
                        }
                        #endregion
                    }
                    else
                    {
                        #region 失效音乐

                        DuiLabel infoforTimer = new DuiLabel();
                        infoforTimer.Size           = new Size(70, 20);
                        infoforTimer.Text           = "文件失效";
                        infoforTimer.Location       = new Point(350, 4);
                        infoforTimer.ForeColor      = Color.Red;
                        infoforTimer.Font           = new Font("微软雅黑", 9F);
                        infoforTimer.Name           = "infoforTimer";
                        infoforTimer.TextRenderMode = System.Drawing.Text.TextRenderingHint.AntiAlias;

                        DuiButton btndel = new DuiButton();
                        btndel.Size         = new Size(20, 20);
                        btndel.Location     = new Point(317, 3);
                        btndel.NormalImage  = Properties.Resources.btn_del_h;
                        btndel.HoverImage   = Properties.Resources.btn_del_n;
                        btndel.PressedImage = Properties.Resources.btn_del_p;
                        btndel.MouseClick  += Btndel_MouseClick;
                        btndel.MouseEnter  += Btndel_MouseEnter;
                        btndel.MouseLeave  += Btndel_MouseLeave;
                        btndel.Name         = "btndel";
                        btndel.Tag          = listname;
                        btndel.Visible      = false;

                        DuiLabel lbl = new DuiLabel();
                        lbl.TextRenderMode = System.Drawing.Text.TextRenderingHint.AntiAlias;
                        lbl.Size           = new System.Drawing.Size(160, 20);
                        if (Path.GetFileNameWithoutExtension(name).Length > 14)
                        {
                            lbl.Text        = Path.GetFileNameWithoutExtension(name).Remove(13).Insert(13, "...");
                            lbl.MouseEnter += Lbl_MouseEnter;
                        }
                        else
                        {
                            lbl.Text = Path.GetFileNameWithoutExtension(name);
                        }
                        lbl.Location    = new Point(10, 4);
                        lbl.ForeColor   = Color.Red;
                        lbl.Font        = new Font("微软雅黑", 9F);
                        lbl.Name        = "lbl";
                        lbl.Tag         = Path.GetFileNameWithoutExtension(name);
                        lbl.MouseLeave += Lbl_MouseLeave;

                        DuiBaseControl listx = new DuiBaseControl();
                        listx.BackColor = Color.FromArgb(0, Color.Black);
                        listx.Width     = Width;
                        listx.Height    = 25;
                        listx.Controls.Add(lbl);
                        listx.Controls.Add(infoforTimer);
                        listx.Controls.Add(btndel);
                        listx.MouseMove  += Listx_MouseMove;
                        listx.MouseDown  += Listx_MouseDown;
                        listx.MouseUp    += Listx_MouseUp;
                        listx.MouseEnter += Listx_MouseEnterLose;
                        listx.MouseLeave += Listx_MouseLeaveLose;
                        listx.Name        = name;
                        listx.Height      = 25;
                        listx.Tag         = listname;

                        if (!b)
                        {
                            Items.Add(listx);
                        }
                        else
                        {
                            Items.Insert(Items.IndexOf(ix) + a + 1, listx);
                        }

                        foreach (MusicListItem iy in Groups)
                        {
                            if (iy.Name == listname)
                            {
                                MusicItem m = new MusicItem();
                                m.Path     = name;
                                m.IsOnline = false;

                                iy.musics.Add(m);
                            }
                        }

                        if (OpenedList == listname)
                        {
                            listx.Visible = true;
                        }
                        else
                        {
                            listx.Visible = false;
                        }

                        #endregion
                    }
                    a = a + 1;
                    if (a == 0)
                    {
                        ((DuiLabel)ix.FindControl("Count")[0]).Text = "[这个列表没有歌曲,可以直接把歌曲拖到这里来哦]";
                    }
                    else
                    {
                        ((DuiLabel)ix.FindControl("Count")[0]).Text = "[" + a.ToString() + "]";
                    }
                    RefreshList();
                }
            }
            GC.Collect();
            return(se);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 将mp3最后的128个字节格式化为Mp3Info
        /// </summary>
        /// <param name = "Info">从MP3文件中截取的二进制信息</param>
        /// <returns>返回一个Mp3Info结构</returns>
        private static Mp3Info FormatMp3Info(byte[] Info, System.Text.Encoding Encoding)
        {
            Mp3Info myMp3Info = new Mp3Info();
            string  str       = null;
            int     i;
            int     position     = 0; //循环的起始值
            int     currentIndex = 0; //Info的当前索引值

            //获取TAG标识
            for (i = currentIndex; i < currentIndex + 3; i++)
            {
                str = str + (char)Info[i];
                position++;
            }
            currentIndex       = position;
            myMp3Info.identify = str;

            //获取歌名
            str = null;
            byte[] bytTitle = new byte[30]; //将歌名部分读到一个单独的数组中
            int    j        = 0;

            for (i = currentIndex; i < currentIndex + 30; i++)
            {
                bytTitle[j] = Info[i];
                position++;
                j++;
            }
            currentIndex    = position;
            myMp3Info.Title = ByteToString(bytTitle, Encoding);

            //获取歌手名
            str = null;
            j   = 0;
            byte[] bytArtist = new byte[30]; //将歌手名部分读到一个单独的数组中
            for (i = currentIndex; i < currentIndex + 30; i++)
            {
                bytArtist[j] = Info[i];
                position++;
                j++;
            }
            currentIndex     = position;
            myMp3Info.Artist = ByteToString(bytArtist, Encoding);

            //获取唱片名
            str = null;
            j   = 0;
            byte[] bytAlbum = new byte[30]; //将唱片名部分读到一个单独的数组中
            for (i = currentIndex; i < currentIndex + 30; i++)
            {
                bytAlbum[j] = Info[i];
                position++;
                j++;
            }
            currentIndex    = position;
            myMp3Info.Album = ByteToString(bytAlbum, Encoding);

            //获取年
            str = null;
            j   = 0;
            byte[] bytYear = new byte[4]; //将年部分读到一个单独的数组中
            for (i = currentIndex; i < currentIndex + 4; i++)
            {
                bytYear[j] = Info[i];
                position++;
                j++;
            }
            currentIndex   = position;
            myMp3Info.Year = ByteToString(bytYear, Encoding);

            //获取注释
            str = null;
            j   = 0;
            byte[] bytComment = new byte[28]; //将注释部分读到一个单独的数组中
            for (i = currentIndex; i < currentIndex + 25; i++)
            {
                bytComment[j] = Info[i];
                position++;
                j++;
            }
            currentIndex      = position;
            myMp3Info.Comment = ByteToString(bytComment, Encoding);

            //以下获取保留位
            myMp3Info.reserved1 = (char)Info[++position];
            myMp3Info.reserved2 = (char)Info[++position];
            myMp3Info.reserved3 = (char)Info[++position];

            //
            return(myMp3Info);
        }