Edited at

Magic Leap MagicScript Landscape Application. AudioNode

Prepare

Magic Leap One

https://www.magicleap.com/magic-leap-one

mlsdk v.0.20.0

https://creator.magicleap.com/downloads/lumin-sdk/overview

magic-script-cli v2.0.1

https://www.npmjs.com/package/magic-script-cli

magic-script-polyfills v2.1.1

https://www.npmjs.com/package/magic-script-polyfills

mp3 file

https://www.bensound.com/royalty-free-music/track/pop-dance

Create Project

magic-script init my-sound org.magicscript.sound "Audio Sound"

cd my-sound
mkdir res

Put mp3 file in res folder. (Renamed to audio.mp3)

Code

Change app.package

DATAS = "digest.sha512.signed" : "." \

"bin/" : "bin/" \
"res/" : "res/"
OPTIONS = package/minApiLevel/2

Change app.js

import { LandscapeApp, ui } from 'lumin';

const { UiButton } = ui;

export class App extends LandscapeApp {
onAppStart () {
const prism = this.requestNewPrism([0.5, 0.5, 0.5]);
const button = UiButton.Create(prism, 'PLAY', 0, 0.1);
const resource =
prism.createLoadedFileAudioResourceId("res/audio.mp3");
const audio_node = prism.createAudioNode();
const isCreateAudio =
audio_node.createSoundWithLoadedFile(resource);
let isPlay = false;

button.onActivateSub(function (uiEventData) {
if (isCreateAudio && !isPlay)
{
isPlay = true;
audio_node.startSound();
button.setText("STOP");
}
else if (isCreateAudio && isPlay)
{
isPlay = false;
audio_node.stopSound();
button.setText("PLAY");
}
});
prism.getRootNode().addChild(button);
}
}

Build

magic-script build -i

Run

magic-script run --port=10000

Reference

AudioNode (MagicScript API)

https://docs.magicscript.org/lumin.AudioNode.html

magicscript

https://www.magicscript.org/

Thanks!