我在django网站上使用JWPlayer 6。我想在同一页面上显示不同的视频。由于我正在迭代对象,我不能将不同的类ID分配给Jwplayer标记。因此,当我加载它时,将显示一个视频,而另一个将弹出此错误:
Loading the player
我一直在寻找一种方法来解决这个问题但却没有成功!
Django模板
{% block content %}
{% for flip in flips %}
<p> {{flip.title}} </p>
<center>
<div id="myElement">Loading the player...</div>
<script type="text/javascript">
jwplayer("myElement").setup({
image: "{{MEDIA_URL}}/{{flip.vid_image}}",
source[ {file: "{{MEDIA_URL}}/{{flip.vid_watch}}" },
{file: "{{MEDIA_URL}}/{{flip.vid_mp}}"
],
title:"{{flip.title}}",
width:692,
height:389
});
</script>
</center>
<p>Description: {{flip.description}} </p>
{% endblock %}
答案 0 :(得分:1)
以下是答案
{% block content %}
{% for flip in flips %}
<p> {{flip.title}} </p>
<center>
<div id="myElement_{{ forloop.counter }}">Loading the player...</div>
<script type="text/javascript">
jwplayer("myElement_{{ forloop.counter }}").setup({
image: "{{MEDIA_URL}}/{{flip.vid_image}}",
source[ {file: "{{MEDIA_URL}}/{{flip.vid_watch}}" },
{file: "{{MEDIA_URL}}/{{flip.vid_mp}}"}
],
title:"{{flip.title}}",
width:692,
height:389
});
</script>
</center>
<p>Description: {{flip.description}} </p>
{% endfor %}
{% endblock %}
感谢James Herrieven!