-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b38634
commit ac50f73
Showing
5 changed files
with
22 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/target | ||
Cargo.lock | ||
.deno_plugins/ |
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,10 @@ | ||
// @ts-ignore | ||
export const core = Deno.core as { | ||
ops: () => { [key: string]: number }; | ||
setAsyncHandler(rid: number, handler: (response: Uint8Array) => void): void; | ||
dispatch( | ||
rid: number, | ||
msg?: any, | ||
buf?: ArrayBufferView, | ||
): Uint8Array | undefined; | ||
}; |
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,4 @@ | ||
import { play } from "./mod.ts"; | ||
|
||
await play("music.mp3"); | ||
|
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 @@ | ||
export { play } from "./plugin.ts"; |
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 |
---|---|---|
@@ -1,16 +1,6 @@ | ||
import filename from "./detect.ts"; | ||
import { prepare } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
// @ts-ignore | ||
export const core = Deno.core as { | ||
ops: () => { [key: string]: number }; | ||
setAsyncHandler(rid: number, handler: (response: Uint8Array) => void): void; | ||
dispatch( | ||
rid: number, | ||
msg?: any, | ||
buf?: ArrayBufferView, | ||
): Uint8Array | undefined; | ||
}; | ||
import { core } from "./core_type.ts"; | ||
|
||
const { filenameBase, pluginBase } = { | ||
"filenameBase": "deno_audio", | ||
|
@@ -21,10 +11,6 @@ const { filenameBase, pluginBase } = { | |
const isDev = Deno.env.get("DEV"); | ||
|
||
if (isDev) { | ||
// This will be checked against open resources after Plugin.close() | ||
// in runTestClose() below. | ||
const resourcesPre = Deno.resources(); | ||
|
||
const rid = Deno.openPlugin("./target/debug/" + filename(filenameBase)); | ||
} else { | ||
// logger.info(`Downloading latest Autopilot release from Github`); | ||
|
@@ -40,23 +26,20 @@ if (isDev) { | |
|
||
|
||
const { | ||
play, | ||
play: op_play, | ||
} = core.ops(); | ||
|
||
const textDecoder = new TextDecoder(); | ||
const decoder = new TextDecoder(); | ||
|
||
|
||
export async function play_audio(arg: string) { | ||
export async function play(file: string) { | ||
const encoder = new TextEncoder(); | ||
const view = encoder.encode(arg); | ||
const view = encoder.encode(file); | ||
return new Promise((resolve, reject) => { | ||
core.setAsyncHandler(play, (bytes) => { | ||
core.setAsyncHandler(op_play, (bytes) => { | ||
resolve(textDecoder.decode(bytes)); | ||
}); | ||
core.dispatch(play, view); | ||
core.dispatch(op_play, view); | ||
}); | ||
} | ||
|
||
await play_audio("music.mp3"); | ||
|