Exemplo n.º 1
0
        /// <summary>
        /// 장바구니 재생 버튼 클릭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CartListPlayButton_Click(object sender, EventArgs e)
        {
            #region ### 폼 중복 열기 방지

            foreach (Form openForm in Application.OpenForms)
            {
                if (openForm.Name == "PlayForm")
                {
                    openForm.Activate();
                    return;
                }
            }

            #endregion

            #region ### 예외처리

            if (VideoCartListView.SelectedItems.Count > 0)
            {
                int    index    = VideoCartListView.FocusedItem.Index;
                string cartName = VideoCartListView.Items[index].Text;

                FileInfo fileInfo = new FileInfo(PathList.listPath + cartName + ".csv");

                // 해당 장바구니 파일 존재 여부 확인
                if (fileInfo.Exists)
                {
                    List <Video> videos = new List <Video>();

                    // 파일 읽기
                    try
                    {
                        using (StreamReader streamReader = new StreamReader(fileInfo.FullName))
                        {
                            string listString = string.Empty;
                            while ((listString = streamReader.ReadLine()) != null)
                            {
                                string[] listArray = listString.Split(',');

                                Video video = new Video(Int32.Parse(listArray[0]), listArray[1], listArray[2]);
                                videos.Add(video);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("[에러발생] 리스트 파일을 읽는 중 에러가 발생하였습니다. 관리자에게 문의해주세요.");
                        log.WriteLog("[Error] : In the Video Cart List (Reading) \n" + ex);
                    }

                    // 읽은 파일 개수 확인
                    if (videos.Count > 0)
                    {
                        int notExistCount = 0;
                        int listIndex     = 0;

                        // 파일 존재 여부 확인
                        List <int> removeIndex = new List <int>();
                        foreach (var video in videos)
                        {
                            FileInfo videoFile = new FileInfo(video.videoPath);
                            if (!videoFile.Exists)
                            {
                                notExistCount++;

                                removeIndex.Add(listIndex);
                            }
                            listIndex++;
                        }

                        // 장바구니에 해당 경로에 없는 파일이 있으면
                        if (notExistCount != 0)
                        {
                            removeIndex.Reverse();

                            foreach (var idx in removeIndex)
                            {
                                videos.RemoveAt(idx);

                                // 경로에 없는 파일 삭제 후 번호 재정렬
                                foreach (Video data in videos)
                                {
                                    if (data.videoNum > idx + 1)
                                    {
                                        data.videoNum--;
                                    }
                                }
                            }

                            listDictionary[cartName] = videos;

                            log.SaveVideoCartLists(listDictionary, cartName);
                            UpdateVideoCartListView();

                            MessageBox.Show("해당 경로에 존재하지 않는 파일이 " + notExistCount + "개가 발견되었습니다.\n해당 파일은 장바구니 리스트에서 삭제되었습니다.");
                        }

                        // 장바구니 재생
                        try
                        {
                            // 플레이 리스트 만들기
                            List <string> playList = new List <string>();
                            foreach (var video in videos)
                            {
                                playList.Add(video.videoPath);
                            }

                            //PlayForm playForm = new PlayForm(playList);
                            //playForm.Owner = this;
                            //playForm.Show();
                            using (PlayForm playForm = new PlayForm(playList))
                            {
                                playForm.ShowDialog();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("[에러발생] 장바구니 파일 재생 중 에러가 발생하였습니다. 관리자에게 문의해주세요.");
                            log.WriteLog("[Error] : In the Video Cart List (Playing) \n" + ex);
                        }
                    }
                    else
                    {
                        MessageBox.Show("재생할 장바구니에 리스트가 존재하지 않습니다.\n해당 장바구니를 삭제 후 다시 만들어주세요.");
                    }
                }
                else
                {
                    MessageBox.Show("해당 장바구니 파일이 존재하지 않습니다.\n파일 저장 위치를 확인해주세요.");
                }
            }
            else
            {
                MessageBox.Show("선택된 항목이 없습니다.");
            }

            #endregion
        }
Exemplo n.º 2
0
        /// <summary>
        /// [랜덤] 재생
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RandomFolderPlayButton_Click(object sender, EventArgs e)
        {
            #region ### 폼 중복 열기 방지
            foreach (Form openForm in Application.OpenForms)
            {
                if (openForm.Name == "PlayForm")
                {
                    openForm.Activate();
                    return;
                }
            }
            #endregion

            #region ### 예외처리
            if (RandomVideoFolderListView.SelectedItems.Count > 0)
            {
                int index = RandomVideoFolderListView.FocusedItem.Index;

                DirectoryInfo directoryInfo = new DirectoryInfo(randomFolderList[index].folderPath);

                log.WriteLog(randomFolderList[index].folderPath + " 폴더 랜덤 재생 시작");

                // 재생할 영상 개수 확인
                if (RandomVedioCountUpDown.Value != 0)
                {
                    log.WriteLog("[랜덤 재생] : 재생할 영상 개수 확인");
                    // 폴더 경로 확인
                    if (directoryInfo.Exists)
                    {
                        log.WriteLog("[랜덤 재생] : 폴더 경로 확인");

                        // 폴더 안 동영상 개수 확인
                        int vedioCount = CountFolderVideos(randomFolderList[index].folderPath);
                        if (vedioCount > 0)
                        {
                            log.WriteLog("[랜덤 재생] : 폴더 안 동영상 개수 확인");
                            // 재생할 영상 개수와 폴더 안 영상 개수 비교
                            if (vedioCount >= RandomVedioCountUpDown.Value)
                            {
                                try
                                {
                                    log.WriteLog("[랜덤 재생] : 재생할 영상 개수와 폴더 안 영상 개수 비교 확인");
                                    List <string> randomPlayList = AddPlayList(randomFolderList[index].folderPath);

                                    //PlayForm playForm = new PlayForm(randomPlayList);
                                    //playForm.Owner = this;
                                    //playForm.Show();
                                    using (PlayForm playForm = new PlayForm(randomPlayList))
                                    {
                                        playForm.ShowDialog();
                                    }

                                    //WindowsMediaPlayer player = new WindowsMediaPlayer();
                                    //IWMPPlaylist playList = player.playlistCollection.newPlaylist("RandomPlayList");
                                    //IWMPMedia media;

                                    //foreach (var list in randomPlayList)
                                    //{
                                    //    media = player.newMedia(list);
                                    //    playList.appendItem(media);
                                    //}

                                    //player.currentPlaylist = playList;

                                    //player.openPlayer(randomPlayList[0]);
                                    //if (player.playState == WMPPlayState.wmppsPlaying)
                                    //{
                                    //    player.fullScreen = true;
                                    //}
                                    //player.openPlayer(randomFolderList[index].folderPath + @"\내일은 미스트롯.E10.190502.720p-NEXT.mp4");
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show("[에러발생] 동영상을 실행하는데 에러가 발생했습니다.\n관리자에게 문의하세요");
                                    log.WriteLog("[Error] : " + ex);
                                }
                            }
                            else
                            {
                                log.WriteLog("[WARNING] : 재생할 영상 개수가 폴더 안 영상 개수보다 많음");
                                MessageBox.Show("폴더 안의 영상 개수보다 재생할 영상 개수가 더 많습니다.\n재생할 영상 개수를 다시 설정해주세요.");
                            }
                        }
                        else
                        {
                            log.WriteLog("[WARNING] : 폴더 안 동영상 존재하지 않음");
                            MessageBox.Show("선택한 폴더에 동영상이 없습니다.\n해당 폴더를 다시 한 번 확인해주세요.");
                        }
                    }
                    else
                    {
                        log.WriteLog("[WARNING] : 폴더 경로 확인 실패");
                        MessageBox.Show("선택한 폴더가 존재하지 않습니다.");

                        randomFolderList.RemoveAt(index);
                        RandomVideoFolderListView.Items.RemoveAt(index);

                        log.WriteLog("랜덤 리스트 삭제 완료");
                        log.SaveListLog(randomFolderList, PathList.randomVideoFolderLists, PathList.randomPath);
                        log.WriteLog("랜덤 리스트 업데이트 완료");
                    }

                    //WindowsMediaPlayer player = new WindowsMediaPlayer();
                    //player.openPlayer(randomFolderList[index].folderPath + @"\내일은 미스트롯.E10.190502.720p-NEXT.mp4");
                }
                else
                {
                    log.WriteLog("[WARNING] : 재생할 영상 개수가 0");
                    MessageBox.Show("재생할 영상 개수가 설정되지 않았습니다. 설정해주세요.");
                }
            }
            else
            {
                MessageBox.Show("선택된 항목이 없습니다.");
            }
            #endregion
        }