I'm trying to use this slider: http://tympanus.net/codrops/2012/06/05/fullscreen-slit-slider-with-jquery-and-css3/ but want to play a different audio file, each time the slide loads.
The way I imagine it working, is for the user to click play on the first slide, the audio to finish playing, then for the slide to change and it automatically plays the next audio file and so it continues until all slides are played through.
I've gotten it to the point where the slider changes when the audio has stopped, but cannot figure out how to play the next audio file, one after the other.
I'm very new to jQuery and am struggling a lot. Any help would really be appreciated!
Here is my work in progress: http://dailycrow.me/actualsite/
Thank you.
What I would do is to handle the audio playing with an scripting language such as PHP and call the needed method with parameters with Javascript or JQuery.
You can embed HTML with PHP so the audio can be played. Something like this:
$audioFile = "wishedAudioFile.mp3";
echo '<embed src="'.$audioFile.'" hudden="true" autostart="true"></embed>';
you can maintain an array of sources, where each index refers to a slide index, and from looking at this doc, you can use the onAfterChange event, code would be something like:
var audio = new Audio(), audSrcList = [
'slide1.wav',
'slide2.wav',
'slide3.wav',
'slide4.wav'
...
];
function afterSlideChange(slide, index){
audio.src = audSrcList[index];
audio.play();
};
...
$.Slitslider.defaults = {
...
// callbacks
onBeforeChange : function( slide, idx ) { return false; },
onAfterChange : afterSlideChange //CHANGED here
};
Related
I'm supposed to have 5 animal images on the site, and whenever I hover over an animal, their characteristic sound plays. Is there a more efficient way to do this rather than using switch case?
This is what I have so far (works only for 1 animal):
HTML:
<img src="img/piggy.png" onmouseover="F1(this)">
JS:
function F1(img) {
var audio = document.getElementById("audio");
audio.play();
}
I think this is a really solid base. If it were me I would do almost exactly what you are doing but set up an array with the list of available sound bites. Then, onmouseover pass in a number (0-5) and use that as the selector to choose which soundbyte plays.
var sounds = ["sound1", "sound2", "sound3", "sound4", "sound5"];
function playAudio(track) {
audio.play(sounds[track]);
}
Hopefully that's clear/helpful. Otherwise, let me know and I'll be glad to clarify.
You can have the sound to play embedded in the img tag's dataset :
<img src="img/piggy.png" data-sound='piggy.wav' onmouseover="playSound(this)">
function playSound(element) {
var audio = new Audio(element.dataset.sound);
audio.play();
}
you may want to pre-load all of the audio files on page load
I happily use Reveal.js for presentation purposes, but now I want to create MOOCS using the fine script. I want to put an audio clip with each fragment, that starts playing when the fragment is shown. So far that works fine using the eventListener method to start and pause audio in my slideshow. However, given the nature of this method, the audio or video will continue when the next fragment is shown, as it is dependent on the status of 'fragmentshown' or 'fragmenthidden'. (see below)
Reveal.addEventListener( 'fragmentshown', function( event ) {
var audio = event.fragment.querySelector( 'audio' );
if( audio ) {
audio.play();
}});
Reveal.addEventListener( 'fragmenthidden', function( event ) {
var audio = event.fragment.querySelector( 'audio' );
if( audio ) {
audio.pause();
}});
Is there an easy way to extend this using the 'current-fragment' class that's added to the fragment that is current (duh), to pause (or better yet: stop) the audio when the class is passed on to the next fragment? I'm sure there is, but I'm a novice and would really appreciate a heads up here. It would be great for moocing purposes if this would be part of the code. I get lots of requests for it from teaching colleagues at our university.
To generate a MOOC you can use the audio-slideshow plugin that does the job for you. The plugin allows you to specify an audio file for each slide and fragment. Alternatively, it automatically checks if there is an audio file for the slide and fragment based on the reveal.js indices, e.g. for the second horizontal and first vertical slide ist checks whether there is a file audio/1.0.ogg.
You can also record the audio while presenting using the slideshow-recorder plugin or use text-to-speech.
You can find a demo here and the plugin here
Asvin
I have a HTML page with an image in it.
When I roll-over the image with my mouse it plays an audio file.
I have 4 different audio files, and each time I roll-over the image I need it to play the next audio-file in the sequence.
I've got it playing one audio-file back ok, but how do I get it calling the next audio-file in the queue?
Its likely you just need to make a javascript function on the webpage to handle this. Without seeing your codes I can't really give you a good example. Here is what I would do. Within a a script tag or head javascript:
var current = 0;
var musicList = ["file1.wav", "file2.wav" , ...];
function playSound()
{
// Code to play audio file
// you don't need to bother with <audio> elements.
// HTML 5 lets you access audio API directly
// buffers automatically when created
var snd = new Audio(musicList[current]);
snd.play();
// code to increment and current counter (depending on musicList size)
current++;
current = current % musicList.length;
}
Within your HTML, you can just rely on javascript to do the work by using the onmouseover or onmouseout tag.
<img onmouseover="playSound();" src="smiley.gif" alt="Smiley">
I'm trying to use jQuery to control an HTML5 audio element, but I'm no genius with JS.
What I want is for the player to start on page load, which I've done, but when the play button is clicked, I want to check whether or not the audio is playing.
If it's playing when clicked: Stop the audio.
If it's not playing when clicked: Play the audio.
If you could help, it'd be much appreciated.
Source here: http://www.julake.co.uk/media/loader.php?page=contact
Many thanks,
you should use a single play/pause toggle button in which you need to check if your audio is paused or not
var audioplayer = document.getElementById("audio-player");
$("#play-bt").click(function(){
if (audioplayer.paused) {
audioplayer.play();
}
else {
audioplayer.pause();
}
$(this).toggleClass('pause'); /* style your toggle button according to
the current state */
})
var audio = new Audio("http://www.w3schools.com/html5/song.ogg"); //or you can get it with getelementbyid
audio.addEventListener('canplay', function() {
//code, when audio can play
audio.play(); //this function will start the music
})
with audio.play() function you can start it. You don't need JQuery
If you wish to use a jquery selector or have a jquery selector already, you can add [0] to get the native dom element.
So an example that actually uses jquery would be.
$('audio')[0].pause()
I'm able to get two videos to play sequentially, (and without pause!) with this code from Apple, (see section 2-4)...
https://developer.apple.com/library/content/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/ControllingMediaWithJavaScript/ControllingMediaWithJavaScript.html
...Yet completely lost as to how to play a 3rd or 5th video. Trouble is I'm a Javascript noob :-(, so if you figure this out please share as much of your code as possible.
The first video's ended => Start second video
The second video's ended => Start third video
The third video's ended => Start fourth video
The fourth video's ended => Start first video
It's just redefining the ended event handler nonstop...
You could also use a variable starting at 0. increment it each time and set SRC to i%video_count
var i = 0;
var sources = ["http://www.a.com/blargh.m4v", "http://www.b.com/blargh.m4v"];
videoElement.addEventListener('ended', function(){
videoElement.src = sources[(++i)%sources.length];
videoElement.load();
videoElement.play();
}, false);
...The above code assumes the video is already playing onload, like your example