Using jQuery i created a show/hide function with mouseover and mouseout which is also a link. The initial stage shows a description of the video link. When the nouse enters the description disappears and the word play appears. This works great for larger screens but not for touch devices. How can I remove this function so only the initial descripton is shown and remains a link. I haven't been coding long so I may have over complicated the code. All help appreciated:)
Paul
Heres a link to the site. This issue is regarding the first page.
https://paulevans-dop.com/
HTML
<div class="video_container1">
<section class="content1">
<video id="player1" class="vidSlider" autoplay muted playsinline loop>
<source src="showcase/showcase1.mov" type="video/mp4">
</video>
<a href="promo_player1_index.html"><ul class="vidNavigation" id="film1_card">
<li id="tag1a"><h1 id="title1">GHOST</h1><span class="videoFont"
id="description1">Director:
Amanda Demme. Lomo Vista Recordings</span></li>
<li id="tag1b"><h1 id="playbutton1">PLAY</h1></li>
</ul></a>
</section>
</div>
jQuery
// Showcase 1 TITLE
$(document).ready(function(){
$("#playbutton1").hide();
$("#film1_card").mouseover(function(){
$("#playbutton1").show();
});
$('#film1_card').mouseover(function () {
$('#title1').hide();
});
$("#film1_card").mouseout(function(){
if ($('#film1_card').is(':hover')) {
$('#playbutton1').show();
($('#film1_card').is(':hover'))
$('#playbutton1').hide();
} else {
$('#title1').show();
$('#playbutton1').hide();
}
});
$('#playbutton1').mouseout(function () {
$('#playbutton1').hide();
});
$("#playbutton1").mouseout(function(){
$("#title1").show();
});
});
// Showcase 1 DESCRIPTION
$(document).ready(function(){
$("#playbutton1").hide();
$("#film1_card").mouseover(function(){
$("#playbutton1").show();
});
$('#film1_card').mouseover(function () {
$('#description1').hide();
});
$("#film1_card").mouseout(function(){
if ($('#film1_card').is(':hover')) {
$('#playbutton1').show();
($('#film1_card').is(':hover'))
$('#playbutton1').hide();
} else {
$('#description1').show();
$('#playbutton1').hide();
}
});
$('#playbutton1').mouseout(function () {
$('#playbutton1').hide();
});
$("#playbutton1").mouseout(function(){
$("#title1").show();
});
});
Related
I am designing a website to teach Inuit Sign Language, and it uses the user's camera on multiple pages for the learner to practice signing. It does not stream nor save the signal anywhere: it is only meant to show the user his or her own webcam image. In Mozilla Firefox, the first page that loads the webcam works fine, but in every webpage that uses it after that, the webcam does not work. Reloading the page does nothing (even with CTRL-F5), but closing Firefox altogether and restarting it on the same page makes the camera works... but once again, only for the first page using it.
The bug is somewhat inconsistent, it always happens locally but not always on my host server, and Microsoft Edge works just fine with it. I have no idea what to do to fix this. It's as if Firefox hadn't freed the camera when I left the first webpage or something.
An example webpage can be found here: https://animamundilarp.com/isl_training_tests/practice_inuit_people.html
Click "Next page" twice to reproduce the issue.
Thank you to anybody who can tell me what I am doing wrong.
Here is my full code for the page:
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="mystyle.css">
</head>
<div class="row">
<div class="col-12"><H1>Inuit People</H1></div> <!-- 100% -->
</div>
<div class="row">
<div class="col-12"><P>Please allow the website to use your webcam for this learning activity. your webcam video is not recorded or sent anywhere on the Internet, and it will only display on your own screen.</P></div> <!-- 100% -->
</div>
<div class="row"> <!-- This row includes both the video and the webcam video -->
<div class="col-6"> <!-- This contains the video of the inuit sign -->
<video controls autoplay loop muted playsinline>
<source src="videos/Inuit_people.mp4" type="video/mp4">
Your browser does not support HTML video.
</video>
</div>
<div class="col-6">
<video id="media" controls></video>
</div>
</div>
<script>
navigator.getWebcam = (navigator.getUserMedia || navigator.webKitGetUserMedia || navigator.moxGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
if (navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({
// audio: true, // I keep this part of the code, but since we do not need audio, I kept it only as a comment, to reduce permissions asked by the website.
video: true
})
.then(function (stream) {
var video = document.getElementById("media");
video.srcObject = stream;
video.play();
})
.catch(function (e) {
logError(e.name + ": " + e.message);
});
} else {
navigator.getWebcam({
// audio: true, // I keep this part of the code, but since we do not need audio, I kept it only as a comment, to reduce permissions asked by the website.
video: true
},
function (stream) {
//Display the video stream in the video object
},
function () {
logError("your web cam is not accessible. If you do not have a webcam, you can use a mirror instead to see yourself signing.");
});
}
</script>
<P><button type="button" class="button_previous" onclick="Change_Page_to_Previous()"><span class="arrow_button">←</span> Previous</button> <button type="button" class="button_next" onclick="Change_Page_to_Next()">Next page <span class="arrow_button">→</span></button></P>
<script src="previous_and_next_functions.js">
</script>
You need to release the getUserMedia stream when your web page closes. How you do that is a bit of a kludge: you stop all the tracks in the stream.
(Also, all those alternative places to find the getUserMedia function are in the dustbin of history where they belong, so the code can be cleaner.)
Some Javascript code like this, not debugged, should work for you. Notice the unload event handler
const video = document.getElementById("media")
navigator.mediaDevices
.getUserMedia({ audio:false, video: true })
.then(function (stream) {
video.srcObject = stream
video.play()
window.addEventListener("unload", function(event) {
/* upon unloading do this */
const tracks = stream.getTracks()
tracks.forEach(function(track) {
track.stop()
})
video.srcObject = null
stream = null
})
})
.catch(function (e) {
logError(e.name + ": " + e.message)
})
I add videosphere using aframe. But in android browser it does not work. I am using Samsung S6. In S6 I checked many examples along with my code. It does not work.
<!DOCTYPE html>
<html>
<head>
<title>Hello, WebVR! - A-Frame</title>
<meta name="description" content="Hello, WebVR! - A-Frame">
<script src="https://aframe.io/releases/0.7.0/aframe.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
var scene = document.querySelector("a-scene");
var vid = document.getElementById("video");
var videoShere = document.getElementById("videoShere");
if (scene.hasLoaded) {
run();
} else {
scene.addEventListener("loaded", run);
}
function run () {
if(AFRAME.utils.device.isMobile()) {
document.querySelector('#splash').style.display = 'flex';
document.querySelector('#splash').addEventListener('click', function () {
playVideo();
this.style.display = 'none';
})
} else {
playVideo();
}
}
function playVideo () {
vid.play();
videoShere.components.material.material.map.image.play();
}
})
</script>
</head>
<body>
<div id="splash" style="display:none;">
<div id="start-button">Start</div>
</div>
<a-scene>
<a-assets>
<video id="video" src="https://ucarecdn.com/fadab25d-0b3a-45f7-8ef5-85318e92a261/" webkit-playsinline></video>
</a-assets>
<a-entity camera="userHeight: 1.6" look-controls cursor="rayOrigin: mouse"></a-entity>
<a-videosphere id="videoShere" loop="true" src="#video" rotation="0 -90 0"></a-videosphere>
</a-scene>
</body>
</html>
This is my code. What is the issue with my code? And why it does not work on android browser? Any way to solve this?
As per the A-Frame docs (https://aframe.io/docs/0.8.0/primitives/a-videosphere.html#caveats), you should have the following lines in your code to ensure they function properly in as many devices as possible:
<head>
...
<meta name="apple-mobile-web-app-capable" content="yes">
...
</head>
In the <video> element, itself, you will want to use this code to ensure that the video will play inline and will start playing immediately, if supported by the browser:
<video id="video" src="https://ucarecdn.com/fadab25d-0b3a-45f7-8ef5-85318e92a261/" autoplay loop playsinline webkit-playsinline crossorigin="anonymous"></video>
Note that crossorigin="anonymous" should be set when using assets hosted on other domains. It's also worth noting that some domains won't let you do this even if you use this code.
User interaction within the browser (outside of A-Frame) may be required to trigger the video for browsers that do not allow autoplaying by default. I modified your modal slightly to make it more visible:
<div id="splash" style="display: flex; height: 100%; width: 100%; z-index: 999999; position: absolute; background: rgba(0, 0, 0, 0.8);">
<div id="start-button">Start</div>
</div>
The javascript can be simplified just by placing the following code immediately before the ending </body> tag:
<script>
// User interaction modal to trigger video in some browsers/devices.
var modal = document.querySelector('#splash');
var video = document.querySelector('#video');
modal.addEventListener('click', function(e) {
video.play();
this.parentNode.removeChild(this);
});
</script>
Now, when a user clicks the modal splash screen, the event listener will capture the event, play the video, and remove the splash screen entirely from the DOM.
Here is a working demo: https://ultra-bass.glitch.me/
You just may need to add logic for detecting mobile devices, or more specifically, the devices that require this workaround.
i'm trying to hide the video controls on my video, until the user hover over the video, then the controls shows up. Any idea or advice? Thanks. And I've got more than one video.
HTML:
<div class="item spoon burger"><video width="300" height="auto" controls><source src="videos/sruthi.mp4" type="video/mp4"></video></div>
We can accomplish this through just a couple lines of jQuery, making use of .hover():
Working Example
$('#myvideo').hover(function toggleControls() {
if (video.hasAttribute("controls")) {
video.removeAttribute("controls")
} else {
video.setAttribute("controls", "controls")
}
})
Edit I mistakenly left the variable video in the code above. I changed it to this so that you won't have to manage variables that grab an ID.
$('#myvideo').hover(function toggleControls() {
if (this.hasAttribute("controls")) {
this.removeAttribute("controls")
} else {
this.setAttribute("controls", "controls")
}
})
HTML
<video width="300" height="auto" id="myvideo">
<source src="#" type="video/mp4" />
</video>
Update:
You mentioned that you have several videos. So you can use this same logic, and just add additional selectors into $( ). Here's an example:
$('#yourID1, #yourID2, #yourID3').hover(function toggleControls() { ...
Doing that will listen or wait until it detects that you're hovering over one of those IDs.
Updated fiddle
One issue with #EnigmaRM's answer is that if jQuery somehow misses a hover event, the controls can be toggled the "wrong" way - that is, they disappear on mouse enter and reappear on mouse leave.
Instead, we can ensure that the controls always appear and disappear correctly with event.type:
$("#myvideo").hover(function(event) {
if(event.type === "mouseenter") {
$(this).attr("controls", "");
} else if(event.type === "mouseleave") {
$(this).removeAttr("controls");
}
});
Untested, but I believe this would work. It uses JavaScript instead of CSS.
<div class="item spoon burger"><video id="videoElement" width="300" height="auto"><source src="videos/sruthi.mp4" type="video/mp4"></video></div>
<script type="text/javascript">
(function(window) {
function setupVideo()
{
var v = document.getElementById('videoElement');
v.addEventListener('mouseover', function() { this.controls = true; }, false);
v.addEventListener('mouseout', function() { this.controls = false; }, false);
}
window.addEventListener('load', setupVideo, false);
})(window);
</script>
<script>
function setupVideos() {
for (const video of document.querySelectorAll('video')) {
video.controls = false
video.addEventListener('mouseover', () => { video.controls = 'controls' })
video.addEventListener('mouseout', () => { video.controls = false })
}
}
window.addEventListener('load', setupVideos, false)
</script>
Using the code below, you don't need a separate javascript section (if that is a concern, which is the case sometimes). Just simply use onmouseover="this.play();this.setAttribute('controls','controls')" and onmouseout="this.load();this.removeAttribute('controls')"
If you don't want it to reset to a poster image, then you can get rid of the this.load.
<div class="img_placeholder">
<video width="350" height="250" loop preload="none" poster="../assets/icon-32.png" onmouseover="this.play();this.setAttribute('controls','controls')" onmouseout="this.load();this.removeAttribute('controls')">
<source src="../assets/bear.mp4" type="video/mp4" />
Your browser does not support the video tag.
</video>
</div>
A previous post explained how to do it this way HTML5 video - show/hide controls programmatically
<video id="myvideo">
<source src="path/to/movie.mp4" />
</video>
<p onclick="toggleControls();">Toggle</p>
<script>
var video = document.getElementById("myvideo");
function toggleControls() {
if (video.hasAttribute("controls")) {
video.removeAttribute("controls")
} else {
video.setAttribute("controls","controls")
}
}
</script>
Check if their solution works for you! Please +1 them if so!
This is a super simple question but I am stumped how to get the HTML to work out.
I have all the javascript set up, everything in place, but I don't know how to make the HTML work.
This is what I have
<div id="door">
<a href="inspect/squishdoor.html" onmouseover="document.door.src='storyimages/buttons/doorlarge.png'", "mouseoversound.playclip()" onmouseout="document.door.src='storyimages/buttons/doorlargeinv.png'">
<img src="storyimages/buttons/doorlargeinv.png" name="door"></a>
</div>`
I'd like it to display an image and play a sound, which it does if I choose one or the other but if they are next to each other it doesn't work.
You can use this code :
var $audio = $("audio_element"); //caching
$("object_element_id") .on ('mouseover', function(e){
$audio.play();
});
$("object_element_id") .on ('mouseout', function(e){
$audio.stop();
});
Or simply this
var audio = $("#audio");
$("play a").mouseenter( function() {
audio.play();
}
Where audio is that audio element and play a is element which is hovered.
And how to add these function. There is one example
CODE:
<!DOCTYPE html>
<html>
<body>
<button onclick="playVid()" type="button">Play Video</button>
<button onclick="pauseVid()" type="button">Pause Video</button>
<br>
<video id="video1">
<source src="mov_bbb.mp4" type="video/mp4">
<source src="mov_bbb.ogg" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<script>
var myVideo=document.getElementById("video1");
function playVid()
{
myVideo.play();
}
function pauseVid()
{
myVideo.pause();
}
</script>
<p>Video courtesy of <a href="http://www.bigbuckbunny.org/" target="_blank">Big Buck
Bunny</a>.
</p>
</body>
</html>
I have searched all over google for this and nothing does what it is supposed to
It works perfect in IE ... You can see it in the logs that it works perferct ... But it wont work in chrome!!!
Why is it doing so in chrome ? ... It loads 10sek from catche and then nothing ...
<div style=" width:100%; height:320px; margin-top:-95px; background-image:url('video-logo.png'); background-repeat:no-repeat; background-position:center;">
<div id="videoRain" class="videoWrapper" style="text-align:center; display: none;">
<video id="rainVideo" width="100%" height="400px" preload="auto">
<source src="rain-video.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
</div>
<script>
setTimeout(function(){
var refreshId = window.setInterval(function(){
myVid=document.getElementById('rainVideo');
puhvitud = Math.round(myVid.buffered.end(0));
if (puhvitud >= 14) {
setTimeout(function(){document.getElementById('videoRain').style.display='block';},0);
setTimeout(function(){document.getElementById('rainVideo').play();},0);
clearInterval(refreshId);
setTimeout(function(){document.getElementById('videoRain').style.display='none';},15000);
}
console.log(puhvitud);
}, 2000);
},1000);
</script>
Maybe someone has another way to do this ?
When the video is fully loaded ... this should be ran...
setTimeout(function(){document.getElementById('videoRain').style.display='block';},0);
setTimeout(function(){document.getElementById('rainVideo').play();},0);
setTimeout(function(){document.getElementById('videoRain').style.display='none';},15000);
EDIT:
Tried this:
<script>
function runVideoRain(){
rainVideo.addEventListener("loadeddata", runRain, false);
}
function runRain()
{
setTimeout(function() {document.getElementById('videoRain').style.display='block';},0);
setTimeout(function(){document.getElementById('rainVideo').play();},0);
setTimeout(function() {document.getElementById('videoRain').style.display='none';},15000);
}, false);
</script>
Does not work !!
Uncaught SyntaxError: Unexpected token ,
Uncaught ReferenceError: runVideoRain is not defined
onloadeddata
You can use the onloadeddata attribute.
onloadeddata : Script to be run when media data is loaded
<video id="rainVideo" width="100%" height="400px" preload="auto" onloadeddata="runMyFunction();">
<source src="rain-video.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<script>
function runMyFunction(){
alert('The video is loaded');
}
</script>
It seems that onloadeddata attribute does not work on chrome. But attaching an event handler through addEventListener does the trick !
rainVideo.addEventListener("loadeddata", myRunFunction, false);
//with jQuery
$(rainVideo).on("loadeddata", myRunFunction);