A Web Component to randomly change audio or video sources.
<script type="module" src="random-source.js"></script>
<random-source>
<audio controls>
<source src="https://darn.es/sounds/daviddarnes.m4a" />
<source src="https://darn.es/sounds/daviddarnes2.m4a" />
</audio>
</random-source>This Web Component allows you to:
- Randomly change the source of an
audioorvideoelement once the source has ended - Trust that the first
sourceelement will always be used on load, to match default behaviour
You have a few options (choose one of these):
- Install via npm:
npm install @daviddarnes/random-source - Download the source manually from GitHub into your project.
- Skip this step and use the script directly via a 3rd party CDN (not recommended for production use)
Make sure you include the <script> in your project (choose one of these):
<!-- Host yourself -->
<script type="module" src="random-source.js"></script><!-- 3rd party CDN, not recommended for production use -->
<script
type="module"
src="https://www.unpkg.com/@daviddarnes/random-source@1.1.1/random-source.js"
></script><!-- 3rd party CDN, not recommended for production use -->
<script
type="module"
src="https://esm.sh/@daviddarnes/random-source@1.1.1"
></script>With thanks to the following people:
- Zach Leatherman for inspiring this Web Component repo template