It is fairly easy to embed a QuickTime player in a Dashboard Widget. Dashcode(The IDE for development of a Dashboard Widget) provides us the library of Controls which can be added to the widget. Just drag the Quicktime player from the library onto the widget main front view.
The following code is automatically added in main.html file, upon adding the player to the widget..
<div id="video" apple-part="com.apple.Dashcode.part.videoLayout" apple-default-image-visibility="hidden" apple-group="video"> <video id="dc_ivideo" class="apple-hidden" controls="" apple-group="video"><!--[if IE]><object id="_ie_event_282475249" classid="clsid:CB927D12-4FF7-4a9e-A169-56E4B8A75598"></object><![endif]--> <object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" apple-group="video" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="100%" width="100%" style="behavior:url(#_ie_event_282475249);"> <param name="src" value=""> <param name="href" value=""> <param name="enablejavascript" value="true"> <param name="postdomevents" value="true"> <param name="scale" value="aspect"> <param name="loop" value="false"> <param name="autoplay" value="false"> <param name="controller" value="true"> <embed src="" pluginspage="http://www.apple.com/quicktime/download/" apple-group="video" enablejavascript="true" postdomevents="true" type="video/quicktime" target="myself" scale="aspect" style="width:100%;height:100%" height="100%" width="100%"> </object> </video> </div> </div>
if we intend to listen to an mp3 file at the location “sound/myaudio.mp3″ the above code works fine with only change in the code line <param name=”src” value=”sound/myaudio.mp3″>
This approach, however, has one limitation that we cannot change the content to listen at runtime. To listen to different audio following javascript code would do the trick.
getPlayer(url) { var div2 = document.createElement('div'); div2.style.position = "absolute"; div2.style.top = 80 +'px'; div2.style.height = "40px"; div2.style.backgroundColor = "#000000"; div2.style.width = "310px"; var player = document.createElement('embed'); player.enablejavascript="true"; player.type="audio/mpeg"; player.pluginspage="http://www.apple.com/quicktime/download/"; player.allowembedtagoverrides="true" player.applepart = "com.apple.Dashcode.part.quicktime"; player.target="myself"; player.id = "quicktimeplayer"; player.scale="aspect" player.showlogo = "false"; player.width="310" ; player.height = "32"; player.bgcolor="black"; player.autoplay= "true"; player.controller= true; player.src = url; player.volume = "50"; div2.appendChild(player); document.body.appendChild(div2); player.style.visibility = "visible"; }