Beispiel #1
0
        private void SetListItem(VideoInfo videoInfo, VideoItemFile videoItemFile, string fileType)
        {
            VideoItemFileInfo videoItemFileInfo = new VideoItemFileInfo();

            videoItemFileInfo.videoInfo     = videoInfo;
            videoItemFileInfo.videoItemFile = videoItemFile;

            // if not already in image list, add to it
            if (!smallImageList.Images.ContainsKey(videoItemFile.Extension))
            {
                Icon icon = MyFileTypeIcon.Get(videoItemFileInfo.GetFullName());
                if (icon != null)
                {
                    smallImageList.Images.Add(videoItemFile.Extension, icon);
                }
            }

            ListViewItem listViewItem = new ListViewItem(videoItemFile.Name);

            listViewItem.ImageKey = videoItemFile.Extension;
            listViewItem.SubItems.Add(fileType);
            string fileSize = Convert.ToString(MyFile.FormatSize(videoItemFile.Length));

            listViewItem.SubItems.Add(fileSize);


            listViewItem.Tag = videoItemFileInfo;

            listView.Items.Add(listViewItem);
        }
Beispiel #2
0
        /// <summary>
        /// This method is inherited from the IComparer interface.
        /// It compares the two objects passed using a case insensitive comparison.
        /// </summary>
        /// <param name="x">First object to be compared</param>
        /// <param name="y">Second object to be compared</param>
        /// <returns>The result of the comparison. "0" if equal, negative if 'x' is less than 'y' and positive if 'x' is greater than 'y'</returns>
        public int Compare(object x, object y)
        {
            int          compareResult = 0;
            ListViewItem listviewX, listviewY;

            // Cast the objects to be compared to ListViewItem objects
            listviewX = (ListViewItem)x;
            listviewY = (ListViewItem)y;

            if (sortColumnIndex == SortColumns.SIZE)
            {
                VideoItemFileInfo listviewXVideoFileInfo = (VideoItemFileInfo)listviewX.Tag;
                VideoItemFileInfo listviewYVideoFileInfo = (VideoItemFileInfo)listviewY.Tag;

                compareResult = (listviewXVideoFileInfo.videoItemFile.Length > listviewYVideoFileInfo.videoItemFile.Length) ? 1 : -1;
            }
            else
            {
                // strings: title, type
                compareResult = objectCompare.Compare(listviewX.SubItems[sortColumnIndex].Text, listviewY.SubItems[sortColumnIndex].Text);
            }

            if (sortOrderIndex == SortOrders.DESC)
            {
                // Descending sort is selected, return negative result of compare operation
                compareResult *= -1;
            }
            return(compareResult);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        private void toolStripMenuItemOpenFolder_Click(object sender, EventArgs e)
        {
            // item unselected, so ignore
            if (listView.SelectedItems.Count == 0)
            {
                return;
            }

            VideoItemFileInfo videoItemFileInfo = (VideoItemFileInfo)listView.SelectedItems[0].Tag;
            string            directory         = videoItemFileInfo.videoInfo.videoDirectory;

            MyFile.OpenDirectory(directory);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        /// <summary>
        /// launch selected file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listView_DoubleClick(object sender, EventArgs e)
        {
            VideoItemFileInfo videoItemFileInfo = (VideoItemFileInfo)listView.SelectedItems[0].Tag;

            if (videoItemFileInfo == null)
            {
                return;
            }

            PlayFile playFile = new PlayFile();

            playFile.AddAccessToSubForms(subFormVideoForm, subFormProgress);

            playFile.Play(videoItemFileInfo.videoInfo, videoItemFileInfo.videoItemFile);

            //bubble the event up
            if (this.fileList_DoubleClicked != null)
            {
                this.fileList_DoubleClicked(sender, e);
            }
        }
Beispiel #7
0
        private void toolStripMenuItemOpen_Click(object sender, EventArgs e)
        {
            // item unselected, so ignore
            if (listView.SelectedItems.Count == 0)
            {
                return;
            }

            VideoItemFileInfo videoItemFileInfo = (VideoItemFileInfo)listView.SelectedItems[0].Tag;

            if (videoItemFileInfo == null)
            {
                return;
            }

            FileInfo fileInfo = videoItemFileInfo.GetFileInfo();

            if (fileInfo == null)
            {
                return;
            }

            MyFile.RunFile(fileInfo);
        }
Beispiel #8
0
 public void PlayFile_Completed(object sender, VideoItemFileInfo resultsVideoItemFileInfo, VideoInfo playedVideoInfo)
 {
 }
Beispiel #9
0
        protected void BackgroundWorkerRunFile_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            VideoItemFileInfo resultsVideoItemFileInfo = null;

            // First, handle the case where an exception was thrown.
            if (e.Error != null)
            {
                MyLog.Add(e.Error.ToString());
                subFormProgress.Text(e.Error.Message);
            }
            else if (e.Cancelled)
            {
                // Next, handle the case where the user canceled the operation.
                // Note that due to a race condition in the DoWork event handler, the Cancelled
                // flag may not have been set, even though CancelAsync was called.
                subFormProgress.Text("Canceled");
            }
            else
            {
                // Finally, handle the case where the operation  succeeded.
                resultsVideoItemFileInfo = (VideoItemFileInfo)e.Result;
                if (resultsVideoItemFileInfo != null)
                {
                    MyLog.Add("Played: " + resultsVideoItemFileInfo.videoItemFile.Name + " for " + resultsVideoItemFileInfo.elapsed + "s");
                }
                else
                {
                    MyLog.Add("Played: no results: " + e.ToString());
                }


                long elapsed = resultsVideoItemFileInfo.elapsed;

                // kinda simple check to make sure updating video that was played
                if (subFormVideoForm.selectedVideoInfo.files != null &&
                    subFormVideoForm.selectedVideoInfo.files.video != null &&
                    resultsVideoItemFileInfo.videoItemFile != null &&
                    subFormVideoForm.selectedVideoInfo.files.video.Name == resultsVideoItemFileInfo.videoItemFile.Name)
                {
                    subFormProgress.Text("Done playing..");

                    // MyLog.Add("elapsed:"+elapsed+" watchedAfter:" + (Config.settings.watchedAfter));

                    // if played for more than X minutes, assumed "watched"
                    if (Config.settings.markWatched && elapsed > Config.settings.watchedAfter)
                    {
                        subFormProgress.Value(90);
                        subFormProgress.Text("Updating watched..");

                        subFormVideoForm.SetWatched();

                        subFormVideoForm.SaveForm();
                    }

                    subFormProgress.Value(0);
                    subFormProgress.Text("Ready");
                }

                subFormProgress.Value(0);
                subFormProgress.Text("Ready");
            }

            // bubble the event up
            EventHandler <VideoItemFileInfo> handler = this.playFile_Completed;

            if (handler != null)
            {
                MessageBox.Show("bubble");
                handler(this, resultsVideoItemFileInfo);
            }
        }
Beispiel #10
0
 public void Run(VideoItemFileInfo videoItemFileInfo)
 {
     // Start the asynchronous operation.
     backgroundWorker.RunWorkerAsync(videoItemFileInfo);
 }