Click here to Skip to main content
15,881,559 members
Articles / Web Development / CSS3

AngleSharp

Rate me:
Please Sign up or sign in to vote.
5.00/5 (87 votes)
3 Jul 2013BSD28 min read 260.3K   4.3K   166  
Bringing the DOM to C# with a HTML5/CSS3 parser written in C#.
using System;

namespace AngleSharp.DOM.Html
{
    /// <summary>
    /// Represents the abstract base for HTML media (audio / video) elements.
    /// </summary>
    public abstract class HTMLMediaElement : HTMLElement
    {
        #region Members

        /// <summary>
        /// The source url.
        /// </summary>
        protected String source;
        /// <summary>
        /// The state of the network.
        /// </summary>
        protected MediaNetworkState network;
        /// <summary>
        /// The state of the media.
        /// </summary>
        protected MediaReadyState ready;
        /// <summary>
        /// Currently seeking ?
        /// </summary>
        protected Boolean seeking;
        /// <summary>
        /// The total time (duration).
        /// </summary>
        protected Double duration;
        /// <summary>
        /// The current time.
        /// </summary>
        protected Double currentTime;

        #endregion

        #region ctor

        internal HTMLMediaElement()
        {
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the media source.
        /// </summary>
        public string Src
        {
            get { return GetAttribute("src"); }
            set { SetAttribute("src", value); }
        }

        /// <summary>
        /// Gets or sets the cross-origin attribute.
        /// </summary>
        public string CrossOrigin
        {
            get { return GetAttribute("crossorigin"); }
            set { SetAttribute("crossorigin", value); }
        }

        /// <summary>
        /// Gets or sets the preload attribute.
        /// </summary>
        public string Preload
        {
            get { return GetAttribute("preload"); }
            set { SetAttribute("preload", value); }
        }

        /// <summary>
        /// Gets the current network state.
        /// </summary>
        public MediaNetworkState NetworkState
        {
            get { return network; }
        }

        /// <summary>
        /// Gets the current ready state.
        /// </summary>
        public MediaReadyState ReadyState
        {
            get { return ready; }
        }

        /// <summary>
        /// Gets if seeking is currently active.
        /// </summary>
        public bool Seeking
        {
            get { return seeking; }
        }

        /// <summary>
        /// Gets the current media source.
        /// </summary>
        public string CurrentSrc
        {
            get { return source; }
        }

        /// <summary>
        /// Gets the time in seconds.
        /// </summary>
        public double Duration
        {
            get { return duration; }
        }

        /// <summary>
        /// Gets or sets the current time in seconds.
        /// </summary>
        public double CurrentTime
        {
            get { return currentTime; }
            set
            {
                if (value < 0)
                    currentTime = 0;
                else if (value > Duration)
                    currentTime = Duration;
                else
                    currentTime = value;

                //TODO Current Time changed!
            }
        }

        //TODO
        //http://www.w3.org/TR/html5/embedded-content-0.html#htmlmediaelement

        #endregion

        #region Methods

        /// <summary>
        /// Loads the media specified for this element.
        /// </summary>
        public void Load()
        {
            //TODO
        }

        /// <summary>
        /// Tries to play the media for this element.
        /// </summary>
        public void Play()
        {
            //TODO
        }

        /// <summary>
        /// Pauses the playback of the media for this element.
        /// </summary>
        public void Pause()
        {
            //TODO
        }

        #endregion

        #region Enumerations

        /// <summary>
        /// An enumeration of possible network states.
        /// </summary>
        public enum MediaNetworkState : ushort
        {
            /// <summary>
            /// The element has not yet been initialized.
            /// Everything is in initial state.
            /// </summary>
            Empty = 0,
            /// <summary>
            /// The element's resource selection alg. is active.
            /// No network usage at the moment, but nothing
            /// loaded.
            /// </summary>
            Idle = 1,
            /// <summary>
            /// The download is in progress.
            /// </summary>
            Loading = 2,
            /// <summary>
            /// The element's resource selection alg. is active,
            /// but has not yet found a resource to use.
            /// </summary>
            NoSource = 3
        }

        /// <summary>
        /// An enumeration of media ready states.
        /// </summary>
        public enum MediaReadyState : ushort
        {
            /// <summary>
            /// No information is available.
            /// </summary>
            Nothing = 0,
            /// <summary>
            /// Enough information obtained such that the duration of the
            /// resource is available.
            /// </summary>
            Metadata = 1,
            /// <summary>
            /// Data for immediate playback is available, but not enough
            /// to advance.
            /// </summary>
            CurrentData = 2,
            /// <summary>
            /// Enough data for the current and further positions are 
            /// available.
            /// </summary>
            FutureData = 3,
            /// <summary>
            /// All conditions are met and playback should immediately
            /// execute.
            /// </summary>
            EnoughData = 4
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Chief Technology Officer
Germany Germany
Florian lives in Munich, Germany. He started his programming career with Perl. After programming C/C++ for some years he discovered his favorite programming language C#. He did work at Siemens as a programmer until he decided to study Physics.

During his studies he worked as an IT consultant for various companies. After graduating with a PhD in theoretical particle Physics he is working as a senior technical consultant in the field of home automation and IoT.

Florian has been giving lectures in C#, HTML5 with CSS3 and JavaScript, software design, and other topics. He is regularly giving talks at user groups, conferences, and companies. He is actively contributing to open-source projects. Florian is the maintainer of AngleSharp, a completely managed browser engine.

Comments and Discussions