The easy way would be to not have multiple separate audio tracks if possible, so you can just pause / unpause a single track. But if that's not possible, you'll need to use the Hype timeline, the audio track durations, and do some calculation based on what should be playing.
The 'pause' audio button is easy: Just pause all playing audio elements:
var myAudio1 = document.getElementById("sample1");
var myAudio2 = document.getElementById("sample2");
var myAudio3 = document.getElementById("sample3");
myAudio1.pause();
myAudio2.pause();
myAudio3.pause();
And also pause the timeline.
Make sure you use a different 'var' value that is the same wherever you wish to control the audio.
The basic answer for a smarter 'unpause' button is something like:
if (hypeDocument.currentTimeInTimelineNamed('Main Timeline') > 14 && < 24)) {
myAudio2.play();
}
This says play audio2
only if the timeline is greater than 14 and less than 24.
You could potentially make this smarter and less manual: You'll need to know 'what track is playing at this point in the timeline' so you can unpause correctly without replaying each audio track again, but you'll need to know the track's order in playback to determine what should be playing at that time.
You can get properties of the Hype timeline itself (its duration and current position) by using these two functions:
hypeDocument.currentTimeInTimelineNamed('timelineName')
Returns the current time of the specified timeline in seconds.
hypeDocument.durationForTimelineNamed('timelineName')
Returns the duration of the specified timeline in seconds.
To know which audio elements to unpause when, you might want to look at the hypeDocument.currentTimeInTimelineNamed('timelineName')
and then calculate which audio should be playing. I'm not sure if you wanted to do this all programmatically, but you could pull in the duration of each of the audio tracks, the combined duration of these tracks, and then an approximate relationship between these tracks and the timeline based on their ID.
You can get the duration of an audio track (audioID) by using:
setTimeout(function () {
var audio = document.getElementById('audioID');
console.log("audio", audio.duration);
}, 100);
More info: https://stackoverflow.com/questions/11203773/how-can-i-get-the-html5-audios-duration-time
You could theoretically combine these 'duration' values to determine at what point an audio element should be unpaused.