Debian Codegraph @

jupyter-widgets-controls/lib/widget_audio.js

raw
1 // Copyright (c) Jupyter Development Team.
2 // Distributed under the terms of the Modified BSD License.
3 import { DOMWidgetView } from '@jupyter-widgets/base';
4 import { CoreDOMWidgetModel } from './widget_core';
5 export class AudioModel extends CoreDOMWidgetModel {
6 defaults() {
7 return Object.assign(Object.assign({}, super.defaults()), { _model_name: 'AudioModel', _view_name: 'AudioView', format: 'mp3', autoplay: true, loop: true, controls: true, value: new DataView(new ArrayBuffer(0)) });
8 }
9 }
10 AudioModel.serializers = Object.assign(Object.assign({}, CoreDOMWidgetModel.serializers), { value: {
11 serialize: (value) => {
12 return new DataView(value.buffer.slice(0));
13 },
14 } });
15 export class AudioView extends DOMWidgetView {
16 render() {
17 /**
18 * Called when view is rendered.
19 */
20 super.render();
21 this.luminoWidget.addClass('jupyter-widgets');
22 this.update(); // Set defaults.
23 }
24 update() {
25 /**
26 * Update the contents of this view
27 *
28 * Called when the model is changed. The model may have been
29 * changed by another view or by a state update from the back-end.
30 */
31 let url;
32 const format = this.model.get('format');
33 const value = this.model.get('value');
34 if (format !== 'url') {
35 const blob = new Blob([value], {
36 type: `audio/${this.model.get('format')}`,
37 });
38 url = URL.createObjectURL(blob);
39 }
40 else {
41 url = new TextDecoder('utf-8').decode(value.buffer);
42 }
43 // Clean up the old objectURL
44 const oldurl = this.el.src;
45 this.el.src = url;
46 if (oldurl) {
47 URL.revokeObjectURL(oldurl);
48 }
49 // Audio attributes
50 this.el.loop = this.model.get('loop');
51 this.el.autoplay = this.model.get('autoplay');
52 this.el.controls = this.model.get('controls');
53 return super.update();
54 }
55 remove() {
56 if (this.el.src) {
57 URL.revokeObjectURL(this.el.src);
58 }
59 super.remove();
60 }
61 preinitialize() {
62 // Must set this before the initialize method creates the element
63 this.tagName = 'audio';
64 }
65 }
66 //# sourceMappingURL=widget_audio.js.map