当前位置:   article > 正文

DPlayer使用和下载_dplayer官网

dplayer官网

1.官网介绍

http://dplayer.js.org/#/home?id=installation

2.下载:

记得把带map的一起下了

https://github.com/MoePlayer/DPlayer/tree/master/dist

3.m3u8格式在线测试:

http://www.86y.org/m3u8test.html

4.报错:Hls未定义(如果出现flvjs、dashjs未定什么的类似)

解决:

网上去下个hls.js并链接到你的网页。

原因:

由于DPlayer只是播放器,需要自己添加需要的媒体流协议如Hls,如果没有就会报错。

下面这段是报错位置的部分:

目的是:通过视频格式(如.m3u8)判断需要的媒体流协议:hls、flv、dash、normal。然后进行相应的播放.

  1. value: function initMSE(video, type) {
  2. var _this3 = this;
  3. this.type = type;
  4. if (this.options.video.customType && this.options.video.customType[type]) {
  5. if (Object.prototype.toString.call(this.options.video.customType[type]) === '[object Function]') {
  6. this.options.video.customType[type](this.video, this);
  7. } else {
  8. console.error('Illegal customType: ' + type);
  9. }
  10. } else {
  11. if (this.type === 'auto') {
  12. if (/m3u8(#|\?|$)/i.exec(video.src)) {
  13. this.type = 'hls';
  14. } else if (/.flv(#|\?|$)/i.exec(video.src)) {
  15. this.type = 'flv';
  16. } else if (/.mpd(#|\?|$)/i.exec(video.src)) {
  17. this.type = 'dash';
  18. } else {
  19. this.type = 'normal';
  20. }
  21. }
  22. if (this.type === 'hls' && (video.canPlayType('application/x-mpegURL') || video.canPlayType('application/vnd.apple.mpegURL'))) {
  23. this.type = 'normal';
  24. }
  25. switch (this.type) {
  26. case 'hls':
  27. if (Hls) {
  28. if (Hls.isSupported()) {
  29. var hls = new Hls();
  30. hls.loadSource(video.src);
  31. hls.attachMedia(video);
  32. } else {
  33. this.notice('Error: Hls is not supported.');
  34. }
  35. } else {
  36. this.notice('Error: Can\'t find Hls.');
  37. }
  38. break;
  39. case 'flv':
  40. if (flvjs && flvjs.isSupported()) {
  41. if (flvjs.isSupported()) {
  42. var flvPlayer = flvjs.createPlayer({
  43. type: 'flv',
  44. url: video.src
  45. });
  46. flvPlayer.attachMediaElement(video);
  47. flvPlayer.load();
  48. } else {
  49. this.notice('Error: flvjs is not supported.');
  50. }
  51. } else {
  52. this.notice('Error: Can\'t find flvjs.');
  53. }
  54. break;
  55. case 'dash':
  56. if (dashjs) {
  57. dashjs.MediaPlayer().create().initialize(video, video.src, false);
  58. } else {
  59. this.notice('Error: Can\'t find dashjs.');
  60. }
  61. break;
  62. case 'webtorrent':
  63. if (WebTorrent) {
  64. if (WebTorrent.WEBRTC_SUPPORT) {
  65. this.container.classList.add('dplayer-loading');
  66. var client = new WebTorrent();
  67. var torrentId = video.src;
  68. client.add(torrentId, function (torrent) {
  69. var file = torrent.files.find(function (file) {
  70. return file.name.endsWith('.mp4');
  71. });
  72. file.renderTo(_this3.video, { autoplay: _this3.options.autoplay }, function () {
  73. _this3.container.classList.remove('dplayer-loading');
  74. });
  75. });
  76. } else {
  77. this.notice('Error: Webtorrent is not supported.');
  78. }
  79. } else {
  80. this.notice('Error: Can\'t find Webtorrent.');
  81. }
  82. break;
  83. }
  84. }
  85. }

 

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号