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 (!(File.Exists(path) || Path.GetFullPath(path).IsDriveRootDirectory()))
            {
                throw new FileNotFoundException(String.Format("Not found: {0}", path), path);
            }

            if (VlcMediaPlayer == null)
            {
                return;
            }

            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
        //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)
        {
            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 == null)
            {
                return;
            }

            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 #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));
     if (_context == null)
     {
         _context = new VideoDisplayContext(width, height, ChromaType.RV32);
     }
     chroma  = (uint)_context.ChromaType;
     width   = (uint)_context.Width;
     height  = (uint)_context.Height;
     pitches = (uint)_context.Stride;
     lines   = (uint)_context.Height;
     Dispatcher.Invoke(new Action(() => { VideoSource = _context.Image; }));
     return((uint)_context.Size);
 }
Example #4
0
        /// <summary>
        ///     Load a media by uri.
        /// </summary>
        /// <param name="uri"></param>
        public void LoadMedia(Uri uri)
        {
            if (VlcMediaPlayer == null)
            {
                return;
            }

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

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

            VlcMediaPlayer.Media = VlcMediaPlayer.VlcInstance.CreateMediaFromLocation(uri.ToString());
            VlcMediaPlayer.Media.ParseAsync();
            _isDVD = VlcMediaPlayer.Media.Mrl.IsDriveRootDirectory();
        }
Example #5
0
        /// <summary>
        ///     Load a media by uri and options.
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="options"></param>
        public void LoadMediaWithOptions(Uri uri, params string[] options)
        {
            if (VlcMediaPlayer == null)
            {
                return;
            }

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

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

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

            _isDVD = VlcMediaPlayer.Media.Mrl.IsDriveRootDirectory();
        }
Example #6
0
        public async System.Threading.Tasks.Task StopAsync()
        {
            if (VlcMediaPlayer.Media == null) return;

            VlcMediaPlayer.SetVideoDecodeCallback(null, null, null, IntPtr.Zero);
            VlcMediaPlayer.SetVideoFormatCallback(null, null);

            if (VlcMediaPlayer.State == MediaState.Playing)
            {
                _stopping = true;
                VlcMediaPlayer.Pause();
            }

            await System.Threading.Tasks.Task.Run(() =>
            {
                while (_stopping)
                {

                }
            }).ContinueWith((a) =>
            {
                VlcMediaPlayer.Stop();

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

            });
            VideoSource = null;
        }
Example #7
0
        public IAsyncResult Stop()
        {
            Action action = new Action(() =>
            {
                if (VlcMediaPlayer.Media == null) return;

                VlcMediaPlayer.SetVideoDecodeCallback(null, null, null, IntPtr.Zero);
                VlcMediaPlayer.SetVideoFormatCallback(null, null);

                if (VlcMediaPlayer.State == MediaState.Playing)
                {
                    _stopping = true;
                    VlcMediaPlayer.Pause();
                }

                while (_stopping)
                {

                }
            });

            return action.BeginInvoke((aresult) =>
            {
                VlcMediaPlayer.Stop();
                if (_context != null) _context.Dispose();
                _context = null;

                Dispatcher.BeginInvoke(new Action(() => VideoSource = null));
                action.EndInvoke(aresult);
            }, null);
        }
Example #8
0
        uint VideoFormatCallback(ref IntPtr opaque, ref uint chroma, ref uint width, ref uint height, ref uint pitches, ref uint lines)
        {
            _context = new VideoDisplayContext(width, height, PixelFormats.Bgr32);

            chroma = BitConverter.ToUInt32(new[] { (byte)'R', (byte)'V', (byte)'3', (byte)'2' }, 0);
            width = (uint)_context.Width;
            height = (uint)_context.Height;
            pitches = (uint)_context.Stride;
            lines = (uint)_context.Height;

            Dispatcher.Invoke(new Action(() =>
            {
                VideoSource = _context.Image;
            }));

            return (uint)_context.Size;
        }
Example #9
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)
     {
         _context = new VideoDisplayContext(width, height, ChromaType.RV32);
     }
     chroma = (uint)_context.ChromaType;
     width = (uint) _context.Width;
     height = (uint) _context.Height;
     pitches = (uint) _context.Stride;
     lines = (uint) _context.Height;
     Dispatcher.Invoke(new Action(() =>
     {
         VideoSource = _context.Image;
     }));
     return (uint) _context.Size;
 }