Advertisement
Bedhoel

speaker_2

Feb 2nd, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. <script type="text/javascript">
  2. var audioFiles = [
  3. <?php echo $order_sound ?>
  4. ];
  5.  
  6. function preloadAudio(url) {
  7. var audio = new Audio();
  8. // once this file loads, it will call loadedAudio()
  9. // the file will be kept by the browser as cache
  10. audio.addEventListener('canplaythrough', loadedAudio, false);
  11. audio.src = url;
  12. }
  13.  
  14. var loaded = 0;
  15. function loadedAudio() {
  16. // this will be called every time an audio file is loaded
  17. // we keep track of the loaded files vs the requested files
  18. loaded++;
  19. if (loaded == audioFiles.length){
  20. // all have loaded
  21. init();
  22. }
  23. }
  24.  
  25. var player = document.getElementById('player');
  26. function play(index) {
  27. player.src = audioFiles[index];
  28. player.play();
  29. }
  30.  
  31. function init() {
  32. // do your stuff here, audio has been loaded
  33. // for example, play all files one after the other
  34. var i = 0;
  35. // once the player ends, play the next one
  36. player.onended = function() {
  37. i++;
  38. if (i >= audioFiles.length) {
  39. // end
  40. //return;
  41.  
  42. $.ajax({
  43. url: 'ajax/panggil',
  44. type: 'POST',
  45. dataType: 'html',
  46. data: 'id_pg=<?php echo $data['id_panggilan'] ?>',
  47. success: function(mydata) {
  48. location.reload();
  49. }
  50. });
  51.  
  52. }
  53. play(i);
  54. };
  55. // play the first file
  56. play(i);
  57. }
  58.  
  59. // we start preloading all the audio files
  60. for (var i in audioFiles) {
  61. preloadAudio(audioFiles[i]);
  62. }
  63. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement