简体   繁体   English

在三星智能电视上播放声音

[英]playing sounds on samsung smart tv

I am developing a simple game for samsung smart tv.我正在为三星智能电视开发一款简单的游戏。 I want to play little sound files when certain things happened like ready, win, lose.我想在某些事情发生时播放小声音文件,比如准备好、赢了、输了。 I don't want to deal with flash players, player controls.. Is there a way to use javascript to trigger a play sound action with a predefined sound volume and i nwant to do this several times in my code.我不想处理 flash 播放器、播放器控件。有没有办法使用 javascript 来触发具有预定义音量的播放声音动作,我想在我的代码中多次执行此操作。

You need to add player object ( SAMSUNG-INFOLINK-PLAYER ) into your <body> tag:您需要将播放器 object ( SAMSUNG-INFOLINK-PLAYER ) 添加到您的<body>标签中:

<object id="pluginPlayer" style="visibility: hidden; width: 0px; height: 0px; opacity: 0.0" classid="clsid:SAMSUNG-INFOLINK-PLAYER"></object>

And then in the app's javascript just use this function:然后在应用程序的 javascript 中使用这个 function:

var playerObj = document.getElementById('pluginPlayer');
playerObj.Play("absolute_url_to_your_mp3");

As Player plugin executes in different location inside Samsung's filesystem you need always use absolute path to the file.由于 Player 插件在三星文件系统内的不同位置执行,您需要始终使用文件的绝对路径。 It can be remote one, but you can use location.href of you app's index.html to get absolute local path of app's working directory where you can put the mp3s.它可以是远程的,但你可以使用你应用程序的index.htmllocation.href来获取你可以放置 mp3 的应用程序工作目录的绝对本地路径。

Check the documentation, here:在此处查看文档:

http://www.samsungdforum.com/Guide/View/Developer_Documentation/Samsung_SmartTV_Developer_Documentation_2.5/API_Reference/JavaScript_APIs/Device_API/Player http://www.samsungdforum.com/Guide/View/Developer_Documentation/Samsung_SmartTV_Developer_Documentation_2.5/API_Reference/JavaScript_APIs/Device_API/Player

this was my solution:这是我的解决方案:

add to of index.html file添加到index.html文件

<body>
    <object id="pluginPlayer" border=0    classid="clsid:SAMSUNG-INFOLINK-PLAYER">
...
...
...
</body>

inside my.js file Scene1.js在 my.js 文件中 Scene1.js

SceneScene1.prototype.initialize = function () {
var Player = document.getElementById('pluginPlayer');
var retVal=Player.Play("http://mysite.com/android/smartTV/little_wing.mp3");
...
...
...
}   

I use the SDK version 5.1 for TVs 2013 and 2014 model years and I have the following code works:我将 SDK 5.1 版用于 2013 年和 2014 年 model 年的电视,并且我有以下代码:

<object id="pluginPlayer" classid="clsid:SAMSUNG-INFOLINK-PLAYER"></object>

var playerObj = document.getElementById('pluginPlayer');
var fileName = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);
playerObj.Play(document.location.href.split(fileName)[0] + 'test.mp3');

And this alternative also works (using Flash):这个替代方案也有效(使用 Flash):

<div style="position:absolute; z-index:-1;">
    <object type="application/x-shockwave-flash" width="100" height="50" id="fplayer">
        <param name="movie" value="test.swf"/>
        <param name="quality" value="high"/>
        <param name="bgcolor" value="blue"/>
    </object>
</div>

And many thanks to Dobiatowski!非常感谢 Dobiatowski!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM