[英]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.html
的location.href
來獲取你可以放置 mp3 的應用程序工作目錄的絕對本地路徑。
在此處查看文檔:
這是我的解決方案:
添加到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.