04.11.2016, 17:56
(This post was last modified: 04.11.2016, 19:39 by Erwin van der Zwart.)
Hi Cekca,
There are restrictions build into iOS by Apple that require user input to play audio.
The audio must be called once by a user event like 'click', the sample i made you point out to has this event so that's why it works.
Here is a fix to bypass it but still not fully... You have to at least touch the screen once (anywhere) to be able to play audio during the rest of the session..
And yes you can trigger audio by KNX object, check previous custom JavaScript samples, there a quite a lot scripts with this functionality..
BR,
Erwin van der Zwart
There are restrictions build into iOS by Apple that require user input to play audio.
The audio must be called once by a user event like 'click', the sample i made you point out to has this event so that's why it works.
Here is a fix to bypass it but still not fully... You have to at least touch the screen once (anywhere) to be able to play audio during the rest of the session..
Code:
// Fix iOS Audio Context
(function() {
var fixAudioContext = function (e) {
if (ctx) {
// Create empty buffer
var buffer = ctx.createBuffer(1, 1, 22050);
var source = ctx.createBufferSource();
source.buffer = buffer;
// Connect to output
source.connect(ctx.destination);
// Play sound
if (source.start) {
source.start(0);
} else if (source.play) {
source.play(0);
} else if (source.noteOn) {
source.noteOn(0);
}
}
// Check if document is loaded in iframe
if (window.frameElement){
// Remove event listeners from parent
var thisparent = window.parent;
thisparent.document.removeEventListener('touchstart', fixAudioContext);
thisparent.document.removeEventListener('touchend', fixAudioContext);
}
// Remove events
document.removeEventListener('touchstart', fixAudioContext);
document.removeEventListener('touchend', fixAudioContext);
};
// Check if document is loaded in iframe
if (window.frameElement){
// Add event listeners to parent
var thisparent = window.parent;
// Event listener for iOS 6-8 (was previous touchstart event)
thisparent.document.addEventListener('touchstart', fixAudioContext);
// Event listener for iOS 9+ (is now touchend event)
thisparent.document.addEventListener('touchend', fixAudioContext);
}
// Event listener for iOS 6-8 (was previous touchstart event)
document.addEventListener('touchstart', fixAudioContext);
// Event listener for iOS 9+ (is now touchend event)
document.addEventListener('touchend', fixAudioContext);
})();
And yes you can trigger audio by KNX object, check previous custom JavaScript samples, there a quite a lot scripts with this functionality..
BR,
Erwin van der Zwart