2014-04-09 30 views
0

我是網絡開發新手,這是我的第一個Chrome擴展。這裏是我的腳本來獲取和解析RSS提要:從RSS訂閱項獲取視頻的鏈接

$(document).ready(function() { 
    // FETCH THE RSS FEEDS AND PARSE THEM 
    $.get(rssurl, function(data) { 
     var $xml = $(data); 
     $xml.find("item").each(function() { 
     var $this = $(this), 
      item = { 
        title: $this.find("title").text(), 
        link: $this.find("link").text(), 
        description: $this.find("description").text(), 
        pubDate: $this.find("pubDate").text(), 
        url : $this.find("enclosure").attr("url"), 
        author: $this.find("author").text() 
        }; 

     // ADD IT TO THE ARRAY 
     items.push(item); 
     if(items.length == 1){ 
      $(".title").html(item.title); 
      $(".description").html(item.url); 
      $(".author").html(item.author); 

      $(video).attr({"src" : item.url}); 
     } 
     });// end of each() 
    });// end of $.get() 
}); 

但問題是這樣的:

url : $this.find("enclosure").attr("url"), 

的想法是讓視頻播放,儘管它​​在.mp4是其中沒有。
下面是我解析提要:http://feeds.podtrac.com/tTKj5t05olM $

注:我已經可以在我的鉻清單

+0

所以...你只是想獲取mp4格式的項目? – Chickenrice

+0

是的,並顯示其視頻 –

回答

0

的問題是在這裏:

$(video).attr({"src" : item.url}); 

它需要:

$("video").attr("src",item.url); 
+1

無效的選擇器是主要的視頻顯示問題的原因。 attr(string,value)和attr({string:value})都可以設置元素的屬性值。 Attr({string:value})可以一次設置多個屬性。 – Chickenrice

1

嘗試所有網址以添加以下條件添加項目之前到數組:

if($("enclosure[url$='.mp4']",this).length>0){} 

[屬性$ =「值」]是jQuery的屬性與選擇結束。它將選擇具有指定屬性的元素,其值以給定字符串結尾。

代碼:

$(document).ready(function() { 
    // FETCH THE RSS FEEDS AND PARSE THEM 
    $.get(rssurl, function(data) { 
     var $xml = $(data); 
     $xml.find("item").each(function() { 
     //if item's enclosure url attribute is in .mp4 format... then add it to the video array 
     if($("enclosure[url$='.mp4']",this).length>0){ 
      var $this = $(this), 
       item = { 
         title: $this.find("title").text(), 
         link: $this.find("link").text(), 
         description: $this.find("description").text(), 
         pubDate: $this.find("pubDate").text(), 
         url : $this.find("enclosure").attr("url"), 
         author: $this.find("author").text() 
        }; 

      // ADD IT TO THE ARRAY 
      items.push(item); 

      if(items.length == 1){ 
      $(".title").html(item.title); 
      $(".description").html(item.url); 
      $(".author").html(item.author); 

      $(video).attr({"src" : item.url}); 
      } 
     } 
     });// end of each() 
    });// end of $.get() 
}); 
1

我想你的MP4文件格式不正確,在HTML5視頻標籤的發揮。

當我在Firefox中打開http://media.tqaweekly.com/video/tqa-se4ep29.mp4時,出現一個錯誤,指出視頻已損壞。在Chrome中,我有音頻但沒有視頻。

我解決了這個另一個堆垛機here。我認爲它是類似的。

之後,您需要在HTML5視頻標籤中顯示視頻。但我猜你不需要幫助,瞭解:)

<video width="640" height="360" controls> 
    <source src="yoursrc.mp4" type="video/mp4; codecs=avc1.42E01E,mp4a.40.2"> 
</video> 
+0

我試過[此RSS FEED](http://feeds.twit.tv/aaa_video_hd.xml)但無濟於事。 :( –

+0

你可以試試這個:http://api.ooyala.com/syndication/mp4?id=00d1c219-1b16-4273-a591-3bfb5bf7f2fc –

+0

裏面的文件不會以.mp4結尾,但它們是有效的mp4,例如http://ak.c.ooyala.com/NjbGoxMjqMRw66RZJJ993wWRxux7Z4cf/DOcJ-FxaFrRg4gtGUwOmk2OjBrOxit_Y,我知道這些文件格式正確 –