Hello Hype community!
I am very much hoping to get some input/help with a project I’m working on.
It’s an online interactive album.
I’ve included a Hype mockup that is a bare-bones version of the site with only navigation, sounds, and 3 pages (instead of what will ultimately be 12).
Much of it is working, but I’m having a hard time tracking down an issue described below.
I’d think if you just download the example and start messing around you will quickly see what it is I’m trying to build and what the behavior should be.
Download here:
autoPlayTest3.zip (225.4 KB)
If you do checkout the Hype project, when previewing, make sure to open up the Chrome dev tools console to see what’s going on behind the scenes. I’ve tried to document major actions with console.logs.
Also, FWIW, I am wondering not only how to fix the issues I’m having with my current setup, but also wondering if anyone might have ideas for refactoring my code or even totally restructuring my code so that I can get the behavior I’m looking for in the dry-est way possible? I’m not sure that the way I’ve laid it out here is the best way to do it.
So, here is a more detailed explanation of what I’m trying to do and where I’m at with it:
I’m in the process of building an autoplay/audio playback/navigation system that allows the user to choose and play a song/scene manually, or click an autoplay button that automatically plays the album, song-to-song, all the way through. Each song in the album has its own page that will contain the lyrics and animated album art for that song. Each page is built as consecutive scenes in Hype. I’m using howler.js for the audio, which is all set up and working great. It’s the autoplay system that is not quite working right.
Here is an explanation of how the autoplay system should behave and what’s going wrong:
There is an autoplay button on each song/scene page.
Say a user chooses a song (either from the main menu, or by clicking through the various song/scene pages manually), and then the user presses autoplay.
Here is how the autoplay sequence should behave:
-
Let’s say the user has navigated to a given scene/page (let’s say scene 1).
-
When the autoplay button on that scene/page is clicked, the autoplay sequence will be switched on and the song should start playing (let’s call it song1).
-
At the end of the song1, since the autoplay button is switched on, a function will be triggered that switches to the next Hype scene, which contains the next song/scene in the album (song2).
-
At the end of that song (song2), the process repeats (automatically switching and triggering the next scene and next audio track) until the entire album plays through.
-
When the last song/scene is reached (lets say song12 in order to represent a full album of songs), it then automatically switches to the beginning (song1) and continues to play the album through in an infinite loop until the autoplay button is turned off.
-
When the autoplay button is turned off (while the song is playing), the song that is currently playing will just play though and then stop (thereby halting any further autoplay actions).
-
There is an autoplay button located on the menu page and the intro page. Clicking either of these autoplay buttons should automatically switch to song/scene1 and trigger song1 playback and following through with the rest of the autoplay sequence as outlined above.
-
If a user navigates to a given song/scene (let’s say song3) and then presses the autoplay button (and no song is currently playing), then song3 will be triggered to play and then at the end of that song, the autoplay sequence will continue.
-
If a user navigates to a given song/scene (let’s say song7) and then presses the autoplay button (and no song is currently playing), then song7 should be triggered to play, then at the end of the song, the autoplay sequence will continue.
Here is what’s going right:
- All manual audio controls are woking fine.
- If the user clicks the autoplay button from the menu screen, the intro screen, or the song/scene1 page, then the autoplay sequence works correctly (playing song1 from song/scene1 and then continuing through the whole album).
- If I manually switch to a given song/scene, and I first manually trigger the audio with the PlaySong button, then the autoplay sequence triggers the correct song and continues to play correctly.
Here is what is going wrong:
- If I navigate to a given song page other than song/scene1 and I try to click the autoplay button fresh in order to start the autoplay sequence, it will not play the correct current song. The only way I can get it to play the correct song is if I click the PlaySong button first.
- I’m using a counter (a global window. variable) to keep track of what song and scene is supposed to play at any given time. The strange thing is, if you open the Chrome Javascript console, when I navigate to a given scene, you can see that the counter is being updated correctly (for instance, if you choose scene3 from the menu, then it will jump to scene3 and it will display that the counter is now = 3). However, even though the counter is showing the correct number, the correct song will not play.
So, that’s where I’m at. I would so very much appreciate any help you might be able to offer!
Any ideas?
Thanks so much!
rg