Skip to main content
Version: 7.2.1

Sound

API Reference: Device.Sound

Sound is used to control the playback of sound files.

Permisions for Android

loadURL method INTERNET permission to use network-based content. Add it to manifest file in your project for publishing.

loadFile method requires READ_EXTERNAL_STORAGE permission on API Level 32 and below and READ_MEDIA_AUDIO on API Level 33 and above.

TypeScript
import PageSampleDesign from "generated/pages/pageSample";
import { Route, Router } from "@smartface/router";
import Application from "@smartface/native/application";
import Button from "@smartface/native/ui/button";
import Sound from "@smartface/native/device/sound";

//You should create new Page from UI-Editor and extend with it.
export default class Sample extends PageSampleDesign {
mySound: Sound;
myButton: Button;
constructor(private router?: Router, private route?: Route) {
super({});
}

// The page design has been made from the code for better
// showcase purposes. As a best practice, remove this and
// use WYSIWYG editor to style your pages.
centerizeTheChildrenLayout() {
this.dispatch({
type: "updateUserStyle",
userStyle: {
flexProps: {
flexDirection: 'COLUMN',
justifyContent: 'CENTER',
alignItems: 'CENTER'
}
}
})
}

onShow() {
super.onShow();
const { headerBar } = this;
Application.statusBar.visible = false;
headerBar.visible = false;

}

onLoad() {
super.onLoad();
this.centerizeTheChildrenLayout();

this.mySound = new Sound();
this.mySound.isLooping = true;

this.myButton = new Button({
text: "Load URL",
onPress: () => {
this.mySound.onReady = () => {
this.mySound.play();
};
this.mySound.loadURL("https://www.rmp-streaming.com/media/bbb-360p.mp4");
},
});

this.addChild(this.myButton, "myButton", ".sf-button", {
top: 100,
width: 100,
height: 80,
backgroundColor: "#FFFF00",
});
}
}