views:

339

answers:

3

Hey guys,

I was wondering whether anyone has tried to use the new tag that comes with HTML5 on the iPhone. Specifically, I didn't manage to make the pause() command to work. Below is a portion of the page. As you can see, I'm trying to pause the video 10sec after it started. It works on Safari on a Mac btw. Has anyone managed to make this work?

<head>
<javascript language="JavaScript">

function timeUpdate()
{
 var myVideo = document.getElementsByTagName('video')[0];
 var time = myVideo.currentTime;
 if (time > 10)
 {
  myVideo.pause();
 }
}

function addListeners()
{
 var myVideo = document.getElementsByTagName('video')[0];
 myVideo.addEventListener('timeupdate',timeUpdate,false);
}

</script>
</head>

<body onload="addListeners()">
 <video controls src="resources/bb_poor_cinderella_512kb.mp4" 
  poster="resources/background.png">
  Video tag not supported!
 </video>
</body>

Thanks,
Ariel

A: 

You should use <script>, not <javascript language="JavaScript">.

Michael Aaron Safyan
+5  A: 

This code is invalid:

<javascript language="JavaScript"> 

There is no HTML tag called <Javascript>

To set the language to javascript, you should use this:

<script type="text/javascript">
// Code here
</script>

Note that the language attribute is deprecated according to the W3C standard (http://www.w3.org/TR/REC-html40/interact/scripts.html) so you should use type rather than language.

SLC
@SLC, FYI you don't need to specify the type in HTML5... "text/javascript" is assumed.
Michael Aaron Safyan
Better safe than sorry though :)
SLC
Nah: a lot of the work that went into HTML5 was Ian Hickson reverse-engineering browsers to see what worked, and writing the spec accordingly. So with an old tag like `<script>`, if HTML5 doesn’t require an attribute like `type`, you can be pretty sure that it’s not required.
Paul D. Waite
Thanks guys, but to my point - none of the above matters... it doesn't change the end result - still doesn't work on the iPhone, as opposed to Safari on Mac.I actually tried more things besides pause. For example - tried to register to onloadstart, or even to onplay, change the movie with the src attribute and call the load() function on the video element to play a different movie - doesn't work on the iPhone (works on Mac though).Does anyone have experience using these features on iPhone, and can tell what works and what doesn't?Thanks,Ariel
Ariel
+2  A: 

As far as i know iPhone wont let you play video inline in the mobile safari browser. So pausing wont work ofcourse. iPhone open the video in an external videoplayer, you dont have control over browser features, so the pausing doenst work.

Barry
Yeap, so I guess that's that...Thanks!
Ariel