最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to customize html5 audio player - Stack Overflow

programmeradmin2浏览0评论

I'm doing a html5 audio player so I'm trying to use a custom player. I don't want to use the default <audio> tag interface. I want to do my own html/css styles for the player.

My actual code(it works)

if('webkitAudioContext' in window) {
    var myAudioContext = new webkitAudioContext();
    }

    request = new XMLHttpRequest();
    request.open('GET', 'http://96.47.236.72:8364/;', true);
    request.responseType = 'arraybuffer';
    request.addEventListener('load', bufferSound, false);
    request.send();

    function bufferSound(event) {
      var request = event.target;
      var source = myAudioContext.createBufferSource();
      source.buffer = myAudioContext.createBuffer(request.response, false);
      source.connect(myAudioContext.destination);
      source.noteOn(0);
    }

/

Does someone know how can to edit this player style, or do something to use my own html/css code to execute this player?

I'm doing a html5 audio player so I'm trying to use a custom player. I don't want to use the default <audio> tag interface. I want to do my own html/css styles for the player.

My actual code(it works)

if('webkitAudioContext' in window) {
    var myAudioContext = new webkitAudioContext();
    }

    request = new XMLHttpRequest();
    request.open('GET', 'http://96.47.236.72:8364/;', true);
    request.responseType = 'arraybuffer';
    request.addEventListener('load', bufferSound, false);
    request.send();

    function bufferSound(event) {
      var request = event.target;
      var source = myAudioContext.createBufferSource();
      source.buffer = myAudioContext.createBuffer(request.response, false);
      source.connect(myAudioContext.destination);
      source.noteOn(0);
    }

http://jsfiddle/EY54q/1/

Does someone know how can to edit this player style, or do something to use my own html/css code to execute this player?

Share Improve this question edited Apr 10, 2014 at 8:44 Dirty-flow 2,30011 gold badges30 silver badges49 bronze badges asked Feb 10, 2014 at 17:48 Wagner MoreiraWagner Moreira 1,0881 gold badge17 silver badges43 bronze badges 2
  • Check this one out [Editing audio player][1] [1]: stackoverflow./questions/4126708/… – PlaceUserNameHere Commented Feb 10, 2014 at 17:54
  • It's alright to have a link to a working jsfiddle, but it also helps to have the relevant code in the question itself (links aren't valid forever). – ohmu Commented Feb 10, 2014 at 19:21
Add a ment  | 

2 Answers 2

Reset to default 4

You can pletely make your own style. just forget about the controls option (you can simply use controls and do not need to use controls="controls"). Just create buttons/divs/whatever, style them, and add an eventlistener that controls the audio interface:

html:

<button id="playpause">play
    <!--you can style the content with anything!-->
</button>
<audio id="player">
    <source src="http://96.47.236.72:8364/;" />
</audio>

JS:

window.player = document.getElementById('player');
document.getElementById('playpause').onclick = function () {
    if (player.paused) {
        player.play();
        this.innerHTML = 'pause';
    } else {
        player.pause();
        this.innerHTML = 'play';
    }
}

http://jsfiddle/LqM9D/1/

I see you are also using the audio api. Please note that you can't just dump an audio file in a buffer. It needs to be decoded to raw PCM. This takes a lot of time. A really easy method is to create a source node which is linked to the audio element:

var source = context.createMediaElementSoure(player); //we defined player in the first block of code

To make your page a bit more cross-browser capable:

window.AudioContext = window.AudioContext||window.webkitAudioContext;
context = new AudioContext();

Edit:

I think you want to know what else you can do with the element. You can also make a slider for the timeline, and a volume slider/mute button, although I'd prefer the latter two to do that on a gainnode at the end of a line of filters and such.

Yes. It is possible via "shadow dom". You just need to enable it in your browser and write styles for elements, that will arrive.

As I understend - it is browser specific feature. But for webkit-based styling of "shadow dom" work perfect. There is not so many info, however this feature already used in full. For example see this question: Why do no user-agents implement the CSS cursor style for video elements If you enable displaying shadow dom in inspector setting, you will se how it works. (Also there is public list with selectors list - https://gist.github./afabbro/3759334)

For other browsers you need check support of working with "shadow dom".

发布评论

评论列表(0)

  1. 暂无评论