예제 #1
0
 /// <summary>
 /// Plays the current media
 /// </summary>
 public void Play()
 {
     if (Player.State == MediaStates.Ended)
     {
         var V = Volume;
         InitPlayer();
         Volume = V;
         Player.Play();
     }
     else if (Player.State != MediaStates.Playing)
     {
         Player.Play();
         OnStarted(this, EventType.Start);
     }
 }
예제 #2
0
        private bool StartVideoRecording(string path)
        {
            bool videoRecordingStarted = false;

            path += "\\"; //ensure that it's a folder
            string savePath = string.Format("{0}{1:yyyy_MM_dd_HH-mm-ss}.{2}", path, DateTime.Now, _fileExtensionVideo);

            try
            {
                //ensure that the wanted directory exists
                Directory.CreateDirectory(path);

                //ensure that there isn't a second recording saved at the same time (with the same file name)
                if (!File.Exists(savePath))
                {
                    string[] options = { ":network-caching=100",
                                         ":sout=#duplicate{dst=std{access=file,mux=" + _fileExtensionVideo + ",dst='" + savePath + "'},dst=display}" };
                    _vlcMediaPlayer.Play(_streamUrl, options);

                    //wait for opening
                    while (_vlcMediaPlayer.State == MediaStates.NothingSpecial)
                    {
                    }
                    while (_vlcMediaPlayer.State == MediaStates.Opening)
                    {
                    }

                    //verify if not playing
                    if (_vlcMediaPlayer.State != MediaStates.Playing)
                    {
                        _vlcMediaPlayer.Stop();
                        MessageBox.Show("Too many players.", "Recording error.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        //delete the corrupted file from the video folder
                        File.Delete(savePath);
                    }
                    else//everything is fine
                    {
                        videoRecordingStarted = true;
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Recording error.", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(videoRecordingStarted);
        }
예제 #3
0
        public void AlarmActivated( )
        {
            IsHandlerBusy = true;
            _sleepFor     = _recordForSeconds;
            var saveTo = new FileInfo(Path.Combine(_videoDumpDirectory, $"{DateTime.Now.ToFileDateTime()}.mpg"));

            if (!Directory.Exists(saveTo.DirectoryName))
            {
                Directory.CreateDirectory(saveTo.DirectoryName);
            }


            var player = new VlcMediaPlayer(new System.IO.DirectoryInfo(_settings.VlcFolder));

            player.SetMedia(_camera.RtspSource, $":sout=#transcode{{acodec=mp3}}:duplicate{{dst=std{{access=file,mux=ts,dst=\'{saveTo.FullName}\'}}}}");
            player.EncounteredError += PlayerEncounteredError;
            _logger.Write(LogEventLevel.Information, $"Saving video to {saveTo.FullName} for {_recordForSeconds} ");
            player.Play();
            while (_sleepFor > 0)
            {
                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
                _sleepFor--;
            }

            _logger.Write(LogEventLevel.Information, $"Stopping log write to {saveTo.FullName}");
            player.Stop();
            IsHandlerBusy = false;
        }
 public void IsStoppedTest()
 {
     player = instance.CreatePlayer(BaseTestFilePath + "n900_extremely_short.avi");
     player.Play();
     player.Stop();
     Assert.IsTrue(player.IsStopped);
 }
예제 #5
0
        /// <summary>
        ///     Replay media.
        /// </summary>
        public void Replay()
        {
            ThrowIfNotInitialize();

            StopInternal();
            VlcMediaPlayer.Play();
        }
예제 #6
0
        public async Task <VideoAudioInfo> Execute(Stream thumbnailStream)
        {
            ThumbnailStream = thumbnailStream;
            LibVlcManager.LoadLibVlc(AppDomain.CurrentDomain.BaseDirectory + @"..\..\libvlc");
            Vlc vlc = new Vlc(new[] { "-I", "dummy", "--ignore-config", "--no-video-title" });

            Console.WriteLine($"LibVlcManager: {LibVlcManager.GetVersion()}s");
            mediaPlayer = vlc.CreateMediaPlayer();
            mediaPlayer.SetVideoDecodeCallback(LockCB, unLockCB, DisplayCB, IntPtr.Zero);
            mediaPlayer.SetVideoFormatCallback(VideoFormatCallback, VideoCleanupCallback);
            mediaPlayer.Playing += MediaPlayer_Playing;
            mediaPlayer.Media    = vlc.CreateMediaFromLocation(FilePath);

            await Task.Run(() =>
            {
                mediaPlayer.Play();
                mediaPlayer.IsMute = true;
                Stopwatch s        = new Stopwatch();
                s.Start();
                while (waiting)
                {
                    Thread.Sleep(100);
                }
                s.Stop();
                TimeSpan sec = new TimeSpan(s.ElapsedTicks);
                Console.WriteLine(sec.ToString());
                mediaPlayer.Dispose();
                vlc.Dispose();
            });

            _VideoAudioInfo.Resolution = JsonConvert.SerializeObject(_VideoResolution);
            //_VideoAudioInfo.Thumbnail = ThumbnailStream;
            return(_VideoAudioInfo);
        }
예제 #7
0
        private void Record(string source, string directory, string pattern)
        {
            var filename = Path.Combine(directory, string.Format(pattern, DateTime.Now.ToString("yyyyMMddHHmmss")));

            var opts   = $":sout=#std{{access=file,dst='{filename}'}}";
            var player = new VlcMediaPlayer(new DirectoryInfo(ConfigurationManager.AppSettings["VlcDirectory"]), new[] { "--rtsp-tcp" });

            player.SetMedia(source, opts);
            player.EncounteredError += (sender, eventArgs) =>
            {
                player.Dispose();
                Upload(filename);
            };
            player.Play();
            var recordTimer = new Timer((duration + 2) * 1000);

            recordTimer.AutoReset = false;
            recordTimer.Elapsed  += (sender, eventArgs) =>
            {
                player.Stop();
                player.Dispose();
                recordTimer.Dispose();
                Console.WriteLine($"recorded {filename}");
                Upload(filename);
            };
            Console.WriteLine($"start recording to {filename}");
            recordTimer.Start();
        }
예제 #8
0
        private void VlcMediaPlayerMediaStateChanged(object sender, MediaStateChangedEventArgs e)
        {
            if (_disposing || _isStopping)
            {
                return;
            }

            Debug.WriteLine($"StateChanged : {e.State}");

            Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { StateChanged?.Invoke(this, e); }));

            if (e.State == MediaState.Ended)
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    switch (EndBehavior)
                    {
                    case EndBehavior.Nothing:

                        break;

                    case EndBehavior.Stop:
                        Stop();
                        break;

                    case EndBehavior.Repeat:
                        StopInternal();
                        VlcMediaPlayer.Play();
                        break;
                    }
                }));
            }
        }
예제 #9
0
        private static void Main(string[] args)
        {
            var file = new FileInfo(@"path");

            var currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);

            // Default installation path of VideoLAN.LibVLC.Windows
            var libDirectory =
                new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));

            using (var mediaPlayer = new VlcMediaPlayer(libDirectory))
            {
                // Options without any encode
                var mediaOptions = new[]
                {
                    ":sout=#rtp{sdp=rtsp://192.168.1.162:8008/test}",
                    ":sout-keep"
                };

                mediaPlayer.SetMedia(file, mediaOptions);

                mediaPlayer.Play();

                Console.WriteLine("Streaming on rtsp://192.168.1.162:8008/test");
                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
            }
        }
예제 #10
0
        private void VlcMediaPlayerEndReached(object sender, ObjectEventArgs <MediaState> e)
        {
            if (_disposing || _isStopping)
            {
                return;
            }

            Dispatcher.BeginInvoke(new Action(() =>
            {
                switch (EndBehavior)
                {
                case EndBehavior.Nothing:

                    break;

                case EndBehavior.Stop:
                    Stop();
                    break;

                case EndBehavior.Repeat:
                    StopInternal();
                    VlcMediaPlayer.Play();
                    break;
                }

                _isPublished = false;
                if (Win32Api.SetThreadExecutionState(Win32Api.ES_CONTINUOUS) == null)
                {
                    // try XP variant as well just to make sure
                    Win32Api.SetThreadExecutionState(Win32Api.ES_CONTINUOUS);
                }
            }));
        }
예제 #11
0
        private void VlcMediaPlayerEndReached(object sender, ObjectEventArgs <MediaState> e)
        {
            if (_disposing || _isStopping)
            {
                return;
            }

            Dispatcher.BeginInvoke(new Action(() =>
            {
                switch (EndBehavior)
                {
                case EndBehavior.Nothing:

                    break;

                case EndBehavior.Stop:
                    Stop();
                    break;

                case EndBehavior.Repeat:
                    StopInternal();
                    VlcMediaPlayer.Play();
                    break;
                }
            }));
        }
예제 #12
0
파일: VlcControl.cs 프로젝트: metoer/wpf
 public void Play()
 {
     //EndInit();
     if (myVlcMediaPlayer != null)
     {
         myVlcMediaPlayer.Play();
     }
 }
        public void VolumeTest()
        {
            player = instance.CreatePlayer(BaseTestFilePath + "n900_extremely_short.avi");
            player.Play();
            int currentVolume = player.Volume;

            player.Volume = currentVolume + 10;
            Assert.IsTrue(currentVolume < player.Volume);
        }
예제 #14
0
 public void Play()
 {
     // if player and current radio exists, set it and start playing
     if (_mediaPlayer != null && Status.CurrentRadio != null)
     {
         _mediaPlayer.SetMedia(Status.CurrentRadio.Url);
         _mediaPlayer.Play();
     }
 }
예제 #15
0
        /// <summary>
        ///     Replay media.
        /// </summary>
        public void Replay()
        {
            if (VlcMediaPlayer == null)
            {
                throw new InvalidOperationException("VlcMediaPlayer doesn't have initialize.");
            }

            StopInternal();
            VlcMediaPlayer.Play();
        }
예제 #16
0
        /// <summary>
        ///     Play media.
        /// </summary>
        public void Play()
        {
            ThrowIfNotInitialize();

            if (_context != null)
            {
                VideoSource = _context.Image;
            }
            VlcMediaPlayer.Play();
        }
예제 #17
0
        /// <summary>
        ///     Replay media.
        /// </summary>
        public void Replay()
        {
            if (VlcMediaPlayer == null)
            {
                return;
            }

            StopInternal();
            VlcMediaPlayer.Play();
        }
예제 #18
0
 public void StartStreaming()
 {
     if (isOpening)
     {
         return;
     }
     ResetPlayer();
     isOpening = true;
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsPlaying)));
     VlcMediaPlayer.Play();
 }
예제 #19
0
        public void SubtitleTracksTest()
        {
            VlcInstance    instance = null;
            VlcMediaPlayer player   = null;

            instance = new VlcInstance(VlcInstanceArgs);
            player   = instance.CreatePlayer(BaseTestFilePath + "mewmew-vorbis-ssa.mkv");
            Assert.IsInstanceOfType(player, typeof(VlcMediaPlayer));
            player.Play();
            Assert.AreEqual(player.Media.Length, 58183);
            ArrayList subtitles = player.Media.SubtitleTracks;

            Assert.AreEqual(subtitles.Count, 17);

            Assert.AreEqual("Disable", ((VLCLibrary.libvlc_track_description_t)subtitles[0]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(0));
            Assert.AreEqual("Track 1 - [English]", ((VLCLibrary.libvlc_track_description_t)subtitles[1]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(1));
            Assert.AreEqual("Track 2 - [Nederlands]", ((VLCLibrary.libvlc_track_description_t)subtitles[2]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(2));
            Assert.AreEqual("Track 3 - [English]", ((VLCLibrary.libvlc_track_description_t)subtitles[3]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(3));
            Assert.AreEqual("Track 4 - [Suomi]", ((VLCLibrary.libvlc_track_description_t)subtitles[4]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(4));
            Assert.AreEqual("Track 5 - [Français]", ((VLCLibrary.libvlc_track_description_t)subtitles[5]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(5));
            Assert.AreEqual("Track 6 - [Deutsch]", ((VLCLibrary.libvlc_track_description_t)subtitles[6]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(6));
            Assert.AreEqual("Track 7 - [עברית]", ((VLCLibrary.libvlc_track_description_t)subtitles[7]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(7));
            Assert.AreEqual("Track 8 - [Magyar]", ((VLCLibrary.libvlc_track_description_t)subtitles[8]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(8));
            Assert.AreEqual("Track 9 - [Italiano]", ((VLCLibrary.libvlc_track_description_t)subtitles[9]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(9));
            Assert.AreEqual("Track 10 - [日本語]", ((VLCLibrary.libvlc_track_description_t)subtitles[10]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(10));
            Assert.AreEqual("Track 11 - [Norsk]", ((VLCLibrary.libvlc_track_description_t)subtitles[11]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(11));
            Assert.AreEqual("Track 12 - [Polski]", ((VLCLibrary.libvlc_track_description_t)subtitles[12]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(12));
            Assert.AreEqual("Track 13 - [Português]", ((VLCLibrary.libvlc_track_description_t)subtitles[13]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(13));
            Assert.AreEqual("Track 14 - [Русский]", ((VLCLibrary.libvlc_track_description_t)subtitles[14]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(14));
            Assert.AreEqual("Track 15 - [Español]", ((VLCLibrary.libvlc_track_description_t)subtitles[15]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(15));
            Assert.AreEqual("Track 16 - [Svenska]", ((VLCLibrary.libvlc_track_description_t)subtitles[16]).psz_name);
            Assert.IsTrue(player.ChangeSubtitleTrack(16));

            player.Stop();
            player.Dispose();

            instance.Dispose();
        }
예제 #20
0
        public void AspectRatioTest()
        {
            VlcInstance    instance = new VlcInstance(VlcInstanceArgs);
            VlcMediaPlayer player   = instance.CreatePlayer(BaseTestFilePath + "n900_extremely_short.avi");

            player.Play();
            Assert.AreEqual("1.66", player.Media.AspectRatio);
            player.Stop();
            player.Dispose();
            instance.Dispose();
        }
        public void ChangeSubtitleTrackTest()
        {
            VlcInstance    instance = new VlcInstance(VlcInstanceArgs);
            VlcMediaPlayer player   = instance.CreatePlayer(BaseTestFilePath + "mewmew-vorbis-ssa.mkv");

            player.Play();

            int currentSubtitleTrackId = VLCLibrary.Instance.video_get_spu(player.Handle);

            player.ChangeSubtitleTrack(3);
            Assert.AreNotEqual(currentSubtitleTrackId, VLCLibrary.Instance.video_get_spu(player.Handle));
        }
예제 #22
0
        /// <summary>
        /// Extract a still frame from a video
        /// </summary>
        /// <param name="startAt"></param>
        /// <returns></returns>
        public Bitmap GetFrame(double startAt)
        {
            FileInfo file  = new FileInfo(this.FileName);
            FileInfo file2 = new FileInfo(Path.GetTempPath() + "\\snapshot.png");

            if (File.Exists(file2.FullName))
            {
                File.Delete(file2.FullName);
            }
            VlcMediaPlayer mediaPlayer = new VlcMediaPlayer(VideoTools.GetLibVlcLocation(), VideoTools.GetVlcOptionsHeadless(startAt));

            try
            {
                bool done         = false;
                bool takesnapshot = true;
                mediaPlayer.PositionChanged += (sender, e) =>
                {
                    if (takesnapshot)
                    {
                        takesnapshot = false; // avoid re-entry
                        mediaPlayer.TakeSnapshot(file2);
                        done = true;
                    }
                };
                mediaPlayer.SetMedia(file);
                mediaPlayer.Play();
                DateTime start = DateTime.UtcNow;
                while (!done) // wait for video to start, timeout 3 seconds
                {
                    if ((DateTime.UtcNow - start).TotalMilliseconds >= 3000)
                    {
                        throw (new Exception("Error when starting video!"));
                    }
                }
                mediaPlayer.Dispose();
            }
            catch (Exception exc)
            {
                mediaPlayer.Dispose();
                throw (new Exception("VLC library error:" + exc.Message));
            }

            if (File.Exists(file2.FullName))
            {
                Bitmap pic = new Bitmap(file2.FullName);
                return(pic);
            }
            else
            {
                throw (new Exception("Error while extracting snapshot from video!"));
            }
        }
예제 #23
0
        /// <summary>
        ///     Play media.
        /// </summary>
        public void Play()
        {
            if (VlcMediaPlayer == null)
            {
                return;
            }

            if (_context != null)
            {
                VideoSource = _context.Image;
            }
            VlcMediaPlayer.Play();
        }
예제 #24
0
        public void VlcMediaConstructorTest()
        {
            VlcInstance    instance = null;
            VlcMediaPlayer player   = null;

            instance = new VlcInstance(VlcInstanceArgs);
            player   = instance.CreatePlayer(BaseTestFilePath + "n900_extremely_short.avi");
            Assert.IsInstanceOfType(player, typeof(VlcMediaPlayer));
            player.Play();
            Assert.AreEqual(player.Media.Length, 5000);
            player.Stop();
            player.Dispose();
        }
예제 #25
0
        /// <summary>
        ///     Play media.
        /// </summary>
        public void Play()
        {
            if (VlcMediaPlayer == null)
            {
                throw new InvalidOperationException("VlcMediaPlayer doesn't have initialize.");
            }

            if (_context != null)
            {
                VideoSource = _context.Image;
            }
            VlcMediaPlayer.Play();
        }
예제 #26
0
        public void Play(Uri playPathUri, string[] mediaOptions)
        {
            try
            {
                _vlcMediaPlayer.SetMedia(playPathUri, mediaOptions);

                _vlcMediaPlayer.Play();
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                PlayFinished = true;
            }
        }
예제 #27
0
        static void Main(string[] args)
        {
            try {
                var info = new DirectoryInfo(Directory.GetCurrentDirectory() + "//vlc");
                Console.WriteLine(info.FullName);
                var player = new VlcMediaPlayer(info);

                player.SetMedia(Directory.GetCurrentDirectory() + "//September.m4a");
                player.Play();
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
예제 #28
0
        public static async Task <bool> PlayAsync(this VlcMediaPlayer player, int millisecondsTimeout, CancellationToken cancellationToken = default)
        {
            await Task.Run(() =>
            {
                player.Play();
                while (player.State != MediaStates.Playing && player.State != MediaStates.Error)
                {
                    continue;
                }
            }, cancellationToken).WithTimeout(millisecondsTimeout);

            await Task.Delay(1);

            return(player.State == MediaStates.Playing);
        }
예제 #29
0
        private void Playb_Click(object sender, EventArgs e)
        {
            player.Play();
            //throw new Exception("watch");
            // console.Text = player.playerState;

            //   console.Text = player.AudioTrackCount.ToString();

            /*
             * VlcMedia c = player.getMedia();
             *     Int64 it = c.duration;
             *     console.Text = it.ToString();
             *     c.Dispose();
             */
        }
예제 #30
0
        public void LengthTest()
        {
            VlcInstance    instance = null;
            VlcMediaPlayer player   = null;

            instance = new VlcInstance(VlcInstanceArgs);
            player   = instance.CreatePlayer(BaseTestFilePath + "mewmew-vorbis-ssa.mkv");
            Assert.IsInstanceOfType(player, typeof(VlcMediaPlayer));
            player.Play();
            Assert.AreEqual(player.Media.Length, 58183);

            player.Stop();
            player.Dispose();

            instance.Dispose();
        }