繁体   English   中英

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

[英]playing sounds on samsung smart tv

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

您需要将播放器 object ( SAMSUNG-INFOLINK-PLAYER ) 添加到您的<body>标签中:

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

然后在应用程序的 javascript 中使用这个 function:

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

由于 Player 插件在三星文件系统内的不同位置执行,您需要始终使用文件的绝对路径。 它可以是远程的,但你可以使用你应用程序的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>

在 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");
...
...
...
}   

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

这个替代方案也有效(使用 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>

非常感谢 Dobiatowski!

暂无
暂无

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

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