我想達到列表中的每個項目以生成新的視頻源,其中包括我的一些代碼。例如,我想要做一些像{{url_list.video_count}}
更改視頻。我怎樣才能做到這一點?javascript中的Django列表項目
我想在我的網站上播放視頻。在我看來,{{url_list.0}}
非常適合首發。在JavaScript中,我想根據{{url_list.video_count}}
更改源,以在第一個視頻結束時播放其他視頻。
我基本上想要一個看不見的播放列表。
這裏是我的JavaScript代碼:
var video_count = 1;
videoPlayer = document.getElementById("example_video");
arr_length = {{ url_list.count }};
function run() {
video_count++;
if (video_count == arr_length) video_count = 0;
nextVideo = "{{ url_list.1}}";
videoPlayer.src = nextVideo;
videoPlayer.play();
};
在views.py:
def get_context_data(self,**kwargs):
context = super(VideoListView, self).get_context_data(**kwargs)
context['url_list'] = Video.objects.all().order_by("-order").values_list("url", flat=True)
return context
在models.py:
@receiver(pre_save,sender=Video)
def video_url_handler(sender,instance,*args,**kwargs):
instance.url = "media/video/%i.ogg" % instance.id
問題編輯 – kings856