這段時間太忙了,都沒時間我工作心得寫下來了,今天抽個時間把前兩天工作中碰到的一些很棘手的問題以及解決的方法:
問題描述:
embed標籤接受到直播流以後在IE下可以通過play()和pause()方法得到很好的播放/暫停控制,但在FireFox和safari 去無能為力,在Firefox和safari下可以正常的播放(在safari需要裝media外掛程式),但是就是通過play() 和pause()無法控制它的播放和暫停,問題的根源是Firefox和Safari不能很好的支援embed標籤。就這個一個小問題耗了好多時間,惱火啊!
解決方案:
也許會有更好的方法,我的解決方案是這樣的:當點擊暫停按鈕的時候,首先去判斷瀏覽器的類型,如果不是IE就直接把Embed這個標籤從DOM中remove掉,單點播放按鈕的時候再把Embed標籤動態載入到DOM中。就這樣,問題解決了。
相關代碼如下:
//包含Embed標籤的層
<div id="radio_container"><embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/mediaPlayer/" id="player" src="http://pub.qmoon.net:8009/911pop" name="player" width="0" height="0" volume="100"> </embed></div>
//暫訂
var trnode=document.getElementById("player");
trnode.parentNode.removeChild(trnode);
//播放
var container=document.getElementById("radio_container");
var str="<embed type=/"application/x-mplayer2/" pluginspage=/"http://www.microsoft.com/windows/mediaPlayer//" id=/"player/" src=/"http://直播流地址/" name=/"player/" width=/"0/" height=/"0/" volume=/"100/">";
container.innerHTML+=str;
哈哈,希望能對部分朋友有所協助哈^-^