Audio5js HTML5音频播放兼容性解决方案

  /
  -/public
  --/js
  --- audio5.js
  --/swf
  --- audio5js.swf

 <script src="/js/audio5.js"></script>
  <script>
    function initAudio () {
      var audio5js = new Audio5js({
        ready: function () {
          this.load('/someaudio.mp3');
          this.play();
        }
      });
    }
    initAudio();
  </script>


var audio5js = new Audio5js({
    swf_path: './swf/audio5js.swf',
    codecs: ['mp4', 'vorbis', 'mp3'],
    ready: function(player) {
      var audio_url;
      switch (player.codec) {
      case 'mp4':
        audio_url = '/audio/song.mp4';
        break;
      case 'vorbis':
        audio_url = '/audio/song.ogg';
        break;
      default:
        audio_url = '/audio/song.mp3';
        break;
      }
      this.load(audio_url);
      this.play();
    }
  });


<a id="play">Play / Pause</a>
  <a id="seek">Move to Start</a>
  <script>
    var play = document.getElementById('play');
    var seek = document.getElementById('seek');

    var playPause = function () {
      this[this.playing ? 'pause' : 'play']();
      // or simply call this.playPause();
    }

    var moveToStart = function () {
      this.seek(0);
      this.volume(1);
    }

    var audio5js = new Audio5js({
      ready: function () {
        this.load('/audio/song.mp3');
        play.addEventListener('click',
          playPause.bind(this));
        seek.addEventListener('click',
          moveToStart.bind(this));
      }
    });
  </script>


Playback API

Audio5js lets you control the life-cycle of audio playback with the following API:

  • load - Load an audio file to the player
  • play - Play loaded audio
  • pause - Pause playing audio
  • playPause - Toggle audio play / pause
  • volume - Get / Set audio volume
  • seek - Seek audio to time

You should note the following when using the playback API:

  • Volume values range from 0 to 1.
  • Seek values are should be passed asseconds of total audio duration.









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值