Пример #1
0
        /// <summary>
        /// Start video source.
        /// </summary>
        ///
        /// <remarks>Starts video source and return execution to caller. Video source
        /// object creates background thread and notifies about new frames with the
        /// help of <see cref="NewFrame"/> event.</remarks>
        ///
        /// <exception cref="ArgumentException">Video source is not specified.</exception>
        ///
        public void Start()
        {
            lock (_lock)
            {
                if (!VlcHelper.VlcInstalled)
                {
                    return;
                }
                if (_stoprequested)
                {
                    return;
                }

                if (!IsRunning && !_starting)
                {
                    _starting = true;
                    if (string.IsNullOrEmpty(_source))
                    {
                        throw new ArgumentException("Video source is not specified.");
                    }

                    bool init = _mFactory == null;

                    bool file = false;
                    try
                    {
                        if (File.Exists(_source))
                        {
                            file = true;
                        }
                    }
                    catch
                    {
                    }

                    if (init)
                    {
                        var args = new List <string>
                        {
                            "-I",
                            "dumy",
                            "--ignore-config",
                            "--no-osd",
                            "--disable-screensaver",
                            "--plugin-path=./plugins"
                        };
                        if (file)
                        {
                            args.Add("--file-caching=3000");
                        }

                        _mFactory = new MediaPlayerFactory(args.ToArray());
                        _mPlayer  = _mFactory.CreatePlayer <IVideoPlayer>();
                        _mPlayer.Events.PlayerPlaying += EventsPlayerPlaying;
                        _mPlayer.Events.TimeChanged   += EventsTimeChanged;
                        var fc = new Func <SoundFormat, SoundFormat>(SoundFormatCallback);
                        _mPlayer.CustomAudioRenderer.SetFormatCallback(fc);
                        var ac = new AudioCallbacks {
                            SoundCallback = SoundCallback
                        };
                        _mPlayer.CustomAudioRenderer.SetCallbacks(ac);
                        _mPlayer.CustomRenderer.SetCallback(FrameCallback);
                        _mPlayer.CustomRenderer.SetExceptionHandler(Handler);
                        _mPlayer.CustomAudioRenderer.SetExceptionHandler(Handler);
                    }



                    if (file)
                    {
                        _mMedia = _mFactory.CreateMedia <IMediaFromFile>(_source);
                    }
                    else
                    {
                        _mMedia = _mFactory.CreateMedia <IMedia>(_source);
                    }

                    _mMedia.AddOptions(_arguments);

                    _mMedia.Events.DurationChanged -= EventsDurationChanged;
                    _mMedia.Events.StateChanged    -= EventsStateChanged;
                    _mMedia.Events.DurationChanged += EventsDurationChanged;
                    _mMedia.Events.StateChanged    += EventsStateChanged;

                    _needsSetup = true;
                    _mPlayer.CustomRenderer.SetFormat(new BitmapFormat(FormatWidth, FormatHeight, ChromaType.RV24));

                    _mPlayer.Open(_mMedia);
                    _mMedia.Parse(true);

                    _framesReceived = 0;
                    Duration        = Time = 0;
                    LastFrame       = DateTime.MinValue;
                    _mPlayer.Play();

                    //check if file source (isseekable in _mPlayer is not reliable)
                    Seekable = false;
                    try
                    {
                        var p = Path.GetFullPath(_mMedia.Input);
                        Seekable = !String.IsNullOrEmpty(p);
                    }
                    catch (Exception)
                    {
                        Seekable = false;
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Start video source.
        /// </summary>
        ///
        /// <remarks>Starts video source and return execution to caller. Video source
        /// object creates background thread and notifies about new frames with the
        /// help of <see cref="NewFrame"/> event.</remarks>
        ///
        /// <exception cref="ArgumentException">Video source is not specified.</exception>
        ///
        public void Start()
        {
            lock (_lock)
            {
                if (!VlcHelper.VlcInstalled)
                {
                    return;
                }
                if (_stoprequested)
                {
                    return;
                }
                if (!IsRunning && !_starting)
                {
                    _starting = true;
                    // check source
                    if (string.IsNullOrEmpty(_source))
                    {
                        throw new ArgumentException("Audio source is not specified.");
                    }

                    bool init = _mFactory == null;
                    if (init)
                    {
                        _mFactory = new MediaPlayerFactory();
                        _mPlayer  = _mFactory.CreatePlayer <IVideoPlayer>();
                        _mPlayer.Events.PlayerPlaying += EventsPlayerPlaying;
                        _mPlayer.Events.TimeChanged   += EventsTimeChanged;
                        var fc = new Func <SoundFormat, SoundFormat>(SoundFormatCallback);
                        _mPlayer.CustomAudioRenderer.SetFormatCallback(fc);
                        var ac = new AudioCallbacks {
                            SoundCallback = SoundCallback
                        };
                        _mPlayer.CustomAudioRenderer.SetCallbacks(ac);
                        _mPlayer.CustomAudioRenderer.SetExceptionHandler(Handler);
                    }

                    bool file = false;
                    try
                    {
                        if (File.Exists(_source))
                        {
                            file = true;
                        }
                    }
                    catch
                    {
                    }
                    if (file)
                    {
                        _mMedia = _mFactory.CreateMedia <IMediaFromFile>(_source);
                    }
                    else
                    {
                        _mMedia = _mFactory.CreateMedia <IMedia>(_source);
                    }

                    _mMedia.AddOptions(_arguments);

                    _mMedia.Events.DurationChanged -= EventsDurationChanged;
                    _mMedia.Events.StateChanged    -= EventsStateChanged;
                    _mMedia.Events.DurationChanged += EventsDurationChanged;
                    _mMedia.Events.StateChanged    += EventsStateChanged;

                    _needsSetup = true;

                    _mPlayer.Open(_mMedia);
                    _mMedia.Parse(true);
                    _framesReceived = 0;
                    Duration        = Time = 0;
                    LastFrame       = DateTime.MinValue;
                    _mPlayer.Play();

                    //check if file source (isseekable in _mPlayer is not reliable)
                    Seekable = false;
                    try
                    {
                        var p = Path.GetFullPath(_mMedia.Input);
                        Seekable = !String.IsNullOrEmpty(p);
                    }
                    catch (Exception)
                    {
                        Seekable = false;
                    }
                }
            }
        }