简体   繁体   English

播放HTML5视频时不会加载XML文件

[英]XML file does't load when HTML5 video plays

I should be able to loads the related XML file and displays the content of the XML file as the video plays back. 我应该能够加载相关的XML文件,并在视频播放时显示XML文件的内容。

What am I missing? 我错过了什么?

DEMO DEMO

JAVSCRIPT JAVSCRIPT

var XML_PATH = "http://www.adjustyourset.tv/interview/cuepoints.xml";

var cuepoints=new Array();

$(document).ready(function() {
    loadXML();
});

function loadXML()
{
    $.ajax({
            type: "GET",
            url: XML_PATH,
            dataType: "xml",
            success: function onXMLloaded(xml) 
            {
                // set cuepoints
                cuepoints=$(xml).find("cuepoints");

                // loop for each cuepoint
                $(xml).find('cuepoint').each(function loopingItems(value)
                {   
                    // create an object
                    var obj={
                    timeStamp:$(this).find("timeStamp").text(),
                    desc:$(this).find("desc").text(),
                    thumbLink:$(this).find("thumbLink").text(),
                    price:$(this).find("price").text()};
                    cuepoints.push(obj);

                    $("#mycustomscroll").append('<ul>');
                    $("#mycustomscroll").append('<li id="item"><strong>'+(value+1)+"</strong><br/><strong>Time Stamp: </strong>"+obj.timeStamp+'</li>');
                });

                // close </ul>
                $("#mycustomscroll").append('</ul>');
                // append li tags
                $("#leftcolumn").append('<li src="'+cuepoints[0].desc+'"> <p src="'+cuepoints[0].thumbLink+'" /></li>');

                $("#price").append(cuepoints[0].price);

            }
    });
}

Nothing is calling init() . 什么都没有调用init()

Change 更改

function init() {
    // call loadXML function
    loadXML();
}

to

$(document).ready(function() {
    loadXML();
});

Ok. 好。 Now i understood the question. 现在我理解了这个问题。 You are able to get the xml from the ajax request but you are not able to parse it properly. 您可以从ajax请求中获取xml,但是您无法正确解析它。

If you are concerned about this piece of code 如果你担心这段代码

  $(xml).find('cuepoint').each(function loopingItems(value)
                {    
            // create an object
                    var obj={timeStamp:$(this).find("timeStamp").text(), desc:$(this).find("desc").text(), thumbLink:$(this).find("thumbLink").text(), price:$(this).find("price").text()};
                    cuepoints.push(obj);

                    // append <ul> and timeStamp
                    $("#mycustomscroll").append('<ul>');
                    $("#mycustomscroll").append('<a><li id="item"><strong>'+(value+1)+"</strong><br/><strong>Time Stamp: </strong>"+obj.timeStamp+'</li></a>');
                });

then i suggest you to use this.getAttribute('timeStamp') or $(this).attr('timeStamp') instead of $(this).find("timeStamp").text() , you wont get anything from this because this is an attribute and not an element. 然后我建议你使用this.getAttribute('timeStamp') or $(this).attr('timeStamp')而不是$(this).find("timeStamp").text() ,你不会从这里得到任何东西因为这是属性而不是元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM