-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added audio support for dialog cards
- Loading branch information
Showing
5 changed files
with
69 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import axios from "axios"; | ||
|
||
import { extname } from "path"; | ||
import { toBuffer } from "../helpers"; | ||
import { H5pContent } from "./h5p-content"; | ||
import { H5pCopyrightInformation } from "./h5p-copyright-information"; | ||
|
||
export class H5pAudio extends H5pContent { | ||
/** | ||
* Downloads the audio at the URL and fills an H5pAudio objects with some metadata data of the image. | ||
* @param url The url to download from. | ||
* @returns the H5PAudio object, the buffer containing the raw audio data and the file extension of the URL | ||
*/ | ||
public static async fromDownload( | ||
url: string | ||
): Promise<{ audio: H5pAudio; buffer: Buffer; extension: string }> { | ||
let response = await axios.get(url, { responseType: "arraybuffer" }); | ||
if (response.status !== 200) { | ||
throw new Error(`Error: Could not download audio at ${url}!`); | ||
} | ||
let a = new H5pAudio(); | ||
a.mime = response.headers["content-type"].replace( | ||
"audio/mp3", | ||
"audio/mpeg" | ||
); | ||
a.copyright.license = "U"; | ||
return { | ||
audio: a, | ||
buffer: toBuffer(response.data), | ||
extension: extname(url), | ||
}; | ||
} | ||
|
||
public path: string; | ||
public mime: string; | ||
public copyright: H5pCopyrightInformation = new H5pCopyrightInformation(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters