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.

JavaScript
JavaScript
const Page = require("sf-core/ui/page");
const extend = require("js-base/core/extend");
const Button = require('sf-core/ui/button');
const Color = require('sf-core/ui/color');
const Sound = require("sf-core/device/sound");
const FlexLayout = require('sf-core/ui/flexlayout');
var Page1 = extend(Page)(
function(_super) {
_super(this, {
onShow: function(params) {
Application.statusBar.visible = false;
this.headerBar.visible = false;
},
onLoad: function(params) {
var mySound = new Sound();
mySound.isLooping = true;
var myButton = new Button({
top: 100,
width: 100,
height: 80,
text: "Load URL",
backgroundColor: Color.RED,
onPress: function() {
mySound.onReady = function () {
mySound.play();
}
mySound.loadURL("https://www.rmp-streaming.com/media/bbb-360p.mp4");
}
});
this.layout.alignItems = FlexLayout.AlignItems.CENTER;
this.layout.addChild(myButton);
}
});
}
);
module.exports = Page1;