How would I create a text "button" that will play a sound?
- ScotsScripts
- Posts: 1
- Joined: Fri Feb 22, 2019 7:58 pm
How would I create a text "button" that will play a sound?
I just updated to a new phone and one of my widgets is no longer available (sound button free). This allowed me to create a widget with a text label (in this case the old time smiley face and associate it with a sound file that would play without putting anything on the screen except "stop" (which had replaced the text/button.)
Is there a way to do this with LL scripting and if so, do you have any tips or coding or anything to share that will help? Thanks!
Is there a way to do this with LL scripting and if so, do you have any tips or coding or anything to share that will help? Thanks!
Re: How would I create a text "button" that will play a sound?
Create a blank item and set this as launch action with the sound file path as data:
Code: Select all
bindClass("android.media.MediaPlayer");
var item = getEvent().getItem();
function stop() {
item.setLabel(item.getTag("label"));
item.setTag("label",null);
item.my.player.stop();
item.my.player.release();
}
if(item.getTag("label")==null){
item.my.player = MediaPlayer.create(getActiveScreen().getContext(), Uri.parse("file://"+getEvent().getData()));
item.my.player.start();
item.my.player.setOnCompletionListener(function(mp){stop();});
item.setTag("label",item.getLabel());
item.setLabel("Stop");
} else {
stop();
}
Re: How would I create a text "button" that will play a sound?
I'm pleased to know that someone is using the "my" object!
Re: How would I create a text "button" that will play a sound?
It was introduced after I asked for a runtime object storage. So not surprising that I am using it
- TrianguloY
- Posts: 109
- Joined: Thu Jan 24, 2019 9:46 am
Re: How would I create a text "button" that will play a sound?
https://www.lightninglauncher.com/scrip ... html#getMy()
(note that with this javascript almost any 'X.getY().Z' can be replaced with 'X.Y.Z').
A Scriptable object is a javascript object, like a '{}', but it is stored on the item itself (similar to a tag, but can store any other object not only a string, although it is not saved).
(note that with this javascript almost any 'X.getY().Z' can be replaced with 'X.Y.Z').
A Scriptable object is a javascript object, like a '{}', but it is stored on the item itself (similar to a tag, but can store any other object not only a string, although it is not saved).