HTML5 mp3 AUDIO & iPhone (etc)

July 17, 2014 at 00:55:59
Specs: All OS's, 2Ghz/ 2Gb
I found that using a simple instance of the <AUDIO> function played on computers/browsers on Androids, but not on iPhone.
This was found to be because the iPhone (etc) does not pre-load the track to save on bandwidth.
The solution that apparently works is (in practice) here http://stroudvoices.co.uk/search20
important code is:

<div id="player">Load Player</div>
&

<script language="JavaScript1.0" type="text/JavaScript">
var loadonce = 0;
function loadPlayer() {
if(loadonce++ > 0)return; //load only once
var audioPlayer = new Audio();
audioPlayer.controls="controls";
audioPlayer.src="http://stroudvoices.co.uk/wp-content/uploads/2014/04/instructions.mp3";
document.getElementById("player").appendChild(audioPlayer);
}
</script>

"loadonce" prevents multiple instances of players. Opera uses ogg so that is the next hurdle.

Any comments before I embed this into my search engine for the site? http://stroudvoices.co.uk/search-by...

TIA


See More: HTML5 mp3 AUDIO & iPhone (etc)

Report •

#1
July 17, 2014 at 01:02:10
Load Player is surrounded by a TAG
a href="#" onclick="loadPlayer()"
code did not display properly - not sure how to box it here.

Report •

#2
July 20, 2014 at 12:26:05
some people say it doesn't play on iPhone 5 others say it does -
this is my text page
http://stroudvoices.co.uk/search20

any testers out there

TIA

Knowledge knows what it knows, intelligence knows when it doesn't.


Report •

#3
September 8, 2014 at 14:28:58
this was my solution
along with HTML of

onClick="loadPlayer()"

<script language="JavaScript1.0" type="text/JavaScript">
var loadonce = [0,0,0,0,0];
var players=new Array;
players[1] = new Audio();
players[1].controls="";

function loadPlayer() {
if(loadonce[1]++ > 0){
if (loadonce[1]==2){ // 2 because it has already been indexed.
players[1].play();
}
if (loadonce[1]==3){ // 3 because it has already been indexed.
players[1].pause();
loadonce[1]=1; // rest to click for play
}
return; //load only once, second click is play, third pause etc.
}
players[1].src="instructions.mp3";
}
</script>

Knowledge knows what it knows, intelligence knows when it doesn't.


Report •

Related Solutions

#4
September 8, 2014 at 14:30:46
[SOLVED] [SOLVED] [SOLVED] [SOLVED]

can't find the solved button!

Knowledge knows what it knows, intelligence knows when it doesn't.


Report •

Ask Question