Exemplo n.º 1
0
        private void PlaylistThread()
        {
            bool playing = true;

            while (playing)
            {
                Shot   s            = playlist.Dequeue();
                bool   playFinished = false;
                string filename     = s.FileLocation;

                if (filename != null)
                {
                    VLCMediaControl.MediaPlayer.EncounteredError += (sender, e) =>
                    {
                        MediaOutputTextBox.AppendText("VLC Error");
                        playFinished = true;
                    };

                    VLCMediaControl.MediaPlayer.EndReached += (sender, e) =>
                    {
                        playFinished = true;
                    };

                    VLCMediaControl.MediaPlayer.Play(new FileInfo(filename));

                    // Playback from stream example:
                    //VLCMediaControl.MediaPlayer.Play(new Uri("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi"));
                    // Playback from file example:
                    //VLCMediaControl.MediaPlayer.Play(new FileInfo(@"..\..\..\..\Media\FateApocrypha.mp4"));

                    while (!playFinished)
                    {
                        Thread.Sleep(TimeSpan.FromMilliseconds(100));
                    }

                    if (playlist.Count == 0)
                    {
                        playing = false;
                    }
                }
            }
        }
Exemplo n.º 2
0
        // VLC.NET has no playlist functionality, so we make our own by
        // unloading a queue in another thread
        private void OnPlayButtonClick(object sender, RoutedEventArgs e)
        {
            VLCCleanUp();
            StringBuilder sb = new StringBuilder();

            // Get selected collection of shot to play
            var vm = (ViewModel)this.DataContext;

            if (vm != null)
            {
                if (vm.Solution != null)
                {
                    if (vm.Solution.Count > vm.ShotCollectionSelectedId)
                    {
                        var shots = vm.Solution[vm.ShotCollectionSelectedId];

                        if (shots.Shots.Count > 0)
                        {
                            // Construct playlist
                            //bool flipFlop = true;
                            playlist.Clear();
                            //foreach (var s in shots.Shots)
                            //{
                            //   // Since we lack proper content, use samples for now
                            //   if (flipFlop)
                            //   {
                            //      s.FileLocation = System.IO.Path.Combine(Environment.CurrentDirectory, "Media\\FateApocrypha.mp4");
                            //   }
                            //   else
                            //   {
                            //      s.FileLocation = System.IO.Path.Combine(Environment.CurrentDirectory, "Media\\MaidensSalvationTheory.mp4");
                            //   }
                            //   flipFlop = !flipFlop;
                            //   playlist.Enqueue(s);
                            //}

                            // Output shots to be played to user
                            sb.Append("Playing shots: ");
                            foreach (var s in shots.Shots)
                            {
                                sb.Append(String.Format("{0}, ", s.ShotId));
                            }
                            sb.Append("\n");

                            // Start playing in different thread
                            //ThreadStart threadStart = new ThreadStart(PlaylistThread);
                            //Thread thread = new Thread(threadStart);
                            //thread.Start();
                        }
                        else
                        {
                            sb.AppendFormat("Error: ViewModel.Solution.Shots[{0}].Count is < 1",
                                            vm.ShotCollectionSelectedId);
                        }
                    }
                    else
                    {
                        sb.AppendFormat("Error: ViewModel.Solution is size {0} while ViewModel.ShotCollectionSelectedId is {1}\n",
                                        vm.Solution.Count, vm.ShotCollectionSelectedId);
                    }
                }
                else
                {
                    sb.AppendLine("Error: ViewModel.Solution is null");
                }
            }
            else
            {
                sb.AppendLine("Error: ViewModel is null");
            }

            MediaOutputTextBox.AppendText(sb.ToString());
        }