-
Notifications
You must be signed in to change notification settings - Fork 619
Audio element stops/pause playing even if it is flag as data-turbolinks-permanent #157
Comments
Hi, I don't know about previous versions, but I had the same problem with video elements and webRTC live communication. I managed to "solve" it by manually calling $myMediaElement.play(); on every
It's a stupid fix, but I haven't found anything better for now and for me it works. There is a problem though with normal |
Thanks, I did the same thing on my side though. My issue with this is if the user pause the audio before changing page, the audio starts playing. Glad I'm not alone with this issue. |
You can solve this by creating a plain audio object without a Tag
Then changing pages works. But you need to build an own audio element with play pause, volume etc.. |
Similar to #177. |
same here .. |
Turbolinks clones Good news is that uninterrupted audio/video play back across pages can be achieved by tracking the playing state ourselves. I've not been able to discover how media elements are cloned, but (luckily) it seems like the current time is cloned, so we can just call ;(function () {
var forEach = Array.prototype.forEach
var selector = [
'[data-turbolinks-permanent] audio',
'audio[data-turbolinks-permanent]',
'[data-turbolinks-permanent] video',
'video[data-turbolinks-permanent]'
].join(',')
addEventListener('turbolinks:load', function () {
var mediaElements = document.querySelectorAll(selector)
forEach.call(mediaElements, uninterrupt)
})
// Bind to turbolinks:render to handle previews
addEventListener('turbolinks:render', function () {
var mediaElements = document.querySelectorAll(selector)
forEach.call(mediaElements, function (media) {
if (media.isPlaying) media.play()
})
})
function uninterrupt (media) {
if (!media.uninterrupted) {
media.addEventListener('play', function () { media.isPlaying = true })
media.addEventListener('pause', function () { media.isPlaying = false })
media.uninterrupted = true
}
}
})() This will work for |
Hi all, I faced the same issue (music stops playing). But it can be resolved by specifying the ID attribute of the "data-turbolinks-permanent" container. This is my case:
This way, any time I click on a link, the player stops playing. if I change the code this way, it works perfectly and the audio keeps playing when moving from a page to another:
It seems that the ID attribute is necessary on the turbolinks' permanent containers. Hope this helps. |
Hi,
I'm trying to make turbolinks 5 to work with an html5 audio element. I put this element within a div flagged as data-turbolinks-permanent. Everything works well, the div has not been refresh but the audio just pause. I can hit the play and it continues where it was.
It was ok with a previous version of turbolinks.
Any idea?
The text was updated successfully, but these errors were encountered: