Example #1
0
        /// <summary>
        ///     Load a media by file path and options.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="options"></param>
        public void LoadMediaWithOptions(string path, params string[] options)
        {
            if (VlcMediaPlayer == null)
            {
                throw new InvalidOperationException("VlcMediaPlayer doesn't have initialize.");
            }

            if (!(File.Exists(path) || Path.GetFullPath(path).IsDriveRootDirectory()))
            {
                throw new FileNotFoundException(string.Format("Not found: {0}", path), path);
            }

            if (VlcMediaPlayer.Media != null)
            {
                VlcMediaPlayer.Media.Dispose();
            }

            if (_context != null)
            {
                _context.Dispose();
                _context = null;
            }

            VlcMediaPlayer.Media = VlcMediaPlayer.VlcInstance.CreateMediaFromPath(path);
            VlcMediaPlayer.Media.AddOption(options);
            VlcMediaPlayer.Media.ParseAsync();

            _isDVD = VlcMediaPlayer.Media.Mrl.IsDriveRootDirectory();
        }
Example #2
0
        private uint VideoFormatCallback(ref IntPtr opaque, ref uint chroma, ref uint width, ref uint height,
                                         ref uint pitches, ref uint lines)
        {
            Debug.WriteLine(String.Format("Initialize Video Content : {0}x{1}", width, height));
            if (_context == null)
            {
                uint tmpWidth  = width;
                uint tmpHeight = height;

                if (DisplayThreadDispatcher == null)
                {
                    throw new InvalidOperationException("VlcPlayer not be ready, if you want to use VlcPlay no in XAML, please read this Wiki: \"https://github.com/higankanshi/Meta.Vlc/wiki/Use-VlcPlayer-with-other-controls\".");
                }

                DisplayThreadDispatcher.Invoke(DispatcherPriority.Normal,
                                               new Action(() => { _context = new VideoDisplayContext(tmpWidth, tmpHeight, ChromaType.RV32); }));
            }
            chroma      = (uint)_context.ChromaType;
            width       = (uint)_context.Width;
            height      = (uint)_context.Height;
            pitches     = (uint)_context.Stride;
            lines       = (uint)_context.Height;
            VideoSource = _context.Image;
            return((uint)_context.Size);
        }
Example #3
0
        private uint VideoFormatCallback(ref IntPtr opaque, ref uint chroma, ref uint width, ref uint height,
                                         ref uint pitches, ref uint lines)
        {
            Debug.WriteLine(String.Format("Initialize Video Content : {0}x{1}", width, height));

            var videoFormatChangingArgs = new VideoFormatChangingEventArgs(width, height, ChromaType.RV32);

            if (VideoFormatChanging != null)
            {
                VideoFormatChanging(this, videoFormatChangingArgs);
            }

            if (_context == null || videoFormatChangingArgs.Width != _context.Width || videoFormatChangingArgs.Height != _context.Height)
            {
                if (DisplayThreadDispatcher == null)
                {
                    throw new NullReferenceException(String.Format("Image = {0}, Image.SeparateThreadDispatcher = {1}, ThreadSeparatedImage.CommonDispatcher = {2}", Image, Image.SeparateThreadDispatcher, ThreadSeparatedImage.CommonDispatcher));
                }
                DisplayThreadDispatcher.Invoke(DispatcherPriority.Normal,
                                               new Action(() =>
                {
                    if (_context != null)
                    {
                        _context.Dispose();
                    }
                    _context    = new VideoDisplayContext(videoFormatChangingArgs.Width, videoFormatChangingArgs.Height, videoFormatChangingArgs.ChromaType);
                    VideoSource = null;
                }));
            }

            _context.IsAspectRatioChecked = false;
            chroma  = (uint)_context.ChromaType;
            width   = (uint)_context.Width;
            height  = (uint)_context.Height;
            pitches = (uint)_context.Stride;
            lines   = (uint)_context.Height;
            return((uint)_context.Size);
        }
        private uint VideoFormatCallback(void **opaque, byte *chroma, uint *width, uint *height, uint *pitches,
                                         uint *lines)
        {
            Debug.WriteLine($"Initialize Video Content : {*width}x{*height}");

            var videoFormatChangingArgs = new VideoFormatChangingEventArgs(*width, *height, ChromaType.RV32);

            VideoFormatChanging?.Invoke(this, videoFormatChangingArgs);

            if (_context == null || videoFormatChangingArgs.Width != _context.Width ||
                videoFormatChangingArgs.Height != _context.Height)
            {
                if (DisplayThreadDispatcher == null)
                {
                    throw new NullReferenceException(
                              $"Image = {Image}, Image.SeparateThreadDispatcher = {Image.SeparateThreadDispatcher}, ThreadSeparatedImage.CommonDispatcher = {ThreadSeparatedImage.CommonDispatcher}");
                }
                DisplayThreadDispatcher.Invoke(DispatcherPriority.Normal,
                                               new Action(() =>
                {
                    if (_context != null)
                    {
                        _context.Dispose();
                    }
                    _context = new VideoDisplayContext(videoFormatChangingArgs.Width,
                                                       videoFormatChangingArgs.Height, videoFormatChangingArgs.ChromaType);
                    VideoSource = null;
                }));
            }

            _context.IsAspectRatioChecked = false;
            *(uint *)chroma = (uint)_context.ChromaType;
            *width   = (uint)_context.Width;
            *height  = (uint)_context.Height;
            *pitches = (uint)_context.Stride;
            *lines   = (uint)_context.Height;
            return((uint)_context.Size);
        }
Example #5
0
        /// <summary>
        ///     Load a media by uri.
        /// </summary>
        /// <param name="uri"></param>
        public void LoadMedia(Uri uri)
        {
            if (VlcMediaPlayer == null)
            {
                throw new InvalidOperationException("VlcMediaPlayer doesn't have initialize.");
            }

            if (VlcMediaPlayer.Media != null)
            {
                VlcMediaPlayer.Media.Dispose();
            }

            if (_context != null)
            {
                _context.Dispose();
                _context = null;
            }

            VlcMediaPlayer.Media = VlcMediaPlayer.VlcInstance.CreateMediaFromLocation(uri.ToHttpEncodeString());
            VlcMediaPlayer.Media.ParseAsync();

            _isDVD = VlcMediaPlayer.Media.Mrl.IsDriveRootDirectory();
        }
Example #6
0
        //note: if you pass a string instead of a Uri, LoadMedia will see if it is an absolute Uri, else will treat it as a file path
        /// <summary>
        ///     Load a media by file path.
        /// </summary>
        /// <param name="path"></param>
        public void LoadMedia(string path)
        {
            if (VlcMediaPlayer == null)
            {
                throw new InvalidOperationException("VlcMediaPlayer doesn't have initialize.");
            }

            Uri uri;

            if (Uri.TryCreate(path, UriKind.Absolute, out uri))
            {
                LoadMedia(uri);
                return;
            }

            if (!(File.Exists(path) || Path.GetFullPath(path).IsDriveRootDirectory()))
            {
                throw new FileNotFoundException(string.Format("Not found: {0}", path), path);
            }

            if (VlcMediaPlayer.Media != null)
            {
                VlcMediaPlayer.Media.Dispose();
            }

            if (_context != null)
            {
                _context.Dispose();
                _context = null;
            }

            VlcMediaPlayer.Media = VlcMediaPlayer.VlcInstance.CreateMediaFromPath(path);
            VlcMediaPlayer.Media.ParseAsync();

            _isDVD = VlcMediaPlayer.Media.Mrl.IsDriveRootDirectory();
        }
Example #7
0
        private uint VideoFormatCallback(ref IntPtr opaque, ref uint chroma, ref uint width, ref uint height,
            ref uint pitches, ref uint lines)
        {
            Debug.WriteLine(String.Format("Initialize Video Content : {0}x{1}", width, height));
            if (_context == null)
            {
                uint tmpWidth = width;
                uint tmpHeight = height;

                if (DisplayThreadDispatcher == null)
                {
                    throw new InvalidOperationException("VlcPlayer not be ready, if you want to use VlcPlay no in XAML, please read this Wiki: \"https://github.com/higankanshi/Meta.Vlc/wiki/Use-VlcPlayer-with-other-controls\".");
                }

                DisplayThreadDispatcher.Invoke(DispatcherPriority.Normal,
                    new Action(() => { _context = new VideoDisplayContext(tmpWidth, tmpHeight, ChromaType.RV32); }));
            }
            chroma = (uint) _context.ChromaType;
            width = (uint) _context.Width;
            height = (uint) _context.Height;
            pitches = (uint) _context.Stride;
            lines = (uint) _context.Height;
            VideoSource = _context.Image;
            return (uint) _context.Size;
        }