Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently May 18th, 2024, 9:34 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Sound JavaScript HTML5
PostPosted: September 28th, 2015, 8:18 am 
Offline

Joined: July 12th, 2009, 10:33 am
Posts: 124
Hi

Just thought I'd try again to sort out some sound delay issues in HTML5 on the iPad by creating an audio sprite. Borrowed this example from DW to play a sound from a chosen position, but it doesn't actually work in IE on 3 different machines here. The start and stop is OK, but not the 12s start. Chrome is fine.

http://www.themightymaestro.com/testsound/js.htm

Anyone any ideas?

EDIT: It doesn't actually work on the iPad anyway. Anyone any other ideas? This seems to work on everything, so if it can be incorporated, that looks like a possible solution.

http://jsfiddle.net/aarongloege/rQv5h/e ... 1443425886

Thanks
Dan

_________________
V9.6. Windows 10. Testing on PC, Mac, iPad.


For this message dan1 has been thanked by : mackavi


Last edited by dan1 on September 29th, 2015, 1:27 am, edited 1 time in total.

Top
 Profile Visit website  
 
 Post subject: Re: Sound JavaScript HTML5
PostPosted: September 28th, 2015, 10:29 am 
Offline

Joined: July 12th, 2009, 10:33 am
Posts: 124
I'm having a play with the jsfiddle solution, but I'm completely unsure where to put JavaScript functions and scripts in Opus. Any ideas where you would place the components below so that they function once published? I'll need avoid the HTML head and body additions on publishing as my pub creates a large number of htm pages and I don't want these scripts etc to appear on all of them. Thanks :)



<html>
<head>

</head>
<body>

<audio id="audio">
<source src="http://dl.dropbox.com/u/1538714/article_resources/cat.m4a" type="audio/mpeg" />
<source src="http://dl.dropbox.com/u/1538714/article_resources/cat.ogg" type="audio/ogg" />
</audio>
<button onclick="playSprite('meow1');">Play Meow 1 Sprite</button>
<button onclick="playSprite('meow2');">Play Meow 2 Sprite</button>
<button onclick="playSprite('whine');">Play Whine Sprite</button>
<button onclick="playSprite('purr');">Play Purr Sprite</button>





<script type='text/javascript'>

//<![CDATA[

var audioSprite = document.getElementById('audio');

// sprite data
var spriteData = {
meow1: {
start: 0,
length: 1.1
},
meow2: {
start: 1.3,
length: 1.1
},
whine: {
start: 2.7,
length: 0.8
},
purr: {
start: 5,
length: 5
}
};

// current sprite being played
var currentSprite = {};

// time update handler to ensure we stop when a sprite is complete
var onTimeUpdate = function() {
if (this.currentTime >= currentSprite.start + currentSprite.length) {
this.pause();
}
};
audioSprite.addEventListener('timeupdate', onTimeUpdate, false);

// in mobile Safari, the first time this is called will load the audio. Ideally, we'd load the audio file completely before doing this.
var playSprite = function(id) {
if (spriteData[id] && spriteData[id].length) {
currentSprite = spriteData[id];
audioSprite.currentTime = currentSprite.start;
audioSprite.play();
}
};
//]]>

</script>

</body>

</html>

_________________
V9.6. Windows 10. Testing on PC, Mac, iPad.


For this message dan1 has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject: Re: Sound JavaScript HTML5
PostPosted: September 28th, 2015, 12:13 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
If you just want to use that sample, then stick it in the HTML5 object. Use my clean version as yours is causing problems:

Code:
<audio id="audio">
    <source src="http://dl.dropbox.com/u/1538714/article_resources/cat.m4a" type="audio/mpeg" />
    <source src="http://dl.dropbox.com/u/1538714/article_resources/cat.ogg" type="audio/ogg" />
</audio>
<button onclick="playSprite('meow1');">Play Meow 1 Sprite</button>
<button onclick="playSprite('meow2');">Play Meow 2 Sprite</button>
<button onclick="playSprite('whine');">Play Whine Sprite</button>
<button onclick="playSprite('purr');">Play Purr Sprite</button>


<script>
    var audioSprite = document.getElementById('audio');

    // sprite data
    var spriteData = {
        meow1: {
            start: 0,
            length: 1.1
        },
        meow2: {
            start: 1.3,
            length: 1.1
        },
        whine: {
            start: 2.7,
            length: 0.8
        },
        purr: {
            start: 5,
            length: 5
        }
    };

    // current sprite being played
    var currentSprite = {};

    // time update handler to ensure we stop when a sprite is complete
    var onTimeUpdate = function() {
        if (this.currentTime >= currentSprite.start + currentSprite.length) {
            this.pause();
        }
    };
    audioSprite.addEventListener('timeupdate', onTimeUpdate, false);



    var playSprite = function(id) {
        if (spriteData[id] && spriteData[id].length) {
            currentSprite = spriteData[id];
            audioSprite.currentTime = currentSprite.start;
            audioSprite.play();
        }
    };

</script>


</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Sound JavaScript HTML5
PostPosted: September 28th, 2015, 1:07 pm 
Offline

Joined: July 12th, 2009, 10:33 am
Posts: 124
Thanks Mack.

That was just the example from the jsfiddle site...
http://jsfiddle.net/aarongloege/rQv5h/e ... 1443425886

I've got a range of pages that will need this functionality e.g. a set of musical notes created with Opus graphics on a stave, each playing the relevant sound when clicked. The same graphics and sounds are then used in a game. I think I need to break this down and get a handle on how to incorporate the different parts ie.

1. Where to put the initial sound file links.
2. Where to place the script setting up the sprite timing.
3. The js functions.
4. How to call the function with the chosen parameter set.

I'm a bit lost here and there's too many possibilities to get through on trial and error. I'm guessing from your reply that some of this can still go in an HTML object (sorry - never used these so will have to investigate). I can see from the DW example how to set a variable on a button and find it from within a javascript, but not how to call the actual function.

Cheers
Dan

_________________
V9.6. Windows 10. Testing on PC, Mac, iPad.


For this message dan1 has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject: Re: Sound JavaScript HTML5
PostPosted: September 28th, 2015, 2:38 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
The DW method won't work. You need to add a click event handler directly to an element, which may have to be a button. However, once triggered manually, the sound should be accessible to other indirect calls.

The first part of above is what is happening when you use the code within the HTML5 object, the button elements are not part of the Opus code and have their own independent event handlers that call the sound functions. You can use the HTML5 object just to display the element and attach the script with the sound handling code as a linked .js file in the Opus header options cutting down on repetition and making it easier to maintain.

I'm not sure if sound will be 100% cross-browser yet, but we have used this method in projects for several clients and it did work for Apple Pad and Phone devices.

</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Sound JavaScript HTML5
PostPosted: September 29th, 2015, 12:06 am 
Offline

Joined: July 12th, 2009, 10:33 am
Posts: 124
Cheers Mack. I'm still pretty lost but I'll try and get my head around how Opus publishes and see what works. Everything will be trigged by user actions, so that isn't a problem (although it might need a Start button or something to get the file downloaded before the first sound is needed).

I was also going to avoid the Opus header as I publish from one publication to 50 htm pages, and don't want all the different sprite info in all of them - the sounds are different on every page. I guess a bit of the script is reused.

Anyway, will post if I get anywhere.

Thanks again for the thunks.
:)

_________________
V9.6. Windows 10. Testing on PC, Mac, iPad.


For this message dan1 has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject: Re: Sound JavaScript HTML5
PostPosted: September 29th, 2015, 1:15 am 
Offline

Joined: July 12th, 2009, 10:33 am
Posts: 124
Actually, this was a doddle. I just put the sound file and JavaScript into an HTML object as you suggested, then could call the function from any DW object by adding a javascript to a DW onclick event.

http://www.themightymaestro.com/testsound/js2.htm

The Start button needs to be clicked first in my IE, but not iPad or Chrome. Either way, it initiates the sound file and means it's ready instantly afterwards - I'll just link it to a silent section of the sound file.

Very excited that my website might work properly on iPads at last.

Was going to attach my test file, but got "Sorry, the board attachment quota has been reached.". It's here....

http://www.themightymaestro.com/testsound/testsound.zip

Massive thanks for your help :)

_________________
V9.6. Windows 10. Testing on PC, Mac, iPad.


For this message dan1 has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject: Re: Sound JavaScript HTML5
PostPosted: September 29th, 2015, 2:01 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
That's very interesting. I wonder if and what changed as this was a problem 12 months ago. I'm finishing a SCORM project at the moment, but will have a play with some samples to see how it's different to our original findings.

Glad it works for you though and thanks for taking the time to post the reply with working sample.

</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Sound JavaScript HTML5
PostPosted: September 30th, 2015, 1:08 am 
Offline

Joined: July 12th, 2009, 10:33 am
Posts: 124
No probs.

I've asked people on fb to test this on different devices.

http://www.themightymaestro.com/testsound/test5.htm

So far....

PC - IE11 no probs. Chrome V45 no probs.
Mac - waiting to hear
iPad - ios8+ no probs. ios7 couldn't get past the start button. Maybe a real button would help, but can't see the notes working anyway.

iPhone5 - generally fine on updated ios, although this is too small for a phone. ios7 didn't get past the button.
iPhone4 - ios7 as above
Android - updated fine.

No one has said they have a problem specifically with the sound. The button is a non-starter for some, but having got past that it seems fine so far.

_________________
V9.6. Windows 10. Testing on PC, Mac, iPad.


For this message dan1 has been thanked by : mackavi


Top
 Profile Visit website  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group