Thêm nút tải video về máy tính cho JW Player

Cập nhật lần cuối vào

Bài viết này mình sẽ hướng dẫn cho bạn cách thêm nút download vào JW Player. Cách làm rất đơn giản, bạn xem ví dụ như sau:

<script type="text/javascript">
var player = jwplayer('player');

player.setup({
  file: "//content.jwplatform.com/videos/xJ7Wcodt-cIp6U8lV.mp4",
  image: "//content.jwplatform.com/thumbs/xJ7Wcodt-720.jpg"
});

player.addButton(
  //This portion is what designates the graphic used for the button
  "//icons.jwplayer.com/icons/white/download.svg",
  //This portion determines the text that appears as a tooltip
  "Download Video",
  //This portion designates the functionality of the button itself
  function() {
    //With the below code, we're grabbing the file that's currently playing
    window.location.href = player.getPlaylistItem()['file'];
  },
  //And finally, here we set the unique ID of the button itself.
  "download"
);
</script>

Như vậy là bạn đã có thể thêm được nút download vào trong trình phát video. Ngoài ví dụ bên trên thì bạn cũng có thể thay bằng hàm bên dưới để áp dụng cho danh sách phát.

<script>
	player.addButton("//i.imgur.com/7BngCuw.png", "Download Video", function () {
		var item = player.getPlaylistItem(),
			quality = player.getCurrentQuality();
		window.open(item.sources[quality]["file"]);
	}, "download");
</script>

Nếu danh sách phát có nhiều video với chất lượng khác nhau thì tải video với chất lượng hiện tại đang xem. Ngoài ra, bạn cũng có thể xem thêm hướng dẫn JW Player dành cho nhà phát triển trên trang chủ của họ.

Theo dõi
Thông báo của
guest

0 Comments
Phản hồi nội tuyến
Xem tất cả bình luận