You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.3 KiB

7 years ago
  1. /**********************************************************************************
  2. *
  3. * Copyright (C) 2017 MuK IT GmbH
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. **********************************************************************************/
  19. odoo.define('muk_preview_audio.PreviewGenerator', function (require) {
  20. "use strict";
  21. var core = require('web.core');
  22. var PreviewHandler = require('muk_preview.PreviewHandler');
  23. var PreviewGenerator = require('muk_preview.PreviewGenerator');
  24. var QWeb = core.qweb;
  25. var _t = core._t;
  26. var AudioHandler = PreviewHandler.extend({
  27. mimetypeMap: {
  28. '.wav': 'audio/wav',
  29. '.ogg': 'audio/ogg',
  30. '.mp3': 'audio/mpeg',
  31. 'wav': 'audio/wav',
  32. 'ogg': 'audio/ogg',
  33. 'mp3': 'audio/mpeg',
  34. },
  35. checkExtension: function(extension) {
  36. return ['.wav', '.ogg', '.mp3', 'wav', 'ogg', 'mp3'].includes(extension);
  37. },
  38. checkType: function(mimetype) {
  39. return ['audio/wav', ' audio/ogg', 'audio/mpeg'].includes(mimetype);
  40. },
  41. createHtml: function(url, mimetype, extension, title) {
  42. var result = $.Deferred();
  43. if(!mimetype || mimetype === 'application/octet-stream') {
  44. mimetype = this.mimetypeMap[extension];
  45. }
  46. var $content = $(QWeb.render('AudioHTMLContent', {url: url, type: mimetype, title: title}));
  47. var visualizer = new Visualizer($content.find('audio'), $content.find('.visualizer'), $content.find('canvas'));
  48. result.resolve($content);
  49. return $.when(result);
  50. },
  51. });
  52. PreviewGenerator.include({
  53. audioHandler: {
  54. "AudioHandler": new AudioHandler(),
  55. },
  56. init: function(additional_handler) {
  57. additional_handler = _.extend(this.audioHandler, additional_handler);
  58. this._super(additional_handler);
  59. },
  60. });
  61. });