make style on html5 audio player timeline

匿名 (未验证) 提交于 2019-12-03 08:54:24

问题:

I want to make a style on html5 audio player.

    <audio id="player" controls="controls">         <source src="song.ogg" type="audio/ogg" />          <!-- using mozilla firefox -->         Your browser does not support HTML5 audio. Please upgrade your browser.     </audio> 

Is it possible to put css style on the html5 generic audio player timeline?

-thanks.

回答1:

The following code, when pasted into Chrome's developer console, reveals a document fragment that describes the audio element's structure:

var aud = document.createElement('audio'); document.querySelector('body').appendChild(aud); aud.controls = true; 

Going to the chrome debugger's elements tab reveals this document fragment:

<div>  <div>   <div>    <input type="button">    <input type="range" precision="float" max="0">    <div style="display: none;">0:00</div>    <div>0:00</div>    <input type="button">    <input type="range" precision="float" max="1" style="display: none;">    <input type="button" style="display: none;">    <input type="button" style="display: none;">   </div>  </div> </div> 

If there was a way to change the style of the time display or the play/pause button without redefining the inner structure(i.e. shadow DOM), it would be through that document fragment. There is neither a function nor an attribute that suggests the ability to access said document fragment.



回答2:

Youtube does their own HTML5 video timeline in case someone wants to "try something new"(or just hack an easy way to download some of their ad-free WebM videos), so I know it is possible. I'm guessing you would need to do it like this:

 <audio id="player" ><!--notice how you get rid of the controls -->         <source src="song.ogg" type="audio/ogg" /> <!-- using mozilla firefox -->         Your browser does not support HTML5 audio. Please upgrade your browser.     </audio> 

If you have the audio player hidden, you can add Event Listeners to update the status/progress. You will definitely want to use at least onTimeUpdate

Meanwhile, you can make your own DOM controller with a square tags with border-radius = (width/2) for a circle, or just use a . I suggest you look into the Shadow DOM for a way to hide functionality from both users and other scripts. If you want to just show the user how far the music has played and not allow the user to seek, use a tag or a tag. Otherwise, you can use an tag and stylize that. Don't forget to add an onInput handler to skip through the track.

edit

I did not see that image. You must have uploaded it while I was answering. I would suggest you use a filter, but that might not work on anything but images. Try making a div transparent over it and allowing the user to click through it

edit #2

It turns out that background-color kinda tints the player in Chrome(only the audio player) depending on the background color, but the play time color does not change color with either background-color or color. You can get full control and uniformity over your style with a custom player, but that would mean extra work for you. I hope that my answers were helpful.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!