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.
TypeScript
1
import PageSampleDesign from 'generated/pages/pageSample';
2
import FlexLayout from '@smartface/native/ui/flexlayout';
3
import Application from '@smartface/native/application';
4
import Button from '@smartface/native/ui/button';
5
import Sound from '@smartface/native/device/sound';
6
7
//You should create new Page from UI-Editor and extend with it.
8
export default class Sample extends PageSampleDesign {
9
10
mySound: Sound;
11
myButton: Button;
12
13
constructor() {
14
super();
15
// Overrides super.onShow method
16
this.onShow = onShow.bind(this, this.onShow.bind(this));
17
// Overrides super.onLoad method
18
this.onLoad = onLoad.bind(this, this.onLoad.bind(this));
19
20
this.layout.flexDirection = FlexLayout.FlexDirection.COLUMN;
21
this.layout.justifyContent = FlexLayout.JustifyContent.CENTER;
22
this.layout.alignItems = FlexLayout.AlignItems.CENTER;
23
}
24
}
25
26
/**
27
* @event onShow
28
* This event is called when a page appears on the screen (everytime).
29
* @param {function} superOnShow super onShow function
30
* @param {Object} parameters passed from Router.go function
31
*/
32
function onShow(superOnShow: () => void) {
33
const { headerBar } = this;
34
superOnShow();
35
Application.statusBar.visible = false;
36
headerBar.visible = false;
37
}
38
39
/**
40
* @event onLoad
41
* This event is called once when page is created.
42
* @param {function} superOnLoad super onLoad function
43
*/
44
function onLoad(superOnLoad: () => void) {
45
superOnLoad();
46
47
this.mySound = new Sound();
48
this.mySound.isLooping = true;
49
50
this.myButton = new Button({
51
text: "Load URL",
52
onPress: () => {
53
this.mySound.onReady = () => {
54
this.mySound.play();
55
}
56
this.mySound.loadURL("https://www.rmp-streaming.com/media/bbb-360p.mp4");
57
}
58
});
59
60
this.layout.addChild(this.myButton, "myButton", ".sf-button", {
61
top: 100,
62
width: 100,
63
height: 80,
64
backgroundColor: "#FFFF00"
65
});
66
67
}
68
Copied!
Last modified 2mo ago
Copy link