ATXcloud
ATXcloud

Reputation: 31

iDevice onclick not playing video with current code

My ultimate goal is to have on iDevices viewing my website, an image link that on click, plays a video at full screen, and upon finish of video redirects to another webpage. I am open to any solution that achieves my goal, even if it means scrapping the code I've got.

Here is my best attempt as of yet: This is My current testing site

I was following this stackoverflow post

I am happy with the results on my laptop [edit works on Chrome but not FF 16.0.1 sigh I don't know anymore), but I am currently unable to click the image to play the video on my iDevices (ipad1 & iphone4). I've spent hours attempt to achieve this by researching, trial & error to no prevail.

Here is the code I am working with:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0" />
<meta name="description" content="" />
<title>test</title>

<script type="text/javascript">

    function videoEnd() {
        var video = document.getElementById("video");
        video.webkitExitFullScreen();
        document.location = "http://www.atxcloud.com/wp-content/uploads/Panos/beerdiaries/jk5%20all/build.html";
    }

    function playVideo() {
        var video = document.getElementById("video");
        video.addEventListener('ended', videoEnd, true);
        video.webkitEnterFullScreen();
        video.load();
        video.play();
    }

</script>
</head>
<body>
<video id="video" poster="http://www.atxcloud.com/wp-content/uploads/Panos/beerdiaries/RnD/image.png" onclick="playVideo();">
    <source src="http://www.atxcloud.com/wp-content/uploads/Panos/beerdiaries/RnD/video.mp4" type="video/mp4" />
</video>
</body>
</html>

Upvotes: 3

Views: 403

Answers (1)

user2008398
user2008398

Reputation: 17

If a browser doesn't support the fullscreen API (http://caniuse.com/#feat=fullscreen) then that may throw an error in your playVideo function. Try this modification:

function videoEnd() {
    var video = document.getElementById("video");
    if(video.webkitExitFullScreen) video.webkitExitFullScreen();
    document.location = "http://www.atxcloud.com/wp-content/uploads/Panos/beerdiaries/jk5%20all/build.html";
}

function playVideo() {
    var video = document.getElementById("video");
    if(video.webkitEnterFullScreen) video.webkitEnterFullScreen();
    video.load();
    video.play();
}

<video id="video" poster="http://www.atxcloud.com/wp-content/uploads/Panos/beerdiaries/RnD/image.png" onclick="playVideo();" onended="videoEnd();">
<source src="http://www.atxcloud.com/wp-content/uploads/Panos/beerdiaries/RnD/video.mp4" type="video/mp4" />

Upvotes: 1

Related Questions