Ejemplo n.º 1
0
        /// <summary>Loads this cached data from the given JSON object.</summary>
        public override void LoadFromJson(Json.JSObject obj)
        {
            // It should be an array:
            Json.JSArray arr = obj as Json.JSArray;

            if (arr == null)
            {
                return;
            }

            // For each one..
            foreach (KeyValuePair <string, JSObject> kvp in arr.Values)
            {
                // Add it:
                Add(kvp.Key, new CachedContent(this, kvp.Key, kvp.Value));
            }
        }
Ejemplo n.º 2
0
        /// <summary>Loads a timeline from the given JSON.</summary>
        public void load(Json.JSObject json)
        {
            if (started)
            {
                // Reset if needed:
                reset();
            }

            duration = null;

            // First, check for the 'tracks' field:
            Json.JSObject trackData = json["tracks"];

            if (trackData == null)
            {
                // Considered to be a single track.
                // Try loading it now:
                Track track = Track.loadFromJson(this, json);

                if (track == null)
                {
                    // Empty:
                    tracks = new Track[0];
                }
                else
                {
                    // We have at least 1 entry in a track.
                    tracks = new Track[1];

                    // We now need to detect what kind of track it is based on what it provides.
                    // If it's a style track, the first element
                    tracks[0] = track;
                }
            }
            else
            {
                // Optional default language (must be before tracks load):
                string lang = json.String("lang");

                if (!string.IsNullOrEmpty(lang))
                {
                    defaultLanguage = lang.Trim().ToLower();
                }

                // Must be an indexed array:
                var trackArray = trackData as Json.JSIndexedArray;

                if (trackArray == null)
                {
                    loadFailed("'tracks' must be an indexed array.", this);
                }

                // Fully defined timeline.
                int length = trackArray.length;

                // Create track set:
                tracks = new Track[length];

                // Load each one:
                for (int i = 0; i < length; i++)
                {
                    // Load the track now:
                    tracks[i] = Track.loadFromJson(this, trackArray[i]);
                }

                // Optional duration:
                string durationText = json.String("duration");

                if (!string.IsNullOrEmpty(durationText))
                {
                    // Load it as a CSS value:
                    duration = Css.Value.Load(durationText);
                }
            }

            status_ = TIMELINE_STARTED;
        }