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

playing sounds on samsung smart tv

本文关键字:播放声音 电视 智能 三星      更新时间:2023-09-26

我正在为三星智能电视开发一款简单的游戏。我想在某些事情发生时播放一些小声音文件,比如准备好、赢、输。我不想处理flash播放器,播放器控制。。有没有一种方法可以使用javascript来触发具有预定义音量的播放声音动作,我希望在我的代码中多次这样做。

您需要将玩家对象(SAMSUNG-INFOLINK-PLAYER)添加到<body>标签中:

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

然后在应用程序的javascript中只需使用以下函数:

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

当播放器插件在三星文件系统的不同位置执行时,您需要始终使用文件的绝对路径。它可以是远程的,但你可以使用应用程序的index.htmllocation.href来获得应用程序工作目录的绝对本地路径,你可以在那里放置mp3。

查看文档,此处:

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

这是我的解决方案:

添加到index.html文件

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

在我的.js文件中Scene1.js

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

我在2013和2014年款的电视上使用SDK版本5.1,我有以下代码:

<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');

这种替代方案也适用(使用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>

非常感谢多比亚托夫斯基!