Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/andycall/mobile-audio-player

跨平台音频播放器
https://github.com/andycall/mobile-audio-player

Last synced: 6 days ago
JSON representation

跨平台音频播放器

Awesome Lists containing this project

README

        

# mobile-audio-player
跨平台音频播放器

## 使用方式

```javascript
var player = $('#audioPlayer').audioPlayer({
controls: true, // 使用默认的控制界面
loop: false, // 重播
debug: false, // 开启debug输出
src: 'http://localhost:9020/halfbottle.mp3', // 默认的音频播放地址
onSrcChange: function (e, src) {
console.log('src change', src);
$('#player_status').append('

src change: ' + src + '

');
},
onAudioEnd: function (e) {
console.log('this sound is end!');
$('#player_status').append('

sound is end

');
},
onPlaying: function (e, second) {
console.log('current played', second);
$('#played').html(second.toFixed(2) + 's');
},
onPause: function (e, src) {
console.log('sound paused', src);
$('#player_status').append('

sound pause: ' + src + '

');
},
onPlay: function (e, src) {
console.log('sound is going to play!', src);
$('#player_status').append('

sound is going to play: ' + src + '

')
},
onError: function (e, error) {
console.log(error);
},
selector: {
played: '#played', // 显示播放进度
playButton: '.play-button' // 播放按钮选择器
}
});

```

## 播放控制

假如目前播放的地址为 `http://localhost:9020/halfbottle.mp3`

player.play('http://localhost:9020/halfbottle.mp3') // 传入相同的地址可以控制播放与暂停

var button = document.querySelector('.play-button');
player.play('http://localhost:9020/halfbottle.mp3', button); // 传入播放按钮的DOM对象就能为该DOM对象修改播放进度