예제 #1
0
 private void BroadcastLoadedVideoEvent(Video.VideoFile video, double time)
 {
     Forms.EventHandlers.LoadedVideoEventArgs e = new Forms.EventHandlers.LoadedVideoEventArgs();
     e.Video = video;
     e.Time  = time;
     OnLoadedVideo(this, e);
 }
예제 #2
0
        private void transparentPanelCover_DragDrop(object sender, DragEventArgs e)
        {
            string filePath = ((string[])e.Data.GetData(DataFormats.FileDrop, false))[0];

            if (!File.Exists(filePath))
            {
                MessageBox.Show("This file doesn't exist!", "Twitch VOD Player", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            bool   fileFormatSupported = false;
            string fileExtension       = Path.GetExtension(filePath);

            foreach (string videoExtension in VideoExtensions)
            {
                if (fileExtension == videoExtension)
                {
                    fileFormatSupported = true;
                    break;
                }
            }
            if (!fileFormatSupported)
            {
                MessageBox.Show("This video cannot be played because the file format is unsupported.", "Twitch VOD Player", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Video.VideoFile video = new Video.VideoFile(filePath);
            Task.Run(() => LoadVideo(video));
        }
예제 #3
0
 public void OpenVodFile()
 {
     openVodFileDialog.Filter = videoExtensionFilter;
     if (openVodFileDialog.ShowDialog() == DialogResult.OK)
     {
         Video.VideoFile video = new Video.VideoFile(openVodFileDialog.FileName);
         Task.Run(() => LoadVideo(video));
     }
 }
예제 #4
0
        public async void CreateChatFile(string outputPath, string chatLogFilePath, string vodId,
                                         bool useVodId, bool setTime, TimeSpan?beginTime, TimeSpan?endTime, Video.VideoFile currentVideo = null)
        {
            CreateChatFileTokenSource = new CancellationTokenSource();

            if (CurrentlyCreatingChatFile)
            {
                return;
            }
            CurrentlyCreatingChatFile = true;

            BroadcastCreatingChatFileEvent("Creating Chat file...\nPlease wait while the program is connecting.");

            //Input validation
            if (outputPath == "")
            {
                BroadcastErrorOccuredCreatingChatFileEvent("You must specify the output directory for this VOD Set.");
                CurrentlyCreatingChatFile = false;
                return;
            }
            else if (chatLogFilePath == "" && !useVodId)
            {
                BroadcastErrorOccuredCreatingChatFileEvent("You must specify the path of the chat log file.");
                CurrentlyCreatingChatFile = false;
                return;
            }
            else if (useVodId && vodId == "")
            {
                BroadcastErrorOccuredCreatingChatFileEvent("VOD ID cannot be empty.");
                CurrentlyCreatingChatFile = false;
                return;
            }
            else if (Properties.Settings.Default.ClientId == "")
            {
                BroadcastErrorOccuredCreatingChatFileEvent("Your Twitch Client ID hasn't been set up yet.\nPlease set up your Client ID first before creating a VOD Set.");
                CurrentlyCreatingChatFile = false;
                return;
            }
            else if (setTime && (beginTime == null || endTime == null || endTime <= beginTime))
            {
                BroadcastErrorOccuredCreatingChatFileEvent("Invalid Begin Time or End Time.");
                CurrentlyCreatingChatFile = false;
                return;
            }

            if (!setTime && currentVideo != null)
            {
                beginTime = TimeSpan.FromMilliseconds(0);
                endTime   = currentVideo.EndTime;
            }

            if (useVodId)
            {
                chatLogFilePath = outputPath + @"\" + (vodId + ".json");

                try {
                    await Task.Run(() => DownloadChatLogFileUsingVodId(chatLogFilePath, vodId, beginTime, endTime));
                } catch (Exception e) {
                    BroadcastErrorOccuredCreatingChatFileEvent("Error occured creating VOD Set directory: " + e.Message);
                    CurrentlyCreatingChatFile = false;
                    return;
                }
            }

            if (CreateChatFileTokenSource.IsCancellationRequested)
            {
                if (File.Exists(chatLogFilePath))
                {
                    File.Delete(chatLogFilePath);
                }
                BroadcastErrorOccuredCreatingChatFileEvent("Creation of chat file was cancelled.");
                CurrentlyCreatingChatFile = false;
                return;
            }

            string chatOutputFilePath;

            if (currentVideo != null)
            {
                chatOutputFilePath = outputPath + @"\" + Path.GetFileNameWithoutExtension(currentVideo.FilePath) + Chat.Constants.ChatFileExtension;
            }
            else
            {
                chatOutputFilePath = outputPath + @"\" + Path.GetFileNameWithoutExtension(chatLogFilePath) + Chat.Constants.ChatFileExtension;
            }

            try {
                //This creates the .cht Chat File
                await Task.Run(() => ConvertChatLog(chatLogFilePath, chatOutputFilePath, beginTime, endTime));

                if (useVodId && File.Exists(chatLogFilePath))
                {
                    File.Delete(chatLogFilePath);
                }
            } catch (Exception e) {
                BroadcastErrorOccuredCreatingChatFileEvent("Error occured converting chat log: " + e.Message);
                CurrentlyCreatingChatFile = false;
                return;
            }

            if (CreateChatFileTokenSource.IsCancellationRequested)
            {
                if (File.Exists(chatLogFilePath))
                {
                    File.Delete(chatLogFilePath);
                }
                if (File.Exists(chatOutputFilePath))
                {
                    File.Delete(chatOutputFilePath);
                }
                BroadcastErrorOccuredCreatingChatFileEvent("Creation of chat file was cancelled.");
                CurrentlyCreatingChatFile = false;
                return;
            }

            BroadcastCreatedChatFileEvent("Successfully created chat file!", chatOutputFilePath);

            CurrentlyCreatingChatFile = false;
        }
예제 #5
0
        private void LoadVideo(Video.VideoFile video, bool startAtBeginning = false)
        {
            if (!isLoadingVideo)
            {
                bool isMuted = IsMuted;

                isLoadingVideo = true;

                MainForm.Instance.Invoke(new Action(() => {
                    openVodToolStripMenuItem.Enabled = false;
                }));

                ShowLoadingVideoDisplay();

                BroadcastLoadingVideoEvent(video);

                SaveCurrentVideoPosition();

                CurrentVideo = video;

                videoPlayer.Ctlcontrols.stop();
                videoPlayer.URL = video.FilePath;

                IsVideoPlayerPlaying = true;

                videoSeekBar.Maximum = (int)CurrentVideo.EndTime.TotalSeconds;

                if (!startAtBeginning)
                {
                    if (savedPositions.Contains(CurrentVideo.FilePath))
                    {
                        double savedPosition = 0;
                        try {
                            savedPosition = (double)savedPositions[CurrentVideo.FilePath];
                        } catch {}
                        if (CurrentVideo.EndTime.TotalMilliseconds - 5000 > (savedPosition))
                        {
                            MainForm.Instance.Invoke(new Action(() => {
                                VideoPlayerTime = savedPosition;
                            }));
                        }
                        else
                        {
                            savedPositions.Remove(CurrentVideo.FilePath);
                        }
                    }
                }
                else
                {
                    MainForm.Instance.Invoke(new Action(() => {
                        VideoPlayerTime = 0;
                    }));
                }

                BroadcastLoadedVideoEvent(CurrentVideo, VideoPlayerTime);

                MainForm.Instance.Invoke(new Action(() => {
                    if (!videoFullscreenButton.Enabled)
                    {
                        videoFullscreenButton.Enabled = true;
                    }

                    MainForm.Instance.Text = TwitchVodPlayer.Constants.Title + " - " + Path.GetFileNameWithoutExtension(video.FilePath);
                }));

                HideLoadingVideoDisplay();

                MainForm.Instance.Invoke(new Action(() => {
                    openVodToolStripMenuItem.Enabled = true;
                }));

                IsMuted = isMuted;

                isLoadingVideo = false;
            }
        }
예제 #6
0
 private void BroadcastLoadingVideoEvent(Video.VideoFile video)
 {
     Forms.EventHandlers.LoadingVideoEventArgs e = new Forms.EventHandlers.LoadingVideoEventArgs();
     e.Video = video;
     OnLoadingVideo(this, e);
 }