Play background music via LS2 API

Hi,
I am trying to make basic app with background music(mp3 file).
But it is not working. My team members are facing huge difficulties because there is no example for how to use the luna service in javascript in WebOS ose develop page.

Below is my source code.

<script src="webOSjs-0.1.0/webOS.js" charset="utf-8"></script>
<script type="text/javascript">
   var lunaReq= webOS.service.request("luna://com.webos.media",
    {
        method:"load",
        parameters:{
			uri: 'music.mp3',
			type : 'media'
		},
        onSuccess: function (returnValue, mediaId) {
			playalarm(mediaId);
        },
        onFailure: function (args) {
        }
    });

	var playalarm = function(mediaId) {
		webOS.service.request("luna://com.webos.media", {
			method:"play",
        	parameters:{
				media : mediaId
			},
			onSuccess: function (returnValue, mediaId) {
				console.log(mediaId);
			},
			onFailure: function (args) {
			}
		})};

</script>

Many thanks in advance :slight_smile:

It might be that you looking for

See http://webostv.developer.lge.com/develop/js-services/calling-js-service/

Thanks,

But I think your link is for WebOS TV. Is it all same with WebOS OSE?

@Ji12345 Its the same, no difference at all.
Also in case you've missed it, the exact same documentation exists in the OSE site as well.
http://webosose.org/develop/js-services/calling-js-service/

1 Like