音乐播放器dewplayer的使用

介绍一个flash音乐播放器:dewplayer(法国的)
官网地址:http://www.alsacreations.fr/dewplayer.html。它提供几种风格,根据自己的需要选择一种风格。下面说一下用javascript来操作dewplayer

引入swfobject.js

1
<script type="text/javascript" src="swfobject.js"></script>

然后是js代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var dewp = document.getElementById("dewplayerjs");
function play() {
            if(dewp!=null) dewp.dewplay();
          }
          function stop() {
            if(dewp!=null) dewp.dewstop();
          }
          function pause() {
            if(dewp!=null) dewp.dewpause();
          }
          function next() {
            if(dewp!=null) dewp.dewnext();
          }
          function prev() {
            if(dewp!=null) dewp.dewprev();
          }
          function set(file) {
            if(dewp!=null) dewp.dewset(file);
          }
          function go(index) {
            if(dewp!=null) dewp.dewgo(index);
          }
          function setpos(ms) {
            if(dewp!=null) dewp.dewsetpos(ms);
          }
          function getpos() {
            if(dewp!=null) alert(dewp.dewgetpos());
          }
          function volume(val) {
            if(dewp!=null) alert(dewp.dewvolume(val));
          }            

html代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
     <div id="dewplayer_content_js">
      <object data="dewplayer.swf" width="200" height="20" name="dewplayer" id="dewplayerjs" type="application/x-shockwave-flash">
      <param name="movie" value="dewplayer.swf" />
      <param name="flashvars" value="mp3=mp3/test1.mp3|mp3/test2.mp3|mp3/test3.mp3&javascript=on" />
      <param name="wmode" value="transparent" />
      </object>
      </div>
      <p>
      <input type="button" onclick="play();" value="Play" />
      <input type="button" onclick="stop();" value="Stop" />
      <input type="button" onclick="pause();" value="Pause" />
      <input type="button" onclick="next();" value="Next" />
      <input type="button" onclick="prev();" value="Prev" />
      <input type="button" onclick="go(2);" value="Go(2)" />
      <input type="button" onclick="set('mp3/test2.mp3');" value="Set mp3" />
      <input type="button" onclick="set('mp3/test3.mp3');" value="Set another mp3" />
      <input type="button" onclick="setpos(10000);" value="Set position 10 sec" />
      <input type="button" onclick="getpos();" value="Get position" />
      <input type="button" onclick="volume(50);" value="Set volume 50%" />
      </p>