예제 #1
0
 private void postDemandInfo(DemandInfo info)
 {
     if (DemandInfoEvent != null && info != null)
     {
         DemandInfoEvent(info);
     }
 }
예제 #2
0
        private void removeDemandInfo(DemandInfo info)
        {
            if (info == null)
            {
                return;
            }

            //删除点歌信息
            if (DemandInfoEvent != null)
            {
                DemandInfoEvent(info);
            }
            m_demandMusicQue.Remove(info);
        }
예제 #3
0
        public void OnRcvDamaku(string userName, string keyword)
        {
            //收到弹幕

            //1、判断歌曲数目
            var isFull = m_demandMusicQue.isFull();

            if (isFull)
            {
                Debug.WriteLine("Warning: song reach max num");
                return;
            }


            //2、判断是不是弹幕点歌格式
            keyword = checkDemandMusicName(keyword);

            if (keyword.Length == 0)
            {
                Debug.WriteLine("Warning: no keyword:" + keyword);
                return;
            }

            var isExist = isKeywordExist(keyword);

            if (isExist)
            {
                Debug.WriteLine("Warning: keyword already exist:" + keyword);
                return;
            }

            Debug.WriteLine("On demand music:" + keyword);

            //add queue
            var demandInfo = new DemandInfo();

            demandInfo.Keyword  = keyword;
            demandInfo.QueueId  = genQueueId();
            demandInfo.UserName = userName;
            demandInfo.Status   = DemandSongStatus.Queue;

            m_tmpDemandQue.Add(demandInfo);

            postDemandInfo(demandInfo);

            tryFigureTmpDemandQue();
        }
예제 #4
0
        public DemandInfo GetInfo(UInt32 queueId, bool isRemove = false)
        {
            DemandInfo info  = null;
            int        index = -1;

            for (int i = 0; i < m_demandMusicQue.Count; i++)
            {
                var tmpInfo = (DemandInfo)m_demandMusicQue[i];
                if (tmpInfo.QueueId == queueId)
                {
                    info  = tmpInfo;
                    index = i;
                    break;
                }
            }

            if (isRemove && index > -1)
            {
                m_demandMusicQue.RemoveAt(index);
            }
            return(info);
        }
예제 #5
0
        public void tryPlayMusic()
        {
            //尝试播放音乐
            var firstInfo = m_demandMusicQue.First();

            if (firstInfo != null)
            {
                m_curMusicMode = MusicMode.DemandMusic;            //点歌模式
                if (firstInfo.Status == DemandSongStatus.WaitPlay) //队列第一个刚好是等待播放状态
                {
                    m_musicPlayer.Play(firstInfo.QueueId, firstInfo.SongInfo.FileName);
                }
            }
            else //自定义音乐播放模式
            {
                var musicNum = m_localMusicList.Count;

                if (musicNum == 0)
                {
                    m_curMusicMode = MusicMode.Invalid; //无效状态
                    return;
                }

                m_curMusicMode = MusicMode.LocalMusic; //本地音乐

                var musicIdx = -1;

                if (m_localMusicIdx == -1) //初始化
                {
                    musicIdx = 0;
                }
                else
                {
                    musicIdx = m_localMusicIdx + 1; //下一曲
                    if (musicIdx >= musicNum)       //循环
                    {
                        musicIdx = 0;
                    }
                }

                m_localMusicIdx = musicIdx;

                //生成信息
                string fileName   = (string)m_localMusicList[musicIdx];
                string musicName  = Path.GetFileNameWithoutExtension(fileName);
                var    demandInfo = new DemandInfo();
                demandInfo.Keyword      = musicName;
                demandInfo.QueueId      = genQueueId();
                demandInfo.UserName     = "******";
                demandInfo.Status       = DemandSongStatus.WaitPlay;
                demandInfo.IsLocalMusic = true;
                demandInfo.SongInfo     = new Song(null)
                {
                    Id = 0, FileName = fileName, Name = musicName
                };
                //加入队列
                m_demandMusicQue.Add(demandInfo);
                postDemandInfo(demandInfo);
                //播放音乐
                m_musicPlayer.Play(demandInfo.QueueId, fileName);
            }
        }
예제 #6
0
        private void onDemandInfo(DemandInfo info)
        {
            var queueId = info.QueueId.ToString();
            var status  = info.Status;

            var          items = listViewMusic.Items;
            ListViewItem item  = items[queueId];

            if (item == null)
            {
                if (status == DemandSongStatus.Queue || (info.IsLocalMusic == true && status == DemandSongStatus.WaitPlay))
                {
                    item      = new ListViewItem();
                    item.Name = queueId;
                    item.SubItems.Add(info.Keyword);
                    item.SubItems.Add(info.UserName);

                    listViewMusic.Items.Add(item);
                }
                else //初始化
                {
                    return;
                }
            }


            var isError = info.isError();


            if (isError)
            {
                string tipsStr = null;
                switch (info.Error)
                {
                case DemandSongError.Full:
                    tipsStr = "曲单已满";
                    break;

                case DemandSongError.Search:
                    tipsStr = "找不到歌曲";
                    break;

                case DemandSongError.GetDetail:
                    tipsStr = "获取歌曲信息失败";
                    break;

                case DemandSongError.Download:
                    tipsStr = "下载失败";
                    break;

                case DemandSongError.Cancel:
                    tipsStr = "取消";
                    break;

                case DemandSongError.Repeat:
                    tipsStr = "重复";
                    break;

                default:
                    break;
                }

                if (tipsStr != null)
                {
                    item.Text = tipsStr;
                }
                Debug.WriteLine("SongInfo Error: " + info.Keyword + " status:" + info.Status + " error:" + info.Error);
            }
            else
            {
                var    song    = info.SongInfo;
                string tipsStr = null;
                switch (status)
                {
                case DemandSongStatus.Queue:
                    tipsStr = "等待处理";
                    break;

                case DemandSongStatus.Search:
                    tipsStr = "搜索中";
                    break;

                case DemandSongStatus.GetDetail:
                    tipsStr = "获取信息中";
                    break;

                case DemandSongStatus.Download:
                    tipsStr = "下载中";
                    item.SubItems[1].Text = song.Name;
                    break;

                case DemandSongStatus.WaitPlay:
                    tipsStr = "等待播放";
                    break;

                case DemandSongStatus.Playing:
                    tipsStr = "播放中";
                    break;

                case DemandSongStatus.PlayEnd:
                    tipsStr = "播放完毕";
                    break;

                default:
                    break;
                }
                if (tipsStr != null)
                {
                    item.Text = tipsStr;
                }
                Debug.WriteLine("SongInfo: " + info.Keyword + " status:" + status);
            }
        }
예제 #7
0
 public void Remove(DemandInfo info)
 {
     m_demandMusicQue.Remove(info);
 }
예제 #8
0
 public void Add(DemandInfo info)
 {
     Debug.Assert(!isFull(), "should check full first");
     m_demandMusicQue.Add(info);
 }