Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat committed Jun 8, 2024
1 parent cda6e4b commit 7451863
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const onCreateWebpackConfig: GatsbyNode['onCreateWebpackConfig'] = ({ sta
module: {
rules: [
{
test: /crunker/,
test: /crunker/g,
use: loaders.null(),
},
],
Expand Down
56 changes: 39 additions & 17 deletions src/announcement-data/AnnouncementSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,25 +200,47 @@ export default abstract class AnnouncementSystem {
window.__audio = undefined
} else {
return new Promise<void>(resolve => {
crunker.play(audio, source => {
console.log('[Crunker] About to play audio...')
crunker._context.onstatechange = () => console.log('state changed to: ', audioContext.state)
console.log('Context state: ', crunker._context.state)

if (crunker._context.state === 'suspended') {
alert('Resuming audio context')
console.log('[Crunker] Resuming audio context')
crunker._context.resume()
console.log('Context state: ', crunker._context.state)
}
const el = crunker.export(audio, 'audio/wav').element

source.addEventListener('ended', () => {
alert('Finished playing audio')
console.log('[Crunker] Finished playing audio')
window.__audio = undefined
resolve()
})
el.addEventListener('ended', () => {
console.log('Finished playing audio')
window.__audio = undefined
el.remove()
resolve()
})

document.body.appendChild(el)

try {
el.play()
} catch (e) {
console.error(e)
// Scroll to element
el.scrollIntoView()
alert(
'Please click the play button to play the live announcement. This is a limitation of your browser. To play announcements automatically, please try a different device or browser.',
)
}

// crunker.play(audio, source => {
// console.log('[Crunker] About to play audio...')
// crunker._context.onstatechange = () => console.log('state changed to: ', audioContext.state)
// console.log('Context state: ', crunker._context.state)

// if (crunker._context.state === 'suspended') {
// alert('Resuming audio context')
// console.log('[Crunker] Resuming audio context')
// crunker._context.resume()
// console.log('Context state: ', crunker._context.state)
// }

// source.addEventListener('ended', () => {
// alert('Finished playing audio')
// console.log('[Crunker] Finished playing audio')
// window.__audio = undefined
// resolve()
// })
// })
})
}
}
Expand Down

0 comments on commit 7451863

Please sign in to comment.