@twilio/player
Advanced tools
Comparing version 1.0.0-beta.14 to 1.0.0-beta.15
/// <reference types="react" /> | ||
/// <reference path="./declarations.d.ts" /> | ||
import * as React from "react"; | ||
@@ -6,3 +7,3 @@ import WaveSurfer from "wavesurfer.js"; | ||
import { WaveSurferParams as WaveSurferParams$0 } from "wavesurfer.js"; | ||
import EE from "eventemitter3"; | ||
import * as EE from "eventemitter3"; | ||
import CanvasEntry from "wavesurfer.js/src/drawer.canvasentry.js"; | ||
@@ -145,3 +146,3 @@ import MultiCanvas from "wavesurfer.js/src/drawer.multicanvas.js"; | ||
load: (url: string, channels?: Channel[]) => void; | ||
hotLoad: (url: string) => Promise<void>; | ||
hotLoad: (url: string) => Promise<unknown>; | ||
play: (start?: number | undefined, end?: number | undefined) => Promise<void>; | ||
@@ -148,0 +149,0 @@ pause: () => Promise<void>; |
@@ -392,21 +392,32 @@ 'use strict'; | ||
}; | ||
this.hotLoad = async (url) => { | ||
if (!this.ws) { | ||
throw new Error("Unable to hotload, because player is either loading or not initialized"); | ||
} | ||
if (!this.mediaElement) { | ||
throw new Error("Unable to hotload, because media element does not exist"); | ||
} | ||
const time = this.ws.getCurrentTime(); | ||
const isPlaying = this.isPlaying(); | ||
const rate = this.ws.getPlaybackRate(); | ||
this.isHotLoading = true; | ||
this.mediaElement.src = url; | ||
this.ws.setPlaybackRate(rate); | ||
this.ws.backend.seekTo(time); | ||
if (isPlaying) { | ||
await this.ws.backend.play(null); | ||
} | ||
this.isHotLoading = false; | ||
this.emit("hot-load"); | ||
this.hotLoad = (url) => { | ||
return new Promise((resolve, reject) => { | ||
if (!this.ws) { | ||
reject(new Error("Unable to hotload, because player is either loading or not initialized")); | ||
return; | ||
} | ||
if (!this.mediaElement) { | ||
reject(new Error("Unable to hotload, because media element does not exist")); | ||
return; | ||
} | ||
const time = this.ws.getCurrentTime(); | ||
const isPlaying = this.isPlaying(); | ||
const rate = this.ws.getPlaybackRate(); | ||
this.isHotLoading = true; | ||
const onCanPlay = () => { | ||
if (this.ws && this.mediaElement) { | ||
this.ws.backend.seekTo(time); | ||
this.ws.setPlaybackRate(rate); | ||
if (isPlaying) { | ||
this.ws.backend.play(); | ||
} | ||
this.mediaElement.removeEventListener("canplay", onCanPlay); | ||
this.isHotLoading = false; | ||
this.emit("hot-load"); | ||
resolve(undefined); | ||
} | ||
}; | ||
this.mediaElement.addEventListener("canplay", onCanPlay); | ||
this.mediaElement.src = url; | ||
}); | ||
}; | ||
@@ -413,0 +424,0 @@ this.play = (start, end) => { |
{ | ||
"name": "@twilio/player", | ||
"version": "1.0.0-beta.14", | ||
"version": "1.0.0-beta.15", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "source": "src/index.ts", |
Sorry, the diff of this file is not supported yet
415444
1716