简体   繁体   中英

Load audio files to HTML5 audio player through jQuery

Is there a way to load the audio file sources through jquery? Instead of loading it inline through HTML?

Example:

<audio controls="controls">
  <source src="track.ogg" type="audio/ogg" />
  <source src="track.mp3" type="audio/mpeg" />
Your browser does not support the audio element.
</audio>

Technically wouldnt I be able to call on the children of the audio and replace the attr of src to my desired URL?

jPlayer is an HTML5 audio and video player for jQuery. It can dynamically load a media : http://jplayer.org/latest/developer-guide/#jPlayer-setMedia

$('#jquery_jplayer').jPlayer('setMedia', {
    mp3: 'media/audio/song.mp3',
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM