Пример #1
0
        private VideoItemFileInfo RunFileWaitForExit(VideoItemFileInfo videoItemFileInfo, DoWorkEventArgs doWorkEvent)
        {
            VideoItemFileInfo resultsVideoItemFileInfo = new VideoItemFileInfo();

            // Abort the operation if the user has canceled.
            // Note that a call to CancelAsync may have set
            // CancellationPending to true just after the
            // last invocation of this method exits, so this
            // code will not have the opportunity to set the
            // DoWorkEventArgs.Cancel flag to true. This means
            // that RunWorkerCompletedEventArgs.Cancelled will
            // not be set to true in your RunWorkerCompleted
            // event handler. This is a race condition.

            if (backgroundWorker.CancellationPending)
            {
                doWorkEvent.Cancel = true;
                resultsVideoItemFileInfo.elapsed       = 0;
                resultsVideoItemFileInfo.videoInfo     = null;
                resultsVideoItemFileInfo.videoItemFile = null;
                return(resultsVideoItemFileInfo);
            }

            Stopwatch stopwatch = Stopwatch.StartNew();

            percentComplete = 0;
            string playing = videoItemFileInfo.videoItemFile.Name;

            if (playing.Length > 30)
            {
                playing = playing.Substring(0, 30) + ".. ";
            }
            backgroundWorker.ReportProgress(percentComplete, "Playing\n" + playing + "..");

            FileInfo fileInfo = videoItemFileInfo.GetFileInfo();
            bool     ret      = MyFile.RunFile(fileInfo);

            percentComplete = 100;
            backgroundWorker.ReportProgress(percentComplete, "Finished playing\n" + playing);


            stopwatch.Stop();

            resultsVideoItemFileInfo.elapsed       = (long)Math.Floor((decimal)stopwatch.ElapsedMilliseconds / 1000);
            resultsVideoItemFileInfo.videoInfo     = videoItemFileInfo.videoInfo;
            resultsVideoItemFileInfo.videoItemFile = videoItemFileInfo.videoItemFile;

            // meh, so completed msg shows
            Thread.Sleep(500);

            return(resultsVideoItemFileInfo);
        }
Пример #2
0
        private void toolStripMenuItemOpen_Click(object sender, EventArgs e)
        {
            // item unselected, so ignore
            if (listViewSyncUp.SelectedItems.Count == 0)
            {
                return;
            }

            FileInfo fileInfo = (FileInfo)listViewSyncUp.SelectedItems[0].Tag;

            if (fileInfo == null)
            {
                return;
            }

            MyFile.RunFile(fileInfo);
        }
Пример #3
0
        public bool Play(VideoInfo videoInfo, VideoItemFile videoItemFile)
        {
            bool ret = false;
            // if playing video, mark video item as played/watched
            // TODO btr way to normalize if a file is a video file
            string fileExt = videoItemFile.Extension.TrimStart('.');

            switch (fileExt)
            {
            case "avi":
            case "m4v":
            case "mov":
            case "mpg":
            case "mkv":
            case "mp4":
            case "mpeg":
                // run as background so can wait w/o blocking ui
                // after X secs timeout, mark as played/watched
                // .. but requires UseShellEx = false which requires more config/settings to specify video player
                // so for now, meh runs as background thread w/o wait
                VideoItemFileInfo videoItemFileInfo = new VideoItemFileInfo();
                videoItemFileInfo.videoInfo     = videoInfo;
                videoItemFileInfo.videoItemFile = videoItemFile;
                backgroundWorkerOpenFile.Run(videoItemFileInfo);
                break;

            default:
                string   fullName = videoInfo.GetFullName(videoItemFile);
                FileInfo fileInfo = MyFile.FileInfo(fullName);
                if (fileInfo == null)
                {
                    // MessageBox.Show("Error trying to open file\n"+fullName+"\nView log for details");
                    ret = false;
                }
                else
                {
                    ret = MyFile.RunFile(fileInfo);
                }
                break;
            }

            return(ret);
        }