player.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0 */
  2. if (ato) {
  3. window.player = videojs('player', {
  4. 'aspectRatio': '16:9',
  5. 'autoplay': 'any',
  6. })
  7. } else {
  8. window.player = videojs('player', {
  9. 'aspectRatio': '16:9',
  10. })
  11. }
  12. /* resolution switch */
  13. window.player.videoJsResolutionSwitcher()
  14. fetch("/res/danmaku/" + current_vid + ':' + idx).then(r => r.json().then(ds => {
  15. /* Initialize danmaku display. */
  16. window.dm = new Danmaku({
  17. container: document.getElementById('player'),
  18. media: document.getElementById('player_html5_api'),
  19. comments: ds,
  20. })
  21. window.dm_status = true
  22. /* Hook the view resize event so danmaku fit in the container. */
  23. window.addEventListener('resize', mutations => {
  24. window.dm.resize()
  25. })
  26. }))
  27. /* custom controls */
  28. var ButtonComp = videojs.getComponent('Button')
  29. var danmakuSwitch = new ButtonComp(player, {
  30. clickHandler: function(event) {
  31. if (window.dm_status)
  32. window.dm.hide()
  33. else
  34. window.dm.show()
  35. window.dm_status = !window.dm_status
  36. }
  37. })
  38. danmakuSwitch.addClass('danmakuSwitchBtn')
  39. window.player.controlBar.addChild(danmakuSwitch, {}, 2)
  40. document.querySelector('.danmakuSwitchBtn .vjs-icon-placeholder').innerHTML =
  41. '<i class="icon ion-md-easel"></i>'
  42. /* auto next */
  43. if (total_pages > 1) {
  44. document.getElementById('continue').checked = ato
  45. document.getElementById('continue').addEventListener('click', function () {
  46. var url = '/video/' + current_vid + ':' + idx + '?listen=1'
  47. if (document.getElementById('continue').checked)
  48. url += '&ato=1'
  49. document.getElementById('avswitch').href = url
  50. })
  51. window.player.on('ended', function () {
  52. if (!document.getElementById('continue').checked)
  53. return
  54. if (++idx == total_pages)
  55. return
  56. window.location.href = '/video/' + current_vid + ':' + idx + '?ato=1'
  57. })
  58. }
  59. /* @license-end */