diff --git a/src/components/VapMp4Player.vue b/src/components/VapMp4Player.vue index ce3c748..4f42650 100644 --- a/src/components/VapMp4Player.vue +++ b/src/components/VapMp4Player.vue @@ -93,10 +93,47 @@ const errorMessage = ref('') let player = null let playToken = 0 let cleanupPlayerVideoGuards = null +let vapInlinePlaybackPatched = false const teleportToBody = computed(() => props.mode === 'overlay') const resolvedSrc = computed(() => resolveProtectedAssetUrl(props.src)) +function patchVapInlinePlayback() { + if (vapInlinePlaybackPatched) { + return + } + + try { + const probePlayer = new Vap() + const proto = Object.getPrototypeOf(probePlayer) + + if (!proto || typeof proto.initVideo !== 'function') { + return + } + + if (proto.__likeiInlinePlaybackPatched) { + vapInlinePlaybackPatched = true + return + } + + const originalInitVideo = proto.initVideo + proto.initVideo = function patchedInitVideo(...args) { + const result = originalInitVideo.apply(this, args) + enforceVideoPlaybackAttributes(this?.video, this?.options?.mute) + return result + } + + proto.__likeiInlinePlaybackPatched = true + vapInlinePlaybackPatched = true + + if (typeof probePlayer.destroy === 'function') { + probePlayer.destroy() + } + } catch (error) { + console.warn('Failed to patch VAP inline playback hooks:', error) + } +} + function enforceVideoPlaybackAttributes(video, shouldMute) { if (!video) { return @@ -238,6 +275,7 @@ async function startPlay() { try { await nextTick() + patchVapInlinePlayback() if (!containerRef.value || currentToken !== playToken) { return